Post Page Advertisement [Top]

Arduino - RGB LED Interfacing - How To?

Arduino - RGB LED Interfacing - How To?

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

Pin Mappings of the RGB LED

Place resistor between the common cathode and the '-'ve terminal

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

Bottom Ad [Post Page]