Controlling WS2812 NeoPixel LED with ESP32 using Blynk App

Controlling WS2812 NeoPixel LED with ESP32 using Blynk App

NeoPixel LED Strip Lights are programmable RGB LED strip which can be programmed to generate any desired lighting pattern. NeoPixel can produce multiple colors in any combination and brightness. It consumes less power and can be addressed individually via programming. In this project, we will learn to control the WS2812 NeoPixel LED strips using ESP32 and Blynk application.

 

Components Required

  • 25 LEDs WS2812B NeoPixel LED Strip
  • 5V, 2 AMP Power supply
  • ESP32 Development board
  • Breadboard
  • Jumper wires

 

WS2812 LED Strip Working

WS2812 LED Strip Working

WS2812 LED strips are an addressable Flexible strip which is very useful in adding beautiful 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 Micro-controllers.

 

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

 

Circuit Diagram

Circuit diagram for WS2812 ESP32 is given below:

WS2812 ESP32 Circuit Diagram

WS2812 NeoPixel LED with ESP32

 

Blynk Application Setup for NeoPixel with ESP32

Blynk is an application that can run over Android and IOS devices to control any IoT devices using our smartphones. We can create our own Graphical user interface to design the IoT application GUI. We previously used Blynk with ESP32 and built many other IoT based projects using Blynk.

Before setup, download the Blynk Application from Google Play store (IOS users can download from Apple 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 project, select the device as “ESP32 Dev Board and connection type as Wi-Fi and click on “Create”.

Blynk Application Setup

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

 

Creating the GUI:

Open the project in Blynk, click on the “+” sign where it will show many widgets. In our case, we need an RGB Color Picker which is listed as “zeRGBa” and a Button which will be used for changing the mode of operation in the LED strip.

Creating GUI in Blynk

 

Setting the Parameter in Widgets:

After dragging the widgets to the project, now set its parameters which are used to send the color and mode of control values to ESP32.

Click on ZeRGBa, then we will get a screen named ZeRGBa setting. Then set the Output option to “Merge” and set the pin to “V2” which is shown in the image below. Similarly, in Button settings, set the output pin to “V3” as shown in the figure below.

Blynk Application Setup for NeoPixel

 

Installing ESP32 Board in Arduino IDE

Before uploading the code into ESP32, we need to install the board in Arduino IDE, if you haven’t done it earlier. To install ESP32 board follows the steps below:

1. Open Arduino IDE, go to FilePreferences

Arduino IDE

 

2. Type “https://dl.espressif.com/dl/package_esp32_index.json” in the Additional Board Manager URL’ field and click ‘Ok’. If you already have other URLs in that field, write this by separating it using a comma (“,”). 

Installing ESP32 Board In Arduino IDE

 

3. Now go to Tools > Board > Boards Manager. In the Boards Manager window, Type ESP32 in the search box, select the latest version of the board ESP32 by espressif systems, and click on install.

Installing ESP32 Board In Arduino IDE

 

4. After installation is complete, go to Tools ->Board -> and select ESP32 Dev ModuleNow you can program the ESP32 with Arduino IDE.

 

Code for ESP32 NeoPixel LED Strip Control

Complete code for ESP32 NeoPixel is given at the end of this tutorial. The step-wise explanation of the code is shown below. 

 

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

 

Here “Adafruit_NeoPixel.h” is used for controlling the RGB LED strip. For including Adafruit_NeoPixel.h library, download the library from this link and include it using the “Include ZIP Library” option.

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_NeoPixel.h>

 

Then define the number of LEDs which is used in the LED strip and also the PIN number which is used to control the LED parameters. 

#define PIN 15
#define NUM 25

 

After this, declare the NeoPixel strip object where Argument 1 is the number of pixels in the NeoPixel strip, Argument 2 is the ESP32 PIN number used and Argument 3 is Pixel type flags.

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM,PIN, NEO_GRB + NEO_KHZ800);

 

