In the previous lesson, we have learned about how to control motion sensor using Arduino. Today we are going to learn about how to control RGB led using Arduino. Let’s get started.
What is RGB led?
RGB led is a LED type, which contains Red, Green, Blue
colors together. You can change the R, G, and B values and make any color in
this world. That is the main use of RGB light. Below is the diagram of RGB
mixing. It can create every visible color on this earth.
With RGB light, you don’t have to buy much more LEDs in
different colors. You can do it with a single RGB LED.
RGB LED has 4 pins. One is GND. You all know about what is
GND. So, other 3 pins are R, G, and B. stands for red and in order to others
are green and blue. So, you can get those colors by making those pins “HIGH”.
You can change the brightness of each pin and get different kind of colors. Blow
is the pinout of RGB led.
You have to make the circuit like below to get a work from
RGB LED.
Blinking red, blue and green.
In this part, we are going to turn on and off red, green,
and blue colors. To do that, you have to make the code like below. And also,
you can test it right now using below start simulation button.
In the void setup of this code, I initialized 6th,
7th, 8th pins as outputs. Then inside the void loop, I put
command to make 6th pin (Red) high. Then I added 1 second delay and
then I put command to make 7th pin (Blue) high and make 6th
pin (Red) low. After that again 1 second delay. Then I added command to turn on
the 8th pin (Green) and make low 7th pin (Blue). Then
again 1 second delay. At the last line of
void setup, I put command to turn off the 8th pin (Green).
Making different colors using RGB LED.
Circuit diagram is same as before one.
This code is very simple. Its void setup is same as before
code. In this code’s void loop, I put 6th and 7th pin
HIGH together. That means red and blue together. That makes purple color. Like
that you can make any color. Then 1 second delay. After that, I turned off 6th
pin and still 7th pin is high. I turn on 8th pin in the next
line. It means blue with green. Result is light blue color. Again 1 second
delay and then 6th pin with 8th pin. It makes yellow
color. Try it out.
Making much more colors.
In this code, I put values instead of HIGH. You have learned
about putting values instead of HIGH or LOW. So, that this makes color low or high.
You can choose RGB colors by pressing below button.
If you have any problem, please comment below. Good Bye. Stay
connected.