Home Arduino Projects Arduino Projects: RGB LED Arduino

Arduino Projects: RGB LED Arduino

by Nikodem Bartnik

Everyone loves LEDs, they are cheap, simple to use and you can easily learn all Arduino tricks with them. But here some an even cooler LED type, this one is different from the ordinary LED we have been using here. It’s called the RGB LED.

What is the RGB LED?

The RGB LED is a single LED that contains 3 LEDs: red, green and blue one.

It can shine in over 16 million colors and is as easy to use as normal LEDs.

We have two main types of RGB LEDs: the common cathode and the common anode.

If you have the common cathode, you should connect the longest leg of the LED to ground (GND) and the rest 3 legs to 3 of the Arduino pins. It shines at HIGH states of the pins.

If you have the common anode you have to connect the longest leg to VCC (5V) and the rest of them to the Arduino pins. It shines at LOW states of the pins.

Do not forget to put a resistor in series with each of the 3 pins between the Arduino and the LEDs pins

Parts needed

Arduino Projects: RGB LED Arduino

Here are two diagrams for connection purposes. The first one is for the common anode (I used it) and the second one is for the common cathode.

Whichever you use, make sure to connect the LED properly. The code does not change.

Arduino Projects: RGB LED Arduino
Arduino Projects: RGB LED Arduino

We need to connect 4 cables and 3 resistors. Here is how it looks like:

Arduino Projects: RGB LED Arduino

Now, we can upload the first program to the Arduino. The following code will light up the red, green and blue LED in a sequence. Not so fancy huh!

Arduino Projects: RGB LED Arduino

The previous code was used for the sake of showing you how it looks and works.

Now, we can build something more sophisticated.

Here, we uses a function random.

This function calls random([min_value], [max_value]); That make you get a random number within the range, min_value (the smallest value we can get is 0 and max value is 255 because those are the max value we can write to the analogWrite() function).

We have the following 3 values for each color and we randomly generate numbers for those colors.

When current_color_value is equal to random_color_value, we get a new random value.

The LED itself is just really bright and we are not able to notice it is color changing. We should somehow diffuse its color to make it look better.

You most probably have this type of foam somewhere in your house, it usually come in boxes to protect their content when shipped. It is just perfect for this. Just make a small hole for the LED to go in and we are set to go.

Arduino Projects: RGB LED Arduino

I hope you have just built your first RGB LED Arduino project. Just take a look on how cool this is.

You might also like:

Related Posts

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy