The RGB LED
The RGB led aka the tricolor led
is a led that can help generate a multitude of colors by mixing red,
blue & green colors. Its more like 3 leds (red, green & blue)
put together into a single led.
It has 4 pins with 1 of
the pins being a common cathode and the other 3 pins acting as anodes
for the 3 different colours. by varying the intensity of each of the 3
colours individually, we can generate various colours. This led is the
same as 1 pixel of a LED TV!.
Here is how to wire it up
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-G8agJehcJIQsjgoiQK2GrHfwZqw4GTZX_cBDBLPGqnvx03pB5mDO3hiRbsVloczdAr__nVxuRR0QVfZbv92zja-cjKGuxiOPQ5ifnk6sSwMOqklrS9IDXzk1HABYVpZJmD0wYWy-ti11/s400/RGB1.jpg) |
Pin Mappings of the RGB LED |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkWZUiNjLed7c-TQS2zWrafUliLTlXSoU504Zz-a04lOaSzGz6s6jjfsM_sU4sgZNpGc2exdffrdvWMOuZ-Rmj0VOhFogXhXU2MfRhkwGSEou4NbjEjbarElt2KCIJ-KLS2avHbE006zbP/s640/RGB2.jpg) |
Place resistor between the common cathode and the '-'ve terminal |
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAqCvwmAz6_V1zXU1Oc0RxPTcFTvH_GpLL9zPbuXyuXpZ7OZWC21cOOt3Ppr3uxCHPt4c8JGNh6mXjOpurQDeJmQiIqp-9V5nhZE_TSEhSX4QZiSUSLbTkyWsiNGk9bA9D8OyWyZv87zuD/s640/RGB3.jpg) |
Connect RED to Pin 11, Blue to Pin 10 & Green to Pin 9 on the Arduino (these are PWM pins) |
Now try the following code first. This code is a normal digital control of all the three colors separately.[RGB_Blink.ino]
/*
RGB_Blink
Turns on each of the color spectrums for 4 seconds, repeatedly.
*/
void setup() {
// initialize the digital pins as an output.
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
digitalWrite(9,LOW);
digitalWrite(11, HIGH);
delay(4000);
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
delay(4000);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
delay(4000);
}
Next Lets get generating Colors, try the following code. Play around with the values and get yourselves comfortable.[RGB.ino]
/* RGB
Sets some random intensity value to the various colours of the RGB LED
*/
void setup()
{
}
void loop()
{
analogWrite(11,153);// Setting the voltage for Blue to around 3 Volts
analogWrite(10,51);// Setting the voltage for Red to around 1 Volt
analogWrite(9,51);// Setting the voltage for Green to around 1 Volt
}
No comments:
Post a Comment