First we need to know what is meant by a RGB led ?
A RGB led is a combination of blue led, green led and red led. It is also called tri-color or multicolor led. With this led obviously you will able to produce the red, green and blue and you can also produce different colors by configuring the intensity of each led. The first picture shows an simple RGB led and the second one is RGB led module :
A RGB led has four pins namely Green pin, Blue pin, Red pin and Cathode ( - ). The cathode is considered as the negative pin and it is connected to the ground of the system. Other three pins control their individual colors.
Now we can start the connections :
Green pin to D13 to Arduino
Blue pin to D3 pin of Arduino
Red pin to D5 pin of Arduino
Cathode ( - ) to the Gnd of Arduino
The circuit diagram, images and references are uploaded in the hardware section. Here is the code :
// Interfacing RGB led with Arduino Uno
int redPin = 5;// Red pin to digital pin 5 of arduino
int greenPin = 12;// Green pin to digital pin 12 of arduino
int bluePin = 3;// Blue pin to digital pin 3 of arduino
//uncomment this line if using a Common Anode LED
//#define COMMON_ANODE
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
setColor(255, 0, 0); // red
delay(1000);
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(0, 255, 255); // aqua
delay(1000);
}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
To create more colors with RGB led we need to set the intensity of each internal LED and combine the three color outputs. We are going to use PWM to adjust the intensity of the red, green, and blue LEDs individually and the trick here is that our eyes will see the combination of the colors, instead of the individual colors because the LEDs are very close to each other inside. This is the color chart of RGB led :
Comments