0% found this document useful (0 votes)
155 views4 pages

1X Ed Led 1X Reen Led 1X Lue Led: How Do RGB Leds Work?

An RGB LED contains three LEDs - red, green, and blue - in a single package. It can produce different colors by controlling the intensity of each individual LED through pulse-width modulation. Common anode and common cathode RGB LEDs differ in whether the anode or cathode is shared between the three LEDs. An Arduino example controls an RGB LED by reading three potentiometers and using those values to set the PWM intensity of each color channel.

Uploaded by

amalija20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
155 views4 pages

1X Ed Led 1X Reen Led 1X Lue Led: How Do RGB Leds Work?

An RGB LED contains three LEDs - red, green, and blue - in a single package. It can produce different colors by controlling the intensity of each individual LED through pulse-width modulation. Common anode and common cathode RGB LEDs differ in whether the anode or cathode is shared between the three LEDs. An Arduino example controls an RGB LED by reading three potentiometers and using those values to set the PWM intensity of each color channel.

Uploaded by

amalija20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

With an RGB LED you can produce almost any color you would like.

How is this possible with just


one single LED?
How do RGB LEDs work?
In fact, an RGB LED is a combination of 3 LEDs in just one package:
 1x Red LED
 1x Green LED
 1x Blue LED
The light that the RGB LED produces are made combining these three LED colors. An RGB LED
looks like this:

Two types of RGB LEDs


There are common anode RGB LEDs and common cathode RGB LEDs. See figure below:

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.

RGB LED Pins


RGB LEDs have 4 pins which can be distinguished by their length. The longest one is the ground
(-) or voltage (+) depending if it is a common cathode or common anode LED, respectively.
The other three legs correspond to red, green, and blue, as you can see in the figure below:

Example – Control an RGB LED with the Arduino


In this example you will use three potentiometers to control each pin of the RGB LED to produce
any color you want.
Parts required
For this example you’ll need:
 1× Arduino
 1× RGB LED common anode
 3× 1kΩ Potentiometer
 1× Breadboard
 3 × 220Ω Resistor
 Jumper wires

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/
*/

int redPin = 3; // Red RGB pin -> D3


int greenPin = 5; // Green RGB pin -> D5
int bluePin = 6; // Blue RGB pin -> D6

int potRed = A0; // Potentiometer controls Red pin -> A0


int potGreen = A1; // Potentiometer controls Green pin -> A1
int potBlue = A2; // Potentiometer controls Blue pin -> A2

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));

// Uncomment for RGB LED COMMON CATHODE


/*
analogWrite(redPin,255-(255./1023.)*analogRead(potRed));
analogWrite(greenPin,255-(255./1023.)*analogRead(potGreen));
analogWrite(bluePin,255-(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.

You might also like