Blynk controlled WS2812 Neopixel LED Strip using NodeMCU

Blynk controlled WS2812 Neopixel LED Strip using NodeMCU and Arduino IDE

LEDs are used in almost every decorative lightings, but most of them only produce a single color. So to create a beautiful light pattern, multiple colors LED strips are used, which are, not only consumes more power but also hard to manage. Today we are using the new generation LED- NeoPixel, which can produce 16.8 million colors. NeoPixels are programmable, and with the right programming, it can create many beautiful lighting patterns. Here a NodeMCU and Blynk app will be used to control the color and brightness of NeoPixel LED strip over the internet. Blynk is a smartphone application, using which we can control any IoT based Application through our smartphone.

 

Components Required

  • WS2812b LED Strip- 1 metre
  • 5V,2 AMP Power supply
  • ESP8266 NodeMCU
  • LED Strip connectors

 

WS2812 NeoPixel LED Strip Working

WS2812 NeoPixel LED Strip

WS2812 LED strips are addressable and programmable Flexible LED strips which are very useful in creating the custom lighting effects. These LED Strips are powered by a 5050 RGB LED with a WS2812 LED driver inbuilt within it. Each LED consumes 60mA current and can be powered from a 5V DC supply. It has a single input data pin which can be fed from the digital pins of Microcontrollers.

 

Features: 

  • Individually addressable RGB LEDs
  • 16.8 million colors per pixel
  • Single-wire digital control
  • Operating Voltage: 5V DC
  • Current Requirement: 60mA per LED
  • Flexible LED structure
  • 5050 RGB LED with WS2812 driver

 

Connection diagram:

Circuit diagram for NeoPixel NodeMCU is given below:

NeoPixel NodeMCU Circuit Diagram

 

Below image shows the setup for NeoPixel ESP8266

NeoPixel ESP8266 Setup

 

Blynk Application Setup for controlling NeoPixel

Blynk is an application that runs over Android and IOS devices to control any IoT based application using Smartphones. We previously used Blynk with NodeMCU and Raspberry Pi to control an LED and also build a weather station using the Blynk app. It allows you to create your Graphical user interface for IoT application. Here we will set up the Blynk application to control NeoPixel LED over Wi-Fi using NodeMCU ESP8266.

So first download and install the Blynk Application from Google Play store (IOS users can download from App Store) and sign-up using your Email id and Password.

 

Creating a new Project: 

After successful installation, open the application and click on “New Project”. Then it will pop up a new screen, where we need to set the parameters like Project name, Board and connection type. For this NeoPixel ESP8266 project select the device as NodeMCU and connection type as Wi-Fi and click on “Create”.

After the successful creation of the Project, we will get an Authenticate ID on registered mail. Save the Authenticate ID for future reference.

Blynk Application Setup for Controlling NeoPixel LED Strip

 

Creating the GUI: 

Open the project in Blynk, click on the “+” sign to add the widgets to control the NeoPixel. In our case, we need an RGB Color Picker which is listed as “zeRGBa” and a slider that will be used for brightness control of the LED strip.

Creating GUI for Controlling Neopixel LED Strip

 

Setting the Parameter in Widgets: 

After dragging the widgets, they now set their parameters which are used to send the color and brightness values to NodeMCU.

Click on ZeRGBa, to go into ZeRGBa setting and set the Output option to “Merge” and set the pin to “V3” which is shown in the image below. Similarly, in Slider settings, set the output pin to “V2.”

NeoPixel LED Strip Parameter Settings

 

Programming NodeMCU to control NeoPixel using Wi-Fi

After successful completion of the Blynk application setup, now upload the code in NodeMCU using Arduino IDE.

To program NodeMCU with Arduino IDE go to File–>Perferences–>Settings.

Programing NodeMCU with Arduino IDE for IoT based Temperature and Humidity Monitor

 

Enter https:// arduino.esp8266.com/stable/package_esp8266com_index.json into the ‘Additional Board Manager URL’ field and click ‘Ok’.

 Add URL to Arduino IDE for IoT based Temperature and Humidity Monitor

 

Now go to Tools > Board > Boards Manager.

Manage Board in Arduino IDE for IoT based Temperature and Humidity Monitor

 

In Boards Manager window, Type esp in the search box, esp8266 will be listed there below. Now select the latest version of the board and click on install.

Install ESP8266 Library to Arduino IDE for IoT based Temperature and Humidity Monitor

 

After installation is complete, go to Tools >Board >and select NodeMCU 1.0(ESP-12E Module). Now you can program NodeMCU with Arduino IDE.

 

Complete code along with the video is given at the end. The step-wise explanation of the code is shown below.

 

First of all, including all the required libraries. Open Arduino IDE, then go to the tab Sketch and click on the option Include Library-> Manage Libraries. Then search for Blynk in the search box and then download and install the Blynk package for ESP8266.

For including FastLED.h library, download the library from here and include it using Include ZIP Library option.

#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#define FASTLED_ESP8266_RAW_PIN_ORDER
#include "FastLED.h"

 

