ESP8266 IoT Based RGB LED Strip Controller

In this project we are making WiFi based RGB LED Strip Controller using ESP8266 and Arduino IDE. First we make basic RGB LED Controller using NodeMCU to understand How to control RGB LED colors using PWM?. Then we make little advanced RGB LED Strip controller with easy to use color pallet selection user interface as shown below.

NodeMCU RGB LED Control

Before moving directly to the coding let’s see working and types of RGB LED.

How RGB LED Works ?

RGB LED means combination of Red, Blue and Green three LEDs in single package. RGB LED products combine these three colors to produce over 16 million colors of light.

How Color Mixing is done in RGB LEDs?

A single LED die can only emit monochromatic light which could be one of the three primary colors – red, green and blue, known as RGB. To realize more colors, three LED dies need to be used together for RGB color mixing. Commonly 7 colors can be produced by controlling the switch of the channel for each primary color. To produce more than 7 colors, each color channel should be able to change in brightness, not just switched on or off. A popular control method is PWM, of which the cycle duty range determines the available brightness levels. The more the levels are available, the more colors can be produced. Apart from the popularity in applications like outdoor decoration lighting in cities, stage lighting designs, home decoration lighting and LED display matrix, RGB color mixing technology can also be found recently in LCD back lighting and projectors.

RGB LED Color Mixing
RGB LED Color Mixing Driver

What are the types of RGB LEDs ?

RGB LEDs are available in different sizes, shapes and wattage. Most commonly used is RGB LED strip.

Diffused 5mm tri-color LED

Diffused 5mm tri-color LED with separate red, green and blue LED chips inside a 5mm package is used as status indicator for example you can show wifi connectivity status. It has 60 degree viewing angle. Diffused RGB LEDs mix color inside a single LED package instead of appearing as 3 distinct LEDs as shown in below.

5 mm RGB LED

They are available in two types Common-Anode and Common-Cathode type which means you connect one pin to 5V or GND and then tie the other three legs to ground or 5V through a resistor. Most commonly used is Common-Anode more than CC because multi-LED driver chips (such as the TLC5940/TLC5941) are often designed exclusively for CA and can’t be used with Common-Cathode.

5mm RGB LED Specifications

  • 5mm diameter
  • Red: 630 nm wavelength, Green: 525 nm, Blue: 430 nm
  • Red: 2.1-2.5V Forward Voltage, at 20mA current, Green: 3.8-4.5V, Blue: 3.8-4.5V
  • Red: 500 mcd typical brightness, Green: 600 mcd, Blue: 300 mcd

5mm RGB LED pin connections

5mm RGB LED pin Connections
5mm LED pin Connections



These surface-mount LEDs are an easy way to add a lot of colorful dots to your project. They’re commonly used on RGB LED strip, same size and shape. They are half a centimeter on a side, which makes them small but not so small that they are difficult to hand solder. There are three LEDs inside, red green and blue and because they are so close together, they mix very nicely, without the need for a diffuser. The LED is bright 3800mcd.

PIN Connections of SMD 5050 RGB LED

RGB SMD5050 Pin Diagram

Arduino KY-016 RGB LED module

Arduino RGB LED Module
Arduino RGB LED Module

RGB LED module consists of 5mm RGB and current limiting resistors. You can control its full colors using PWM.

Arduino Code for Color Control of RGB LED

This is example code for color control of RGB LED using PWM. Make connections of module to Arduino.

Arduino            RGB LED Module
9                               R
10                            G
11                            B
+5V                         +


These RGB LED strips comes in two types one with RGB SMD 5050 LEDs and another with WS2812 it is programmable LED strip in which you can control each LED color. They have 30, 60, etc RGB LEDs per meter.

RGB LED 5050 Strips

RGB LED Strip 5050
RGB 5050 LED Strip

These types of LED strips can control the entire strip at once with any microcontroller and three transistors or ULN2003. The way they are wired, you will need a 12VDC power supply and then ground the R/G/B pins to turn on the three colors. Use any NPN or N-channel MOSFET and PWM the inputs for color-mixing.

It comes with option weatherproof and uncoated with white or black background color. There’s a 3M adhesive strip on the back which should stick to most smooth surfaces.

You can cut these LED strips pretty easily with wire cutters, there are cut-lines every 10cm (3 LEDs each), and trim off the weatherproof cover with a knife.  They come in 5 meter reels with a connector on it.

RGB LED Strip WS2812 (NeoPixel)

WS2812 (NeoPixel) LED Strip
WS2812 (NeoPixel) LED Strip

These flexible RGB LED strips are an easy way to add complex lighting effects to a project. Each LED has an integrated driver (WS2812) that allows you to control the color and brightness of each LED independently. The combined LED/driver IC on these strips is the extremely compact WS2812B (essentially an improved WS2811 LED driver integrated directly into a 5050 RGB LED), which enables higher LED densities. In the picture you can actually see the +5V, D0 (Data) and GND connections only.

This type of LED Strips requires special type of driver. You can make it using Arduino or ESP8266.

WS2812 Driver Connections
WS2912 LED Driver Connections

ESP8266 RGB LED Controller

In this simple RGB LED control over wifi, web server. we are getting our understanding clear or how color values are applied to RGB LED?

RGB LED Connections with NodeMCU

RGB LED is Common Cathode(GND) type, its common terminal is connected to NodeMCU GND Pin and R, G, B connections are made with NodeMCU using 220 Ohm Resistor at D6, D7 and D8.

NodeMCU RGB LED Connections
RGB LED Connections with Node MCU

NodeMCU RGB LED Controller Arduino IDE Code

Before uploading code enter your SSID and Password.

Results and Testing

After uploading code, open serial monitor and get the IP address.

Connection IP Assigned
Connection IP Assigned

After getting IP address open it in web browser

NodeMCU RGB LED Results

Select the color and press set button. You will see RGB LED also change color according to the selection.

To understand the working of code read some of these posts

  1. How to make HTML Web Server on ESP8266?
  2. Read Form Data in ESP8266
  3. ESP8266 WiFi Connection

NodeMCU RGB LED Strip Mood Lamp Controller

In this we are making full RGB LED Strip controller with cool user interface like mood lamp.

RGB LED Strip Connections with NodeMCU

For Driver you can Use MOSFET, Transistors, ULN2003 or L293D.

ESP8266 Mood Lamp
Mood Lamp Circuit

NodeMCU RGB LED Strip Controller Arduino IDE Code

Code is divided into two parts HTML and NodeMCU Code



This file is little bit bigger due to javascript. Save it as header file in same location where ino file is.

Results and Testing

Open Serial monitor and get the IP address and Enter it in web browser.

Try operating it and see the color changes. Below is my test setup with NodeMCU and RGB LED Strip.

Mood Lamp Testing

Refer for more details

  1. Update part of web page without refresh
  2. Weather Station
  3. Real time data logging with graphs
  4. ESP8266 Handle Web Forms data



Leave a Reply