Login

Interface RGB LED with NodeMCU

Objectives

  • Connect an RGB LED to the NodeMCU
  • Make the LED glow RED, GREEN and BLUE alternatively

Things

  1. NodeMCU board (quantity: 1 no.)
  2. Micro USB cable A to B (quantity: 1 no.)
  3. Breadboard (quantity: 1 no.)
  4. Common Cathode RGB LED module (quantity: 1 no.)
  5. Jumper wire – male to male (quantity: 4 no.)
  6. Arduino IDE on your computer

Let’s begin!

RGB stands for Red, Green, Blue. The combination of these three colors can produce over 16 million hues.

An LED having the ability to glow Red, Blue, and Green is called an RGB LED. There are two different types of RGB LEDs namely common cathode RGB LED and common anode RGB LED.

The RGB LED has four different pins, three for the Red, Green and Blue LEDs and the remaining pin for common anode or common cathode, which will be the longest pin. So it actually consists of three different LEDs in one.

 

Common Cathode (-) RGB LED             Common Anode (+) RGB LED

 

If you are using the RGB LED as it is, you will have to include a few series resistors (200Ω to 5kΩ depending on required brightness) to each color pin of the LED. This has to be done so that the LED doesn’t burn out due to excess current flowing in the circuit.

Note: 

  • For the Common Cathode RGB LED, the common pin is connected to ground and the voltage supplied for each color pin will be the voltage output of the Arduino Pin it is connected to.
  • For the Common Anode RGB LED, the common pin is connected to VCC and the voltage supplied for each color pin will be equal to VCC minus voltage output of the Arduino Pin it is connected to.

You can also get the Common Cathode type and the Common Anode type RGD LEDs in well-packaged modules with all the necessary resistors embedded into the circuitry.

 

Common Cathode (-) RGB LED module          Common Anode (+) RGB LED module 

To complete this project, we will use the common cathode (-) RGD LED module.

Using a Breadboard

A breadboard is used to make connections between controller boards like the NodeMCU and components like the RGB LED. A breadboard has internal connections in the following manner

Interfacing Common Cathode (-) RGB LED module with NodeMCU

 

Interfacing Common Cathode (-) RGB LED module with NodeMCU

 

Making Colors on the RGB LED

Giving a voltage on one of the color pins will switch on the LED corresponding to that pin. This means that giving a voltage at the R pin will switch on the RED LED, the G pin will switch on the GREEN LED, and the B pin will switch on the Blue LED.

Since we have digital pins (D5, D6, D7) of the NodeMCU connected to each of the LED pins (R, G, B) of the RGB LED module, we can give a high voltage to the LED pins using the digital pins of the NodeMCU.

Note that it is also possible to give a voltage to multiple pins at once.

Final Code

To copy the code, right click on view raw at the bottom of the code, click on open link in new tab and then copy the code.

There you go!

Takeaway

Loader Loading...
EAD Logo Taking too long?
Reload Reload document
| Open Open in new tab

We would love to see what you build out of these learnings!

Click here to submit your projects, share it with the world and stand a chance to be rewarded.

top

Knowledge and Content by Li2 Technologies | © 2021 NASSCOM Foundation | All rights reserved

X