Lesson 6 - RGB LEDS


In this lesson, you will use PWM to control an RGB LED and cause it to display all kinds of colors.


- 1 * RGB LED

- 3 * Resistor (220Ω)

- 1 * Breadboard

- 1 * SunFounder/ Arduino Uno board

- Jumper wires

- USB cable



RGB stands for the red, green, and blue color channels and is an industry color standard. RGB displays various new colors by changing the three channels and superimposing them, which, according to statistics, can create 16,777,216 different colors. If you say the color displayed doesn’t completely match a natural color, then it almost certainly cannot be differentiated with the naked eyes. 

Each of the three color channels of red, green, and blue has 255 stages of brightness. When the three primary colors are all 0, "LED light" is the darkest, that is, it turns off. When the three primary colors are all 255, "LED light" is the brightest. When superimposing the light emitted by the three primary colors, the colors will be mixed. However, the brightness is equal to the sum of all brightness, and the more you mix, the brighter the LED is. This process is known as additive mixing.

In this experiment, we will also use PWM which, if you’ve followed the lessons thus far, you already have a basic understanding of. Here we input a value between 0 and 255 to the three pins of the RGB LED to make it display different colors.

Experimental Procedures

Step 1: Build the circuit. Use ports 11, 10 and 9. The longest pin of the RGB led will go to ground (GND)

Step 2: Program.

Use the code in the document below and copy/paste it into the Arduino Program on your computer:

Arduino Code lesson 6

Step 3: Compile the code

Step 4: Upload the sketch to the SunFounder Uno board

Here you should see the RGB LED flash circularly red, green, and blue first, then red, orange, yellow, green, blue, indigo, and purple.