Now, define all the parameters like the number of LEDs used, LED type and color order in the code. Also, define the data PIN D1 where the data input pin of RGB LED is connected. Then, define your Wi-Fi user name and password in ssid[] and pass[] an array. Inside auth[] array, write the Blynk authenticate ID which we saved earlier.

#define NUM_LEDS1 60
#define LED_TYPE    WS2812
#define COLOR_ORDER GRB
CRGB leds1[NUM_LEDS1];
char auth[] = "XXXXaL9U92cXXXXXXXXXXXX";
char ssid[] = "admin";
char pass[] = "12345678";
#define PIN1 D1

 

Inside setup() function, initialize the serial communication using Serial.begin and connect to the Blynk cloud using Blynk.begin. Also, set the LED type and number of LEDs using FastLED.addLeds.

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  FastLED.addLeds<LED_TYPE, PIN1, COLOR_ORDER>(leds1, NUM_LEDS1).setCorrection( TypicalLEDStrip );
}

 

Inside infinite loop (), we have used Blynk.run () to check the incoming commands from Blynk GUI and executes the operations accordingly.

void loop()
{
  Blynk.run();
}

 

Here BLYNK_WRITE function is written to check for incoming data at V3 and V2 Virtual terminal, then assign them in three different variables. The variable r, g, b here represents the value of Red, Green and Blue code of the selected color. Similarly, here data is used for storing the brightness value of the LED. Then these values are sent to the function static1 which is used for driving the LED strip.

BLYNK_WRITE (V3)
{
  r = param[0].asInt();
  g = param[1].asInt();
  b = param[2].asInt();
  static1(r, g, b,data);
}

BLYNK_WRITE(V2)
{
data = param.asInt();
static1(r, g, b,data);
}

 

Static1 () function is used to drive the LED strip and to control the brightness of the LED strip. And FastLED.setBrightness is used to set the brightness of the LED. Similarly FastLED.show function is used for driving the LED as per the required color.

void static1(int r, int g, int b,int brightness)
{
  FastLED.setBrightness(brightness);
  for (int i = 0; i < NUM_LEDS1; i++ )
  {
    leds1[i] = CRGB(r, g, b);
  }
  FastLED.show();
}

 

After uploading the complete code into NodeMCU using Arduino IDE, you can control the color and brightness of NeoPixels LED strips from the Blynk mobile app, as shown in the picture below.

Blynk controlled WS2812 Neopixel LED Strip

 

Blynk controlled WS2812 Neopixel LED Strip

Find below the complete code and working video for this ESP8266 NeoPixel Wi-Fi control.

Code

#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#define FASTLED_ESP8266_RAW_PIN_ORDER
#include "FastLED.h"
#define NUM_LEDS1 60
#define LED_TYPE    WS2812
#define COLOR_ORDER GRB
CRGB leds1[NUM_LEDS1];
char auth[] = "fu0oXXXX9U92cXXXXXXX";
char ssid[] = "admin";
char pass[] = "12345678";
#define PIN1 D1
int data=255;
int r,g,b;
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  FastLED.addLeds<LED_TYPE, PIN1, COLOR_ORDER>(leds1, NUM_LEDS1).setCorrection( TypicalLEDStrip );
}

BLYNK_WRITE(V3)
{
  r = param[0].asInt();
  g = param[1].asInt();
  b = param[2].asInt();

  static1(r, g, b,data);
}

void loop()
{
  Blynk.run();
}
BLYNK_WRITE(V2)
{
data = param.asInt(); 
static1(r, g, b,data);
}
void static1(int r, int g, int b,int brightness)
{
  FastLED.setBrightness(brightness);
  for (int i = 0; i < NUM_LEDS1; i++ )
  {
    leds1[i] = CRGB(r, g, b);
  }
  FastLED.show();
}

 

Video

7 Comments

Hello. Works really well but i cant figure out this error. Every led has different color except of when I press white one. Could you please help me? thank you!

I suspect your problem is with the
define COLOR_ORDER GRB
try different orders based on how your colors are messed up: IE, if when you set Green it lights Blue and "Blue" shines Green then try "BRG" instead of "GRB".
The manufacturer of your light strip may also specify the color output (mine was GRB matching the tutorial). If you want to try and skip some troubleshooting try "RGB" instead - it's another common mode.

Srinivas Arikrishnan

26 April 2021

Hello sir its great project to test it out. I'm trying to replicate the same project as you did but im having issue like if i select any color from the zeRGBa it display mix color for example if i choose blue the led strip lights up in mix of color like red purple green and some other colors too. For every 3 leds it display different color.
Can you please help me ? Thank you in advance

Hi, awesome project. I have small problem. When I change color on smartphone first led is different color than other leds, so I need to click couple of times on phone to get them all to be the same color. Help me, please.

Thanks in advance.

can you help me making same project with new blynk app 2.0 as zergba settings are different in new addition of app.
do we require to frame new code or so please help
thanks in advance