Controlling a RGB LED

In this project, you'll learn how to connect and control an RGB LED.

A RGB LED is a LED with three individual color (red, green, blue) LEDs built inside one package. By varying the brightness of each of the three LEDs, millions of colors are possible.

Parts needed:
  • Arduino
  • RGB LED
  • Three 150 Ω resistors (brown-green-brown / brown-green-black-black)
  • Wires
  • Breadboard
Arduino      Breadboard     
150 ohm resistor 150 ohm resistor RGB LED     
1 Making the connections

The negative connection for each of the three LEDs are connected in common internally. This is the longest pin labeled cathode in the RGB LED picture.
 
  • Connect the cathode (longest) pin on the RGB LED to GND on the Arduino board.
  • Connect the red pin on the RGB LED to a 150 Ω (brown-green-brown) resistor. Connect the other end of the resistor to pin 9 on the Arduino.
  • Connect the green pin on the RGB LED to a 150 Ω (brown-green-brown) resistor. Connect the other end of the resistor to pin 10 on the Arduino.
  • Connect the blue pin on the RGB LED to a 150 Ω (brown-green-brown) resistor. Connect the other end of the resistor to pin 11 on the Arduino.


Note that if only one resistor is used on the negative end instead of three resistors on the positive ends, then when the colors are mixed, the resulting color might not be correct because the power distribution to the three leds might be different.
RGB LED connections
2 Create a new program by selecting File from the menu
  • then select New
Then type in this program.











Use three analogWrite commands to control the brightness of each of the three LEDs.

Setting red to 80, green to 0 and blue to 80 gives purple color.
RGB LED program
3 Upload and run the program. You should see the RGB LED showing purple color.