How Easily Can ESP32 Control WS2812B Pixel LED Strips

SuntechLite is a top manufacturer and supplier that focuses on pixel LED strips and LED neon lights.

The ESP32 microcontroller can easily drive the WS2812B pixel LED strip, which achieves pixel-by-pixel control through single-wire data communication. The hardware only needs to connect the data pins and power supply. The ESP32 module can also accurately generate timing signals to effectively avoid LED flickering problems and support driving hundreds of cascaded LEDs at the same time.

But how easily can ESP32 control WS2812B pixel LED strips?

If you want to learn more about related usage methods, please follow our article.

1.Materials Required

Output

  • Voltage: DC 5V
  • Current: Up to 80A
  • Power Rating: 200W

Input

  • Voltage Range: AC 110V/220V (dual input supported, switch-selectable)
power supply 5V
       DC5V Power supply

Purpose of DC5V power supply

  • Powers both the WS2812 pixel LED strip and the ESP32  (via 5V/GND lines)
  • High safety, the low voltage reduce the risk of electric shock.
  • Small size makes it easy to integrate into mobile devices or embedded systems

ESP32 Board

ESP32
 ESP32 Control Board Area Pin Introduction

Model: ESP32
Operating Voltage: DC5V
Input Voltage (recommended): DC5V,
(If you choose to use a DC adapter for power supply, it can be DC6.5V~DC9V)
Digital I/O Pins: GPIO0~33 can be used for PWM output, GPIO34~39 can only be used for input, not output.GPIO2, 12, 15: Keep high level when starting, otherwise it may fail to start. GPIO0: Pull low in download mode and pull high in normal operation.
Analog Input Pins: 9
Clock Speed: 30 MHz
Programming Interface: USB Type-C

Precautions for use

  • The Esp32 controller sends digital data signals to the RGB LED strip
  • Connect the positive pole of the LED strip to the positive pole of the DC5V power supply,Control board current <500mA
  • The negative poles R-/G-/B- of the LED strip are connected to the digital I/O pins respectively (PWM pins are recommended)

WS2812B RGB LED strip

ws2812 led strip

Type: Addressable WS2812B LED strip
Input Voltage: 5V DC
Features: The entire LED strip can be controlled through single-wire serial communication (single signal line), and only one GPIO pin is needed to drive multiple lamp beads
LED Density: 60 leds/m

Accessories and Tools

  • external power supply:It is recommended to use when the load current is too large.
  • 220 ohm – 1K ohm resistor: The GPIO of ESP32 is 3.3V logic level. It is recommended to add a resistor between GPIO and the light strip.

2.ESP32 and WS2812B Wiring Schematic

The wiring diagram of SunTechLite is shown below:

ESP32 WS2812B Schematic diagram
How to Control WS2812B LED Strip with ESP32 Wiring Diagram

Note:

1. The current of the control board is <500mA;

2. The current of the light strip is too large, please use an external power supply to power the light strip;

3. The DC3.3/5V interface is the voltage output port of the ESP32 control board, which cannot be connected to the power supply. The DC interface is used for connecting the power supply;

4. The power supply range of the control board is DC3.3-9V, so the control board is powered by DC5V alone;

5. The wiring of RGB les strip is the same as that of RGBW led strip, but the programs cannot be shared;

6. The more points, the lower the refresh rate;

7. Note that the GPIO of ESP32 is 3.3V logic level, so the GPIO pin needs to be converted to a level before connecting to the light strip signal pin (74HCT125 or MOSFET level conversion).

3.ESP32 and WS2812B Connection Diagram

ESP32 WS2812B connect picuture
How to Control WS2812B LED Strip with ESP32 Suntechlite

The WS2812B LED strip has a built-in chip, and each LED bead can be independently programmed to achieve precise control of “one led, one pixel”. Its single lamp bead has a power of 0.3W and an operating voltage of 5V, which is energy-saving and environmentally friendly. The LED strip is made of a flexible FPC substrate, which can be cut, bent or spliced, and has 3M glue or buckles on the back to meet the needs of curved surface installation. Due to its unique technical characteristics and flexible application scenarios, the WS2812B RGB fantasy LED strip has become the best choice for decorative lighting, commercial displays and creative projects.

