How to Use an RGB LED Module With Arduino

by Leonel Mosciski
19 minutes read

How to Use an RGB LED Module With Arduino

Hw 479 Rgb Pioneered Module On Arduino Amenity Image

Conceivably one of the most widespread modules in an Arduino starter scheme, the RGB LED permits you architecture with one voice sorts of colors via simply 4 pins from the Arduino. This tutorial performances 2 approaches to use this module, so read on to learn how perfectly it jobs!

Content
  • How RGB LEDs Job
  • What You’ll Last offer
  • How to Service an RGB LED Module Swiping advantage of the Digital Ideology
  • How to Service an RGB LED Module Swiping advantage of the PWM Ideology
  • Consistently Inspected Misgivings

What Is an RGB LED Module?

An RGB LED module uses a meaningful kind of LED light that can give off three colors: red, green, as well as blue. Yet, you can render any kind of shade you can possibly picture by revolutionizing which one is swivelled on as well as mixing up each one’s luminosity.

Rgb Pioneered

There are 2 approaches to go around lights an RGB LED module on any kind of Arduino board. The usual tactic is to use the Arduino’s analog pins to send PWM signals to the module. This permits you mix each shade, alignment you complete readjust over the RGB LED.

Meanwhile, the other (digital) substitute is to use pins 11, 12, 13, as well as GND by affixing the module to the Arduino as you would understandably via a shield. This saves elbowroom by not demanding jumper wires for every pin, but it implements fete okay readjust over the LED’s hue as well as luminosity. Even more, the arrangement lone jobs if the module has pins that accommodate suitably on the Arduino board, such as the HW-479 that we’re amassing utilise of in this overview.

How RGB LEDs Job

At this juncture, you may be asking yourself how a singular RGB LED module releases three colors. You may be alarmed to learn that an RGB LED is not really simply one elaborate LED but three smaller LEDs encased in a bigger LED. These mini LEDs share unchanged grounding pin, which have to be the longest of the 4 pins in an RGB LED.

Rgb Smd Pioneered
Image resource: Wikimedia Commons

If you have a bare RGB LED instead of a module in a breakout board, you can render something akin to a module by affixing resistors on each of the shade pins. The resistance payoff differs per fitter, but 220Ω per leg is a safe bet.

Suggestion: learn how to power light hair follicle amassing utilise of Arduino via a relay module.

What You’ll Last offer

If you’re willing to avail initiated, you’ll telephone call for these things to avail this project off the ground.

Hardware

  • HW-479 RGB LED Module
  • Jumper wires (if amassing utilise of the analog tactic)
  • Arduino

Software

  • The Arduino IDE or
  • The PlatformIO expansion for Visual Workshop Code

How to Service an RGB LED Module Swiping advantage of the Digital Ideology

This tactic lone jobs on Arduino boards via a GND pin chummy to pin 13. Examples are the Uno, Duemilanove, Astronomical, as well as Leonardo. If you have an uncorroborated Arduino-based microcontroller board, render sure that it’s amassing utilise of female pin headers. RGB LED modules are basically in male headers.

Readying the Code

  1. First, event the pins: 11 for blue, 12 for green, as well as 13 for red.
const int blueLED = 11; const int greenLED = 12; const int redLED = 13;
  1. On setup(), event these pins as result pins.
void setup() {   pinMode(blueLED, OUTPUT);   pinMode(greenLED, OUTPUT);   pinMode(redLED, OUTPUT); }
  1. On loop(), contain power to one pin, pause the code for 1000 nanoseconds (1 second), then revolve on the next one till with one voice pins are powered. Finally, revolve them off one by one.
void loop() {   digitalWrite(blueLED, HIGH);   delay(1000);   digitalWrite(greenLED, HIGH);   delay(1000);   digitalWrite(redLED, HIGH);   delay(1000);   digitalWrite(blueLED, LOW);   delay(1000);   digitalWrite(greenLED, LOW);   delay(1000);   digitalWrite(redLED, LOW);   delay(1000); }

This is the complete iteration of the code:

const int blueLED = 11; const int greenLED = 12; const int redLED = 13;   void setup() {   pinMode(blueLED, OUTPUT);   pinMode(greenLED, OUTPUT);   pinMode(redLED, OUTPUT); }   void loop() {   digitalWrite(blueLED, HIGH);   delay(1000);   digitalWrite(greenLED, HIGH);   delay(1000);   digitalWrite(redLED, HIGH);   delay(1000);   digitalWrite(blueLED, LOW);   delay(1000);   digitalWrite(greenLED, LOW);   delay(1000);   digitalWrite(redLED, LOW);   delay(1000); }

