What Is an RGB LED Module?

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.

How RGB LEDs Work

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.

What You’ll Need

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

Hardware

HW-479 RGB LED Module Jumper wires (if using the analog method) Arduino

Software

The Arduino IDE or The PlatformIO extension for Visual Studio Code

How to Use an RGB LED Module Using the Digital Method

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.

Preparing the Code

This is the full version of the code:

Building the Circuit

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.

Making It Work

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: Just starting out with microcontrollers? Check out our Arduino Uno and ESP32 comparison to decide which one you should get.

How to Use an RGB LED Module Using the PWM Method

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.

Preparing the Code

Building the Circuit

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.

Making It Work

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. All images by Terenz Jomar Dela Cruz.