Introduction: Getting Started With Arduino - RGB LED
In this tutorial we will look at how to wire up a Red/Green/Blue (RGB) Light Emitting Diode (LED) to an Arduino and control it over the serial port. You could use a basic RGB LED component (i.e. a plastic dome with four legs !), but we are going to use an LED board (like the one shown above) which has all of the correct resistors already connected. These boards are only cheap, but they make the whole project a lot simpler. The one we are using is a "common cathode" LED.
Step 1: Wire Up Your Arduino
First connect four wires to your Arduino:
- A black wire to the ground (GND)
- A red wire to pin 11
- A green wire to pin 10
- A blue wire to pin 9
Note that all these pin numbers have a ~ next to them on the board. This is because all of these pins can output a variable value (so that we can control the brightness of the red, green and blue elements of the LED). If you want to know more about this, do a search for PWM (pulse width modulation).
Step 2: Wire Up Your LED Module
Next plug your LED module into a breadboard and connect the wires from your arduino like so:
- Black goes to GND (Ground)
- Red goes to R
- Green goes to G
- Blue goes to B
Step 3: Wire Your Code
The next step is to write some code to control the LEDs.
Download the RGBSerial.ino file and open it up in the Arduino application. You can tinker with it if you like, or just use it as it is. Once you are happy, upload it onto your Arduino.
Step 4: Connect Via Serial Monitor
Once the code has been successfully uploaded onto the Arduino, open up the "Serial Monitor" by clicking on the magnifying glass icon on the top right of the Arduino window. The Serial monitor should look like the above - make sure that "newline" and "9600 baud" have been selected in the two dropdown menus at the bottom of the window. Next we are going to type in a sequence of three numbers into the text box at the top of the screen (followed by return). These numbers are Red, Green and Blue values that will be sent to the Arduino to light up the LED with the relevant colour combination. These number range from 0 to 255, so that:
255 0 0
would be bright red
0 255 0
would be bright green
0 0 255
would be bright blue
255 0 255
would be bright purple
255 255 255
would be bright white
100 100 100
would be dull white
Step 5: Enjoy
If everything worked, you should be able to experiment with the number sequences and create any colour combination you wish. See this page for a chart showing lots of colour combinations.
If you enjoyed this instructable, check out our other tutorials
If you love this kind of stuff, check out our degree
We have a be nice policy.
Please be positive and constructive.