Then, define the network credentials such as network SSID and password. Write your own network credentials in place of ssid[] and pass a [] array. Inside auth[] array, write the Blynk authenticate ID which we have saved earlier.

char auth[] = "HoLYSq-SGJAafQUQXXXXXXXX";
char ssid[] = "admin";
char pass[] = "12345678";

 

Inside setup(), Serial communication is initialized using function Serial.begin. Here Blynk is connected using Blynk.begin and NeoPixel LED strip is initialized using pixels.begin().

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  pixels.begin();
}

 

Inside infinite loop (), we have used Blynk.run () which checks for 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. Then these values are sent to the function static1 which is used for driving the LED strip.

BLYNK_WRITE(V2)
{
r = param[0].asInt();
g = param[1].asInt();
b = param[2].asInt();
if(data==0)
static1(r,g,b);
}
BLYNK_WRITE(V3)
{
data = param.asInt();
Serial.println(data);
if(data==0)
{
  static1(r,g,b);
}
else if(data==1)
{
  animation1(); 
}
}

 

Static1 () function is used to drive the LED strip with distinct colors. Here, pixels.setPixelColor is used for driving the LED as per our required color.

void static1(int r, int g, int b)
{
  for(int i=0;i<=NUM;i++)
  {
pixels.setPixelColor(i, pixels.Color(r,g,b));
  pixels.show();
  }
}

 

Animation1() function is used to run a customized animation using LEDs. Different animations can be made as per the user's choice as shown below. 

void animation1()
{
  for(int i=0;i<NUM;i++)
  {
    pixels.setPixelColor(i, pixels.Color(255,0,0));
    pixels.show();
    delay(100);
  }
  for(int i=NUM;i>=0;i--)
  {
    pixels.setPixelColor(i, pixels.Color(0,255,0));
    pixels.show();
    delay(100);
  }
  for(int i=0;i<NUM;i++)
  {
    pixels.setPixelColor(i, pixels.Color(0,255,255));
    pixels.show();
    delay(100);
  }
  for(int i=NUM;i>=0;i--)
  {
    pixels.setPixelColor(i, pixels.Color(255,255,0));
    pixels.show();
    delay(100);
  }
}

 

Testing NeoPixel with ESP32

After successful completion of hardware connection, upload the complete code in ESP32 and you will find the illuminated NeoPixels according to your program.

Controlling WS2812 NeoPixel LED with ESP32

Complete code and a demonstration video for this NeoPixel control using ESP32 are given below.

Code

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Adafruit_NeoPixel.h>
#define PIN 15
#define NUM 25
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM,PIN, NEO_GRB + NEO_KHZ800);
char auth[] = "HoLYSq-Sxxxx";
char ssid[] = "admin";
char pass[] = "12345678";
int r,g,b,data;
void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  pixels.begin();
}
void loop()
{
  Blynk.run();
}
BLYNK_WRITE(V2)
{
r = param[0].asInt();
g = param[1].asInt();
b = param[2].asInt();
if(data==0)
static1(r,g,b);
}
BLYNK_WRITE(V3)
{
data = param.asInt();
Serial.println(data);
if(data==0)
{
  static1(r,g,b);
}
else if(data==1)
{
  animation1(); 
}
}
void static1(int r, int g, int b)
{
  for(int i=0;i<=NUM;i++)
  {
  pixels.setPixelColor(i, pixels.Color(r,g,b));
  pixels.show();
  }
}
void animation1()
{
  for(int i=0;i<NUM;i++)
  {
    pixels.setPixelColor(i, pixels.Color(255,0,0));
    pixels.show();
    delay(100);
  }
  for(int i=NUM;i>=0;i--)
  {
    pixels.setPixelColor(i, pixels.Color(0,255,0));
    pixels.show();
    delay(100);
  }
  for(int i=0;i<NUM;i++)
  {
    pixels.setPixelColor(i, pixels.Color(0,255,255));
    pixels.show();
    delay(100);
  }
  for(int i=NUM;i>=0;i--)
  {
    pixels.setPixelColor(i, pixels.Color(255,255,0));
    pixels.show();
    delay(100);
  }
}