Constructing the Circuit

The circuit is humble. Juncture the “-” pin on the RGB LED module to the Arduino’s GND pin. If you straighten it apt, the other three pins have to enter pins 13, 12, as well as 11.

Hw 479 Rgb Pioneered Module Uninfluenced Positioned On Arduino Uno

Making It Job

Once you’ve uploaded the code to the Arduino, you have to appointment the colors on the RGB LED readjust every second.

You can modify the code as well as render it portray 2 or with one voice colors at unchanged time by turning them to HIGH together before the delay() purpose, choose this:

digitalWrite(redLED, HIGH); digitalWrite(greenLED, HIGH); delay(1000);

How to Service an RGB LED Module Swiping advantage of the PWM Ideology

This tactic gives finer readjust compared to the previous tactic. The shade of the LED relies on the proportion of obligation cycles in between pins 9, 10, as well as 11. The greater the proportion in the standard of one shade, the stronger it comes to be in the mix.

Just as, optimizing the obligation cycle augments the LED’s luminosity. If you boom with one voice of the obligation cycles while expanding unchanged proportion, you’ll run out up via a horribly gruel RGB LED.

Readying the Code

  1. Delineate the pins: 9 for blue, 10 for green, as well as 11 for red.
const int blueLED = 9; const int greenLED = 10; const int redLED = 11;
  1. Rotate these apt into result pins.
void setup() {   pinMode(blueLED, OUTPUT);   pinMode(greenLED, OUTPUT);   pinMode(redLED, OUTPUT); }
  1. On loop(), use the analogWrite() purpose instead of digitalWrite() to readjust the pins’ obligation cycles. The process is similar to amassing utilise of PWM to readjust servo motors via a Raspberry Pi, except that we’re amassing utilise of C++ instead of Python.
void loop() {   analogWrite(greenLED, 25);   analogWrite(blueLED, 50);   delay(250);   analogWrite(greenLED, 50);   delay(250);   analogWrite(greenLED, 100);   delay(250);   analogWrite(greenLED, 150);   delay(250);   analogWrite(greenLED, 125);   delay(250);   analogWrite(greenLED, 80);   delay(250);   analogWrite(greenLED, 40);   delay(250);   analogWrite(greenLED, 20);   delay(250);   analogWrite(greenLED, 0);   delay(250); }

Constructing the Circuit

Swiping advantage of jumper wires, connect pins B, G, as well as R to pins 9, 10, as well as 11. Fasten the GND or pin to any kind of of the Arduino’s GND pins.

Hw 479 Rgb Pioneered Module Wired To Arduino 1

Making It Job

You may have picked up that we lone earned serviceability of 2 colors this time: green as well as blue. That’s to render it less center to appointment the brunts of revolutionizing the ratios on the RGB LED’s entirety quantity shade. The LED aesthetic elegances deep blue as well as rotates turquoise before having an orgasm apt into a green cyan, then fading endorse to a deep blue.

Just as, you can fuse this via the previous tactic by amassing utilise of pin 11 as an analog pin to readjust the luminosity of the blue pin.

Pain another fun project to attempt? Learn how to use a Raspberry Pi to render an Arduino Uno blink.

Consistently Inspected Misgivings

What happens if I contain an auxiliary resistor on the RGB LED module?

RGB LED modules already have prefabricated-in resistors. If you contain another, you’ll simply render your own dimmer than it have to have been while dashing on unchanged quantity of voltage as well as present.

What gains an LED light up?

LEDs architecture light through a process termed electroluminescence, a domestic of particular items that lights up once affected by an electro-magnetic area. They are rendered from gallium-based semiconductors that give off light instead of heat.

Why put on’t LEDs light up once wired the opposite way?

LEDs are diodes – hence, the name light-saving diodes. With one voice diodes make it feasible for power enact through from one side but not from the other. Their cathode as well as anode percentages are basically rendered from 2 polymorphous items that, once pressed together, compel electrons to spend auxiliary power to go the other way, choose a automotive travelin a high uphill path.

Why execute TVs use red LEDs?

Contrasted to other LEDs, red LEDs can vibrantly light up amassing utilise of much less power compared to other tinted LEDs owning unchanged size, which gains them nice wills as indicator LEDs once TV technicians scheme for power efficacies in their items.

With one voice images by Terenz Jomar Dela Cruz.

Related Posts