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
  • 3x 150 Ω resistor (brown-green-brown)
  • Wires
  • Breadboard
Arduino      Breadboard      150 ohm resistor RGB LED     
1 Making the connections
  • The negative connection for each of the three LEDs are connected in common. This is the longest leg labeled cathode on the RGB LED. Connect this to the GND pin on the Arduino board.
  • Connect each of the other three positive ends of the RGB LED to a 150 Ω resistor.
  • Connect the other end of each of the resistors to pins 9, 10 and 11 on the Arduino board.
RGB LED connections
2 Create a new Bare Minimum program by selecting File from the menu
  • then select Examples
  • then select Basics
  • then select BareMinimum
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.