Video

15 Comments

Great intractable, but I do get a lot of these:

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

>>>stack>>>

ctx: cont
sp: 3ffffc90 end: 3fffffc0 offset: 01a0
3ffffe30: 40203aa8 3ffee9a8 0000012b 3ffee8e8
3ffffe40: 0000012d 3ffee8e8 000000b5 402012a4
3ffffe50: 3ffee920 00000003 3ffee9a8 00000009
3ffffe60: 3ffee920 00000003 3ffee8d8 4020141c
3ffffe70: 00000000 00000003 3fffff0e 40201810
3ffffe80: 007a1200 ecf0cb90 4bc6a700 4021086e
3ffffe90: 3fffff05 00000009 00000009 3fffff00
3ffffea0: 00000003 00000000 4bc6a7f0 3fffff05
3ffffeb0: 3fffff0e 3fff7776 401002f2 1db22d0e
3ffffec0: 0000000e 00000005 0000000d 40204c82
3ffffed0: 00000000 3fffff00 3ffee920 3fffff00
3ffffee0: 00000000 3fffff00 3ffee920 40201bcc
3ffffef0: 3fffdad0 3ffee944 3ffee920 402018e4
3fffff00: 33007776 34003000 32003637 00003734
3fffff10: 00000000 00000000 00000000 3ffeead4
3fffff20: 00000000 0e56fe14 00000000 3ffeead4
3fffff30: 3fffdad0 3ffee944 00000000 40204634
3fffff40: 0000000e 3ffee944 3ffee920 40204c82
3fffff50: 3fffdad0 3ffee944 3ffee920 3ffeead4
3fffff60: 3fffdad0 3ffee944 3ffee920 40201e52
3fffff70: 00000000 00000000 40206910 0c52530a
3fffff80: 00000000 00000000 00000001 3ffeead4
3fffff90: 3fffdad0 00000000 3ffeea94 40202077
3fffffa0: feefeffe 00000000 3ffeea94 4020474c
3fffffb0: feefeffe feefeffe 3ffe851c 40100d29
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

I changed the number of LEDs from 25 to 300, and that seems to cause the crash.

1. Why do you connect the WS2812 to the 3V3 pin, and not power it from 5V instead?
2. 25 LEDs at 60 mA each is a total of 1500mA. I doubt the ESP32 can deliver that on the 3V3 pin.
3. The Din pin should have a resistor

Ich weiß wie genießen der Weise, in der Sie noch framed diese besondere Problem zzgl. es funktioniert anwesend uns einige Futter für Gedanken . Allerdings Dennoch , von genau das, was persönlich gesehen , I im Grunde wish wenn der Bewertungen Pack Menschen heute bleiben auf point und nicht loslegen on a Seifenkiste einige andere Nachrichten des Tages. Immerhin Wie auch immer, ich danke Ihnen für dieses hervorragende Punkt und obwohl I können nicht gehen zusammen mit it die Idee in der Gesamtheit, I Bezug der Perspektive .

I precisely needed to appreciate you once more. I'm not certain what I would have undertaken in the absence of the actual ideas revealed by you regarding my subject matter. It was actually the frustrating dilemma in my position, nevertheless discovering the specialised manner you dealt with that forced me to weep for happiness. Now i am grateful for your assistance as well as expect you find out what a great job you have been putting in teaching people with the aid of your web site. I am certain you have never met all of us.

Thanks a lot for giving everyone such a marvellous possiblity to discover important secrets from this website. It is always so beneficial and jam-packed with a lot of fun for me and my office colleagues to search your website not less than 3 times in 7 days to study the newest guides you have got. And definitely, I am also certainly satisfied concerning the beautiful creative ideas served by you. Certain 3 tips in this post are rather the most beneficial I have ever had.

