A Simple Guide to RGB LEDs

RGB LEDs are a type of LED that can emit a wide array of colors. In this tutorial, you’ll learn how RGB LEDs work and how to use them with Arduino or in other circuits to produce different colors.

RGB Leds gift

A Light-Emitting Diode (LED) is a small component that illuminates when current flows through it. RGB LEDs operate on the same principle, but they internally contain three LEDs (Red, Green, and Blue) capable of combining to produce nearly any color output.

How do RGB LEDs work?

The RGB color model is a way to represent colors by mixing red, green, and blue light. Each color channel’s intensity determines the overall color displayed. Combining these primary colors at different levels generates millions of colors visible to the human eye.

RGB model

For example, to create purely blue light, you have to adjust the blue LED to the highest intensity while setting the green and red LEDs to the lowest. But, for white light, all three LEDs have to be set to their highest intensity.

RGB LEDs mixing

Types of RGB LEDs

As you already know, RGB LEDs contain three LEDs inside, and usually, these three LEDs share a common anode or cathode. This categorizes RGB LEDs as either a common anode or a common cathode type, similar to the classification of seven-segment displays.

Type of RGB LEDs

As you can see in the picture above, RGB LEDs have four terminals. If the longest pin is on the left the order would be red, anode/cathode, green, and blue.

Common Anode RGB LED

In this type of RGB LED, all the anodes of the internal LEDs are attached to a single anode terminal. To control each color, you need to connect the red, green, and blue pins to a LOW signal or ground, while connecting the anode terminal to the positive side of a power supply.

Common Anode RGB LED

Common Cathode RGB LED

In the common cathode RGB LED, all the cathodes of the internal LEDs are connected to a cathode terminal. To control the colors, just send a HIGH signal or VCC to the red, green, and blue pins, and connect the anode terminal to the negative side of a power supply.

Common Cathode RGB LED

Using a RGB LED with an Arduino

As mentioned, to achieve different colors with an RGB LED you need to control the brightness of each internal LED. This can be accomplished by using PWM signals with an Arduino.

Check the following materials and the circuit you will need to connect your Arduino with a Common Cathode RGB LED:

  • Arduino Uno
  • Common Cathode RGB LED
  • 3x 220 Ohms Resistors
  • Breadboard
Arduino rgb led schematic

In the circuit above the cathode is connected to GND, and the three anodes are connected to three digital pins on the Arduino Board through 220 Ohms resistors. It is important that the pins you use in your Arduino can output PWM signals.

Here’s how you can connect this on a breadboard:

Arduino rgb led circuit

With this setup, you can code different behaviors for the RGB LED. For example, let’s write a program that makes the RGB LED follow a pattern of colors (red, green, blue, cyan, and yellow) that change at intervals of one second.

int redPin= 10;
int greenPin = 9;
int bluePin = 8;

void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

void loop() {
  setRGB(255, 0, 0); // Red Color
  delay(1000);
  setRGB(0, 255, 0); // Green Color
  delay(1000);
  setRGB(0, 0, 255); // Blue Color
  delay(1000);
  setRGB(0, 255, 255); // Cyan Color
  delay(1000);
  setRGB(255, 255, 0); // Yellow Color
  delay(1000);
}

void setRGB(int redValue, int greenValue, int blueValue) {
  analogWrite(redPin, redValue);
  analogWrite(greenPin, greenValue);
  analogWrite(bluePin, blueValue);
}

In the setup function, pins 10, 9, and 8 are configured as outputs. The loop function repeatedly calls the setRGB function to display different colors at one-second intervals. The setRGB function takes three parameters—red, green, and blue values—which can range from 0 to 255. These values are used in the analogWrite function, which outputs PWM signals to control the intensity of each RGB LED channel color.

Questions?

Do you have any questions about RGB LEDs or any feedback you want to share? Let me know in the comments below!

More Light-Emitting Diodes (LED) Tutorials

Leave a Comment