Many people also confuse WS2812 RGB led strip with WS2812B led strip. If you are also troubled by this, don’t worry. We have a dedicated WS2812 vs WS2812B blog to explain it to you.

4. Code Upload

Software: Arduino IDE

Library Used: FastLED

Suntechlite :Provides codes for a variety of light changing effects. If you have any questions, please feel free to contact our professional team of engineers.

				
					#include 

#define LED_PIN     19     // Light strip data pin
#define NUM_LEDS    80    // LED quantity
#define BRIGHTNESS  128   // Initial brightness (0-255)
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB   // Most WS2812 are GRB sequential

CRGB leds[NUM_LEDS];

// Effect mode example
enum Effects {
  EFFECT_FLOW,
  EFFECT_BLINK,
  EFFECT_MARQUEE,
  EFFECT_COUNT
};

uint8_t currentEffect = EFFECT_FLOW;
unsigned long lastEffectChange = 0;
unsigned long lastUpdate = 0;

void setup() {
  delay(3000); // safety delay
  FastLED.addLeds(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
  Serial.begin(115200);
}

// Full color water effect
void flowEffect() {
  static uint8_t hue = 0;
  static uint8_t pos = 0;
  
  // Gradually turn off all LEDs
  fadeToBlackBy(leds, NUM_LEDS, 10);
  
  // Set a colored light spot at the current position
  leds[pos] = CHSV(hue, 255, 255);
  
  // move location
  pos = (pos + 1) % NUM_LEDS;
  
  // change hue
  hue += 3;
  
  FastLED.show();
  delay(30);
}

// Full color flashing effect
void blinkEffect() {
  static bool lightsOn = false;
  static uint8_t hue = 0;
  
  if(lightsOn) {
    // Random color of full light strip
    fill_solid(leds, NUM_LEDS, CHSV(hue, 255, 255));
    hue += 5;
  } else {
    // All off
    fill_solid(leds, NUM_LEDS, CRGB::Black);
  }
  
  lightsOn = !lightsOn;
  FastLED.show();
  delay(lightsOn ? 200 : 800); // 亮200ms,灭800ms
}

// Marquee effect
void marqueeEffect() {
  static uint8_t hue = 0;
  static int position = 0;
  static int tailLength = 15;
  
  // Gradual fading
  fadeToBlackBy(leds, NUM_LEDS, 20);
  
  // Create a Marquee
  leds[position] = CHSV(hue, 255, 255);
  
  // Creating a gradient tail
  for(int i = 1; i  30000) {
    currentEffect = (currentEffect + 1) % EFFECT_COUNT;
    lastEffectChange = millis();
    FastLED.clear();
    FastLED.show();
  }
  
  //Execute current effect
  switch(currentEffect) {
    case EFFECT_FLOW:    flowEffect();    break;
    case EFFECT_BLINK:   blinkEffect();   break;
    case EFFECT_MARQUEE: marqueeEffect(); break;
  }
  
  // Brightness control (optional)
  // adjustBrightness();
}

// Optional: Switch effects via serial port commands
void serialEvent() {
  while(Serial.available()) {
    char c = Serial.read();
    if(c &gt;= '0' &amp;&amp; c &lt;= &#039;2&#039;) {
      currentEffect = c - &#039;0&#039;;
      FastLED.clear();
      FastLED.show();
    }
  }
}

// Optional: Brightness adjustment function
void adjustBrightness() {
  int potValue = analogRead(A0); // Connect the potentiometer to A0
  int newBrightness = map(potValue, 0, 1023, 0, 255);
  FastLED.setBrightness(newBrightness);
}
				
			

5.Demonstration Video

Here is a video showing how to control the light changes effect of a WS2812 LED strip with ESP32

The ESP32 controller has many advantages when controlling WS2812B LED strips. It can preset special effects, such as rainbow gradient and flame simulation, and can automatically adjust the CPU frequency according to the LED brightness to balance performance and energy consumption. It is particularly suitable for application scenarios that require high performance, flexibility and complex functions.

Of course, in addition to WS2812B, there is also WS2815 RGB addressable led stirp with the same protocol for decorative lighting. If you want to know more, please check the link.

Share To

Enquiry