My wife and i have been now glad Chris managed to conclude his studies by way of the ideas he made from your web site. It's not at all simplistic to just continually be releasing techniques which usually people have been trying to sell. And we acknowledge we now have the website owner to be grateful to because of that. The most important illustrations you have made, the easy web site navigation, the relationships your site make it easier to promote - it's mostly superb, and it's letting our son in addition to the family feel that that subject is cool, which is certainly really vital. Thanks for everything!

Thanks a lot for providing individuals with an extraordinarily pleasant chance to read articles and blog posts from this website. It's always so fantastic and as well , stuffed with amusement for me and my office friends to search your web site at minimum 3 times a week to study the newest guidance you have got. And indeed, I am just always impressed for the stunning secrets you give. Selected two areas in this article are in reality the finest I have had.

I needed to draft you a bit of word to be able to say thank you once again for all the pretty opinions you have featured in this case. It's quite wonderfully open-handed of people like you to present unreservedly what exactly a few individuals could possibly have made available as an ebook in making some dough for themselves, notably given that you could have done it in case you decided. These solutions additionally worked like the fantastic way to comprehend someone else have a similar interest similar to my personal own to understand more in respect of this matter. I believe there are numerous more enjoyable occasions in the future for folks who look into your blog.

I wish to convey my respect for your kind-heartedness supporting those who absolutely need help with this particular question. Your personal dedication to getting the message all-around was quite beneficial and has usually encouraged individuals just like me to get to their targets. The warm and friendly guidelines implies a whole lot a person like me and additionally to my fellow workers. Warm regards; from all of us.

I simply wanted to say thanks again. I'm not certain the things I could possibly have followed without those smart ideas revealed by you regarding such a problem. Entirely was a real horrifying matter in my opinion, however , observing your well-written form you handled it made me to leap over contentment. I'm grateful for this information and as well , pray you find out what a great job your are getting into training many people through your website. Probably you have never met all of us.

I want to show appreciation to you for bailing me out of this condition. Just after researching through the the web and finding concepts that were not pleasant, I believed my entire life was well over. Living without the strategies to the issues you've resolved all through the review is a serious case, and the kind which could have adversely damaged my entire career if I hadn't noticed your web page. That natural talent and kindness in taking care of the whole thing was helpful. I'm not sure what I would have done if I had not come upon such a stuff like this. I am able to at this time relish my future. Thanks for your time so much for your specialized and amazing help. I won't be reluctant to recommend your web sites to any person who should get direction on this matter.

Thank you a lot for giving everyone remarkably remarkable possiblity to read critical reviews from this blog. It's always very terrific and jam-packed with a great time for me and my office fellow workers to search your blog at the least 3 times weekly to study the latest stuff you will have. Of course, I am just always amazed with your magnificent solutions you give. Certain 3 ideas in this article are in fact the best we have all ever had.

I would like to express some thanks to the writer just for rescuing me from such a situation. Because of scouting through the online world and obtaining things which were not powerful, I believed my entire life was done. Living minus the answers to the issues you have resolved by means of your main blog post is a crucial case, as well as the kind which may have badly damaged my entire career if I had not noticed your web page. Your personal ability and kindness in playing with almost everything was priceless. I am not sure what I would've done if I hadn't come across such a subject like this. I am able to at this time relish my future. Thank you so much for the impressive and sensible help. I won't hesitate to recommend your web sites to anyone who ought to have guidance on this issue.

My wife and i got so lucky Peter could finish up his survey from your precious recommendations he gained in your site. It's not at all simplistic to just always be giving for free tips and hints that people may have been making money from. We figure out we've got the writer to thank for this. The entire illustrations you have made, the simple site navigation, the friendships you can make it easier to instill - it is many incredible, and it's assisting our son and the family reason why that subject matter is excellent, and that's extraordinarily serious. Thanks for the whole thing!

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.