Menu Close

NodeMCU RGB LED on Arduino IDE

This tutorial of Robo India explains how to use RGB LED on NodeMCU using Arduino IDE.

Detailed Tutorial

1. Introduction:

An RGB LED is a combination of 3 LEDs RED, Green and Blue. These three colors Red, green and blue can make any color. By varying supplied voltage to RGB LEDs different colors are formed. In the Node MCU different voltage are supplied using analog output function.

An RGB LED has 4 pin interfaces. 3 Pins are for Red, Blue and Green. There is a common pins for all three LEDs

An RGB LED can be two types-

  1. Common Anode:-Anode (+) pin is common.
  2. Common Cathode:- (Cathode-/GND) pin is common.

1.1 Common Anode Type

1.2 Common Cathode Type

1.3 Hardware required

S.No.ItemQuantity
1NodeMCU 1
2Breadboard 1
3RGB LED 1
4Resistor 1k 3
5Jumper Male to male 6

2. Building Circuit

Schematic of circuit

Layout of circuit

3. Programming:

Once the circuit part is done, NodeMCU is needed to be programmed. Here is the code to run this circuit on NodeMCU.

You may download this code (Arduino Sketch) from here.

// Robo India Tutorial 
// Digital Input and Output on LED 
// Hardware: NodeMCU

const int RED = 5;
const int GREEN = 4;
const int BLUE = 0;

void setup() {
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
}

void loop() { 
  analogWrite(RED, 50);
  analogWrite(GREEN, 50);
  analogWrite(BLUE, 200);  
  delay (1000);
  analogWrite(RED, 100);
  analogWrite(GREEN, 100);
  analogWrite(BLUE, 100); 
  delay (1000);
}

4. Output

After successful uploading of the code, the RGB LED generates two different colors in a time interval of 1 second. Try different set of RGB to get different colors.

5. Troubleshooting

LED is not glowing: LED may be common cathode type, pull it out and check it.

Generate new colors: Try new combination RGB values. The color will be from RGB palette.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply