How to Use an RGB LED Module With Arduino
HomeHome > Blog > How to Use an RGB LED Module With Arduino

How to Use an RGB LED Module With Arduino

May 31, 2023

Perhaps one of the most common modules in an Arduino starter kit, the RGB LED lets you create all sorts of colors with just four pins from the Arduino. This tutorial demonstrates two ways to use this module, so read on to learn how well it works!

An RGB LED module uses a special kind of LED light that can emit three colors: red, green, and blue. However, you can make any color you could possibly think of by changing which one is turned on and mixing up each one's brightness.

There are two ways to go about lighting an RGB LED module on any Arduino board. The usual method is to use the Arduino's analog pins to send PWM signals to the module. This lets you mix each color, giving you full control over the RGB LED.

Meanwhile, the other (digital) option is to use pins 11, 12, 13, and GND by attaching the module to the Arduino as you would with a shield. This saves space by not requiring jumper wires for every pin, but it does exchange fine control over the LED's hue and brightness. Furthermore, the setup only works if the module has pins that fit properly on the Arduino board, such as the HW-479 that we're using in this guide.

At this point, you may be wondering how a single RGB LED module emits three colors. You may be surprised to learn that an RGB LED is not really just one fancy LED but three smaller LEDs encased in a larger LED. These mini LEDs share the same grounding pin, which should be the longest of the four pins in an RGB LED.

If you have a bare RGB LED instead of a module in a breakout board, you can make something akin to a module by attaching resistors on each of the color pins. The resistance value varies per manufacturer, but 220Ω per leg is a safe bet.

Tip: learn how to power light bulbs using Arduino with a relay module.

If you're ready to get started, you'll need these items to get this project off the ground.

This method only works on Arduino boards with a GND pin next to pin 13. Examples are the Uno, Duemilanove, Mega, and Leonardo. If you have an unofficial Arduino-based microcontroller board, make sure that it's using female pin headers. RGB LED modules are typically in male headers.

This is the full version of the code:

The circuit is simple. Point the "-" pin on the RGB LED module to the Arduino's GND pin. If you align it right, the other three pins should enter pins 13, 12, and 11.

Once you've uploaded the code to the Arduino, you should see the colors on the RGB LED change every second.

You can edit the code and make it show two or all colors at the same time by turning them to HIGH together before the delay() function, like this:

This method gives finer control compared to the previous method. The color of the LED depends on the ratio of duty cycles between pins 9, 10, and 11. The greater the ratio toward one color, the stronger it becomes in the mix.

Also, increasing the duty cycle boosts the LED's brightness. If you increase all of the duty cycles while keeping the same ratio, you'll end up with a very bright RGB LED.

Using jumper wires, connect pins B, G, and R to pins 9, 10, and 11. Connect the GND or pin to any of the Arduino's GND pins.

You may have noticed that we only used two colors this time: green and blue. That's to make it easier to see the effects of changing the ratios on the RGB LED's overall color. The LED looks deep blue and turns turquoise before climaxing into a greenish cyan, then fading back to a deep blue.

Also, you can combine this with the previous method by using pin 11 as an analog pin to control the brightness of the blue pin.

Want another fun project to try? Learn how to use a Raspberry Pi to make an Arduino Uno blink.

RGB LED modules already have built-in resistors. If you add another, you'll just make yours dimmer than it should have been while running on the same amount of voltage and current.

LEDs create light through a process called electroluminescence, a property of certain materials that lights up when affected by an electromagnetic field. They are made from gallium-based semiconductors that emit light instead of heat.

LEDs are diodes – hence, the name light-emitting diodes. All diodes let electricity pass through from one side but not from the other. Their cathode and anode parts are typically made from two different materials that, when pressed together, force electrons to spend more energy to go the other way, like a car travelin a steep uphill path.

Compared to other LEDs, red LEDs can brightly light up using less energy compared to other colored LEDs having the same size, which makes them great options as indicator LEDs when TV manufacturers plan for energy efficiency in their products.

All images by Terenz Jomar Dela Cruz.

Terenz is a hobbyist roboticist trying to build the most awesome robot the world has ever seen. He could have done that already if he wasn't so busy burning through LEDs as a second hobby.

Our latest tutorials delivered straight to your inbox

How to Turn On Google Sheets Dark Mode

6 Great Outlook Alternatives for All Platforms

How to Create an Excel Dashboard

How to Fix the Steam Login Error Code E87 on Windows

How to Install Kali Linux NetHunter on Android Phone

How to Hide Instagram Account and Prevent Other Users from Finding You

TV Not Connecting to Wi-Fi? Here's How to Fix the Problem

How to Check Whether a Power Bank Is Allowed on a Plane

Affiliate Disclosure: Make Tech Easier may earn commission on products purchased through our links, which supports the work we do for our readers.

TipAffiliate Disclosure: