Outputs and switching

WS2812B LED strip with ESP32

A WS2812B strip has a small controller in every LED, so one data wire sets each colour separately at 800 kHz. It is simple to wire, and most trouble comes from two things: power and the data voltage.

Plan the power first. Each LED can draw up to 60 mA at full white, so 60 LEDs can pull about 3.6 A. Never run that through the display board. Use a separate 5 V supply, connect its ground to the ESP32 ground, and feed long strips from more than one point.

The second issue is the signal. At 5 V the datasheet wants about 3.5 V on the data pin (0.7 × VDD), and an ESP32 only gives 3.3 V. Short strips often work anyway, but flicker is common, so add a level shifter for anything permanent. Keep the data wire short and put a resistor of a few hundred ohms in series if you see glitches. The code below uses the ESP32's RMT peripheral directly, without a library. LCD Ultra Pro has a built-in LED strip component with screens, so you can control it without writing code.

WS2812B LED strip wiring diagram for ESP32
Wiring diagram drawn by LCD Ultra Pro.

Specifications

Supply5 V
CurrentUp to 60 mA per LED at full white
Data rate800 kHz, one wire
Input high0.7 × VDD, about 3.5 V at 5 V
Colour orderGRB

Power and logic levels

5 V signal: needs a divider or level shifter

Supply5 V
Signal levelData needs about 3.5 V, ESP32 gives 3.3 V
On an ESP32Not dangerous to the ESP32, but may glitch. Use a level shifter on long strips.
WS2812B LED strip level shifting schematic for a 3.3 V ESP32
One channel raises the data line to 5 V. Keep the wire from the chip to the first LED short.

ESP32 pins, including those on a display board's connectors, work at 3.3 V and are not 5 V tolerant. Modules differ, so if in doubt, measure the signal before you connect it.

Wiring

WS2812B LED stripConnect toNote
5VExternal 5 V supplyNot from the display board
GNDGND + supply GNDCommon ground is required
DINGPIO 5Level shifter for long or permanent strips

Arduino code

const int LED_PIN = 5, LED_COUNT = 8;
rmt_data_t bits[LED_COUNT * 24];

void setColor(int i, uint8_t r, uint8_t g, uint8_t b) {
  uint32_t grb = (g << 16) | (r << 8) | b;
  for (int n = 0; n < 24; n++) {
    bool one = grb & (1UL << (23 - n));
    rmt_data_t &d = bits[i * 24 + n];
    d.level0 = 1; d.duration0 = one ? 8 : 4;   // 100 ns ticks
    d.level1 = 0; d.duration1 = one ? 4 : 8;
  }
}

void setup() {
  rmtInit(LED_PIN, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000);
}

void loop() {
  static int pos = 0;
  for (int i = 0; i < LED_COUNT; i++) setColor(i, i == pos ? 40 : 0, 0, i == pos ? 0 : 5);
  rmtWrite(LED_PIN, bits, LED_COUNT * 24, RMT_WAIT_FOR_EVER);
  pos = (pos + 1) % LED_COUNT;
  delay(120);
}

No extra library needed. Compiled for ESP32-S3 with arduino-esp32 3.x. Not yet tested by us on a physical sensor. Change the pins to match your board.

On a display

LCD Ultra Pro has a built-in LED strip component with a ready control screen, so you can set colours and effects without writing code.

Design a display for WS2812B LED strip

Boards with a ready connector

Only boards whose connectors we have surveyed. Others may still work on free GPIOs.

Elecrow CrowPanel ESP32 HMI 2.4"GPIO_D port: GPIO 25
Elecrow CrowPanel ESP32 HMI 2.8"GPIO_D port: GPIO 25
Elecrow CrowPanel ESP32 HMI 3.5"GPIO_D port: GPIO 25
Elecrow CrowPanel ESP32-S3 HMI 4.3"GPIO_D port: GPIO 37
Elecrow CrowPanel ESP32-S3 HMI 5.0"GPIO_D port: GPIO 38
Elecrow CrowPanel ESP32-S3 HMI 7.0"GPIO_D port: GPIO 38
LilyGO T-Display (classic) 1.14"Left pin header: GPIO 21
LilyGO T-Display-S3-Pro 2.33"QWIIC LEFT: GPIO 43
LilyGO T-Deck 2.8"Grove connector: GPIO 43On the T-Deck Plus this port is taken by the built-in GPS
M5Stack AtomS3 0.85"Grove port: GPIO 2
M5Stack M5StickC Plus2 1.14"Grove port: GPIO 32
Sunton ESP32-2432S028R 2.8"GPIO header (P3): GPIO 22GPIO 21 is the display backlight — not usable. GPIO 35 is input-only. No 3V3 pin on P3 (only GND).
Sunton ESP32-4827S043R/C 4.3"GPIO header (P4): GPIO 17P3 carries the same two pins
Sunton ESP32-8048S043C 4.3"GPIO header (P4): GPIO 17P3 carries the same two pins
Sunton ESP32-8048S050C 5.0"GPIO header (P4): GPIO 17P5 carries the same pins. Shared with the I2S amplifier of the speaker output (P6).
Sunton ESP32-8048S070C 7.0"GPIO header (P4): GPIO 17P5 carries the same pins. Shared with the I2S amplifier of the speaker output (P6).
Waveshare ESP32-S3 Touch LCD 1.28" roundSH1.0 GPIO header: GPIO 15Six GPIOs led out per the wiki pin table
Waveshare ESP32-S3 Touch LCD 1.28" round (CNC metal housing)SH1.0 GPIO header: GPIO 15Six GPIOs led out per the wiki pin table
Waveshare ESP32-S3-LCD-7BGPIO connector (J8): GPIO 6

Good to know

  • Do not power strips from the display board.
  • Connect the grounds of the supply and the ESP32.
  • 3.3 V data can flicker. Use a level shifter for permanent builds.
  • Keep brightness low in tests. Full white draws the most.

What it is good for

  • Status lights
  • Ambient lighting
  • Bar graphs next to a display

FAQ

How much power does a WS2812B strip need?

Up to 60 mA per LED at full white, so 60 LEDs can draw about 3.6 A.

Do I need a level shifter with an ESP32?

Short strips often work without one, but the datasheet wants about 3.5 V. Use one for permanent builds.

Does LCD Ultra Pro support WS2812B?

Yes, there is a built-in LED strip component with its own driver.

Sources

Related parts

Use this information at your own risk. It is for general guidance only: the example code compiles, but it has not been tested on every part, and modules differ between sellers. Check the manufacturer's data before you build. Product names belong to their owners, and LCD Ultra Pro is not affiliated with them. See our Terms.