Wednesday, May 16, 2012

Simple Labs' Quick Start Kit for Arduino - RGB LED Interfacing - How To?


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]
  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(11, HIGH);  
  digitalWrite(11, LOW);    
  digitalWrite(10, HIGH); 
  digitalWrite(10, LOW);    
  digitalWrite(9, HIGH); 

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  


  1. The program would be more readable if you define the pin numbers as follows.

    #define REDPIN 11
    #define BLUEPIN 10
    #define GREENPIN 9

    digitalWrite(REDPIN, HIGH);

  2. In the rgb led I got from your store it was a common anode rather than a common cathode.

  3. What is the minimum value of resistance,we must connect with ground?