Random Nerd Tutorials

Electronics Basics – How do RGB LEDs work?


With an RGB LED you can produce almost any color. 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 color produced by the RGB LED is a combination of the colors of each one of these three LEDs. 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:

rgb led

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.


color mixing


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:

rgb led pin

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 need the following parts (click the links below to find the best price at Maker Advisor):


You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!


Follow these schematics to complete the project:

rgb led_potentiometer

Important: If you’re using an RGB LED common cathode, you need to connect the longer lead to GND.


Upload the following sketch to your Arduino board:

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.


Watch this quick video demonstration to see this project in action:

I hope you found this guide useful.

Share this post with a friend that also likes electronics!

You can contact me by leaving a comment. If you like this post probably you might like my next ones (click here to subscribe my blog).

Thanks for reading,

-Rui Santos

MicroPython Programming with ESP32/ESP8266 eBook

Learn how to program the ESP boards with MicroPython, including projects, tips, and tricks! The registrations are open for a limited time, so SIGN UP NOW »

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our course even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Registrations are open for "MicroPython Programming with ESP32 and ESP8266" eBook