Common Cathode RGB LED Review and Code examples

Today I am reviewing a basic RGB LED. This includes schematics for using it with an Arduino and code examples.

What can the RGB Light Emitting Diode Do

The RGB common cathode light emitting diode works just like a standard LED but there is one small difference. Instead of having a single colour there are 3 different LED’s packed into a single one. This LED has 4 pins, a common cathode and a pin for each colour (red, green and blue).

Common cathode means that each LED shares a common GND connection. This means you will only need one GND connection for all the LED’s.

Datasheet Specifications
Voltage Red 1.9 V to 2.5 V
Green 2.9 V to 3.5 V
Blue 2.9 V to 3.5 V

The important thing to remember when using the RGB LED is that the different colour LED’s require different voltages. What makes it more tricky is that the red LED accepts voltages in a completely different range to the green and blue LED’s. This means that when powering the LED’s you will need to ensure that the resistors are keyed so they LED’s receive the correct voltage.

Wiring it up to an Arduino

To programmatically change the colour of the LED I am wiring the three positive pins to pin 11, 12, and 13 of the Arduino.

When looking at the LED the longest PIN is the common cathode. If you turn the LED so the longest PIN is the second from left as in my diagram the leftmost pin is the red LED.

Going left to right in this orientation the pins are the red LED, common cathode (longest pin), green LED and blue LED.

I am going to be using the digitalWrite Arduino function which will provide 5 volts from the pin. This means that to ensure I give the LED the correct operating voltage I will need to use a resistor.

I have found that a 150 Ω resistor works well for the red LED and a 100 Ω resistor for the blue and green LED.

As shown in the diagram these are placed between the Arduino pins and the positive pin of the LED. These resistors keep the voltage at an acceptable working range for the LED. These values ensure that the LED has enough power to be relatively bright and also not be in danger of damaging it.

Code example to use the RGB LED

First I am going to set up a couple #define‘s to make my program easily to modify. These define what pins I am going to use for my program and the delay between changing colour.

#define BLUE_PIN 13
#define GREEN_PIN 12
#define RED_PIN 11
#define DELAY_VAL 1000

Once this has been done I set up each LED pin as an output pin. This now lets me write to it as an output to light the LED up.

void setup() {
  pinMode(BLUE_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(RED_PIN, OUTPUT);
}

The final piece of code loops through all the possible colours you can create using your 3 LED’s. Here I pause for 1 second (1000 milliseconds) after I change each colour.


void loop() {
  //Blue
  digitalWrite(BLUE_PIN, HIGH);
  delay(DELAY_VAL);
  //Green
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, HIGH);
  delay(DELAY_VAL);
  //Red
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(RED_PIN, HIGH);
  delay(DELAY_VAL);
  digitalWrite(RED_PIN, LOW);

  //Blue, Green = Cyan
  digitalWrite(BLUE_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  delay(DELAY_VAL);

  //Green, Red = Yellow
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(RED_PIN, HIGH);
  delay(DELAY_VAL);

  //Blue, Red = Purple
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(BLUE_PIN, HIGH);
  delay(DELAY_VAL);

  //Blue, Green, Red = White
  digitalWrite(BLUE_PIN, HIGH);
  digitalWrite(GREEN_PIN, HIGH);
  digitalWrite(RED_PIN, HIGH);
  delay(DELAY_VAL);

  //Set all low
  digitalWrite(BLUE_PIN, LOW);
  digitalWrite(GREEN_PIN, LOW);
  digitalWrite(RED_PIN, LOW);
}

When uploaded this will loop through all the colours waiting a second for each colour.

Final Review

I have found these LED’s really useful to be able to change the colour of the display LED. They use standard voltages and the resistors needed to power them from a 5 volt line are easily obtainable. Being able to light multiple colours at once means you can mix them together. The only issue with mixing them is that when lighting all of them the white is slightly off-white. This off-white colour isn’t a major problem however and is far outweighed by the usability of these.

Since you can configure them to be multiple colours they are useful to projects where you want to display a colour changing status light. This makes them a staple in my toolbox when designing circuits that require a status light. Would buy again!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.