Lesson 4 – Controlling RGB LED with PWM

When I revisit this, I want to add potentiometers and a higher wattage RGB LED to add that WOW factor.
An RGB LED is a tri-color LED that consists of Red, Green and Blue (RGB) LEDs in a single package. They come in either common-anode or common-cathode.
We can access each R, G, B LED to produce a unique color.
PWM dimming of RGB LEDs looks amazing. Thus, it’s widely used in mood lighting and in some consumer devices.

Internal wiring of an RGB LED
Circuit assembled on a breadboard

Program Description

This Arduino program controls an RGB LED, cycling through various colors: red, green, blue, yellow, white, and purple, before turning off the LED. Each color is displayed for one second, utilizing loops to repeat the sequence indefinitely.

The setup() function initializes the LED pins as outputs, while the loop() function performs the color changes and delays. Basic LED control and color mixing is shown.
See the flowchart below for more information

Code flowchart