Professional Documents
Culture Documents
1X Ed Led 1X Reen Led 1X Lue Led: How Do RGB Leds Work?
1X Ed Led 1X Reen Led 1X Lue Led: How Do RGB Leds Work?
As you can see, the 3 LEDs can share the cathode or the anode. This results in an RGB LED
that has 4 pins, one for each LED, and one common cathode or one common anode.
The common anode RGB LED is the most popular type.
How to create different colors?
You can create one of those three colors – red, green or blue – by activating just one LED.
For example, if you want to produce blue, you activate the blue LED and turn off the other two.
Mixing colors
To produce other colors, you can combine the three colors in different intensities. To generate
different colors you can use PWM to adjust the brightness of each LED.
As the LEDs are very close to each other, we can only see the final colors result rather than the
three colors individually.
To have an idea on how to combine the colors, take a look at the following chart. This is the
simplest color mixing chart, there are more complex color charts on the web.
Schematics
Follow these schematics to complete the project:
Important: If you’re using an RGB LED common cathode, you need to connect the longer lead to
GND.
Code
Upload the following sketch to your Arduino board:
/*
All the resources for this project:
http://randomnerdtutorials.com/
*/
void setup() {
pinMode(redPin,OUTPUT);
pinMode(bluePin,OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(potRed, INPUT);
pinMode(potGreen, INPUT);
pinMode(potBlue, INPUT);
}
void loop() {
// Reads the current position of the potentiometer and converts
// to a value between 0 and 255 to control the according RGB pin with PWM
// RGB LED COMMON ANODE
analogWrite(redPin,(255./1023.)*analogRead(potRed));
analogWrite(greenPin,(255./1023.)*analogRead(potGreen));
analogWrite(bluePin,(255./1023.)*analogRead(potBlue));
delay(10);
}
view raw Projects/How_do_RGB_LEDs_work.ino
Important: If you’re using an RGB LED common cathode, you need to comment and uncomment
some code in the loop() function as described in the sketch comments.