This tutorial explains how to use RGB LED on NodeMCU using MicroPython.
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.
An RGB LED can be two types-
- Common Anode:-Anode (+) pin is common.
- Common Cathode:- (Cathode-/GND) pin is common.
- NodeMCU - 1
- RGB LED - 1
- Resistor 430Ω - 1
- Jumper Female To Female - 4
Pin Diagram of NodeMCU
- Connect Negative pin of RGB led to GND pin of NodeMCU through a 430Ω resistor.
- Connect Red pin of LED to D5 pin, Green pin to D6 and Blue pin to D7 pin of NodeMCU using Female to Female cables.
- To supply power to NodeMCU you can either use a power supply or simply plug it into your laptop through the USB port.
- Now, our cirucit is complete. We have to load the program for RGB Led colour variations to NodeMcu using Ampy.
- Put the following code in test.py file
import machine import time blue = machine.Pin(14, machine.Pin.OUT) red = machine.Pin(12, machine.Pin.OUT) green = machine.Pin(13, machine.Pin.OUT) while True: green.on() time.sleep_ms(500) green.off() blue.on() time.sleep_ms(500) blue.off() red.on() time.sleep_ms(500) red.off()
- To run this command we have to upload it into NodeMCU using ampy
We do this by executing the command:
ampy --port /dev/tty.SLAB_USBtoUART run test.py
After successful uploading of the code, the RGB LED generates three different colors in a time interval of 500 millisecond. Try different set of RGB to get different colors.
Please do let us know if we are missing any topic or you want us to elaborate any topic, comment below and subscribe to be updated.