ESP32 with WS2812 Pixel Led Programming

Hey Guys , welcome back to Techatronic. today we brought this amazing project where you can interface ESP32 with WS2812 pixel-led. Pixel ws2812 is the most commonly used led’s which is programmable and addressable. You must see lighting effects in club bar restaurants marriages and many other places. the light animation and programming. You can make any color and run in any pattern of this ws2812 led with the ESP32 device.

So, I am sharing my few works here and then we will discuss how to program the Pixel led with ESP32.

Ws2812 programming with esp32
esp32 with ws2812

This is fun to control the light with your phone by simple programming. there are many methods to do the programming such as. you can program the pixel led with WL led where you have pre-defined many functions to control the led. Also. you can program directly your esp32 with ws2812 to learn the basic programming and effect. Arduino is also and option to control the pixel led.

if you want to learn how to use arduino with ws2811 there is a detail article on this too. There is some predefined libraries available on the internet which can help you to make the program. So, let get started the tutorial. first we will explain how to program the pixel led with esp32 with a simple program.

How to Program ESP32 with WS2812

The first step is to setup esp32 with Arduino ide to program in both methods. this is mandatory step to follow. In this above link we have share how to setup esp32 in IDE. After completing this first step we will go to the next step.

Now we have to install 1 library to access the esp32 with ws2812. the link is given here

Fastled

After importing the Fastled into the Arduino ide. we can start making the program. If you have trouble import library in Arduino you can follow this above link.

Method 1

Esp32 programming with ws2812

Now, there is a lot of examples program in the Fastled library you need to click on the file- example – Fastled and from there you can run any of the program and also you can modulate the program as per your requirement.

Also, we are going to share a very simple code which can modify easily and will be very helpful to understand the each part of code.

Circuit Diagram esp32 with ws2812

ws2812 connection with esp

The circuit diagram is very simple only you need to connect ground , vcc and data pin with 330 ohm resistor.

Here we are using the 330-ohm resistor to avoid the noise to transfer the signal given to the LED. This is 2812 Led in the diagram.If you are using ESP32 with ws2811 you need to attached a 12v external power supply.

WS2812 ESP32 Simple Code

#include <FastLED.h>
#define N 50


CRGB pin21[N];


void setup() {
  Serial.begin(115200);
 
   
   FastLED.addLeds<NEOPIXEL ,21>(pin21 , N);
 
   
 
   
}
void loop() {
  
 
    
    for(int i =0; i <= N; i++) {
   
    pin21[i] = CRGB(0,0,0) ;
   
   
    }
    FastLED.setBrightness(250);
    FastLED.show();
   delay(500);
    
     for(int i =0; i <= N; i++) {
   
    pin21[i] = CRGB(0,0,255) ;
   }
  FastLED.setBrightness(250);
    FastLED.show();
 delay(500);
}
   
}

Understanding of code

#include <FastLED.h>
#define N 50


CRGB pin21[N];

In the first line we are including the Fastled file which will be used in the program. there maybe many files of code running in the background.

in 2nd line we are defining how many led we want to program in this case we have to select the 50 led to program.

and 3rd line define that we are using pin number 21 to run the led with program.

Serial.begin(115200);
 
   
   FastLED.addLeds<NEOPIXEL ,21>(pin21 , N);

Serial begin is to start the serial communication between the esp32 and computer.

and the 2nd line define that the address of fast led will be delivered to the the pin 21 and on pin 21 we can use the number of pixel led to program which is 50 which we have define earlier.

for(int i =0; i <= N; i++) {
   
    pin21[i] = CRGB(0,0,0) ;
   
   
    }
    FastLED.setBrightness(250);
    FastLED.show();
   delay(500);

first we started a for loop from 1 to N , N is 50 here the number of LED’s. we are sending the data on pin 21 for each 50 LED’s. Then we are setting the brightness of the LED and the last statement is to glow the LED in esp32 with ws2812.

This was the first method the second method is using the WL Led.

Method 2

How to program WS2812 using WL LED

Download WLED application to your mobile phone. Connect your esp32 with your computer or laptop.

Then you need to open the wled.install.me website

Connect your device and click on install button given at website

After completeing the installation click on the next button

There will be a window prompt and ask for the wifi and password

submit the detail and click on connect.

Now, click on the rst button on esp32.

click on the ip address to begin the application

now, click on the configuration to setup the app

select the led preferences

select the data as per your requirement such as pin, rgb mode , etc.

If you have still any problem in programing or coding you can ask us in the comment section.

Leave a Comment