Control an RGB LED with an Arduino
Arduino Uno tutorials
🕑 This lesson will take about 15 minutes
In this lesson, you will learn how to control an RGB LED (Light Emitting Diode) light with an Arduino. An RGB LED uses combinations of Red, Green, and Blue light to produce different colours. You can write code to specify the amounts of red, green and blue light you would like to mix to produce a desire colour.
The RGB LED has four pins: one for controlling red light, one for green light, one for blue light and one for ground (GND). The longest pin is GND.
Required parts
1 x Arduino Uno
1 x RGB LED
1 x breadboard
3 x 220 Ohm resistors
4 x male-to-male jumper wires
Wiring schematic
Connect the red pin to digital pin 11 on the Arduino via a 220 Ohm resistor on the breadboard.
Connect the long pin (between the red and green pins) to GND on the Arduino
Connect the green pin to digital pin 10 on the Arduino via a 220 Ohm resistor on the breadboard.
Connect the blue pin to digital pin 9 on the Arduino via a 220 Ohm resistor on the breadboard.
The code
Upload the following code to the Arduino Uno.
You can also use the following code which has a dedicated function for setting the colour of the LED. This function makes it easier to change the red, green, and blue values for the LED using one line of code just by calling the RGB_color() function.