Skip to content

LED / Strip · ESP32 guide

Interfacing WS2812B Addressable RGB LED Strip with ESP32

Individually addressable RGB LEDs on one data wire: wire it right, power it properly and every pixel is yours to control.

Updated November 16, 2026 Arduino C++FastLEDAlso forArduino Uno

What is the WS2812B Strip?

A normal RGB LED strip has three wires for colour, and every LED on it shows the same colour at the same time. A WS2812B strip is different: each tiny 5050 LED has its own controller chip built inside, so every pixel can show its own colour and brightness. You feed one data wire into the first pixel, and the pixels pass the information along the strip like a bucket brigade. The first pixel keeps its 24 bits of colour, passes the rest on, the second takes the next 24 bits, and so on to the end. This is what makes rainbow waves, chases, fire effects, scrolling text on matrices and music visualisers possible with a single pin on your Arduino or ESP32.

The same chip is sold under the name NeoPixel (Adafruit's brand) and is the engine behind most LED rings, matrices, sticks and strips. For you it means one thing: the code and wiring are the same whether you have a 30-LED strip or a 300-LED reel.

The WS2812B is easy to drive but unforgiving about three things: power, ground and the data signal level. Get those right and it just works. Get them wrong and you will meet flickering, wrong colours, a dead first pixel or a microcontroller that keeps resetting. This page walks through all of it: how the protocol works, how to size the power supply, power injection on long strips, the 3.3 V data problem on an ESP32, which library to choose, and a troubleshooting table. For wiring and code, see the Arduino Uno guide and the ESP32 guide.

Specifications

LED type
WS2812B: 5050 RGB LED with the driver chip built into every pixel
Supply voltage
5 V DC (about 3.5 to 5.3 V tolerated; 5 V is standard)
Current per pixel
Up to about 60 mA at full white (20 mA per colour); roughly 1 mA idle
Colour depth
24-bit: 8 bits each for red, green and blue
Data order
GRB (green first), not RGB
Data protocol
Single-wire, about 800 kHz; each pixel keeps 24 bits and forwards the rest
Bit timing
1.25 µs per bit: a 0 is a ~0.4 µs high pulse, a 1 is a ~0.8 µs high pulse
Latch / reset
Data held low for at least 280 µs (50 µs on older batches)
Update time
About 30 µs per pixel: 30 LEDs ≈ 1 ms, 144 LEDs ≈ 4.3 ms
Logic high threshold
About 0.7 × VDD, roughly 3.5 V at 5 V (marginal for 3.3 V logic)
Strip densities
30, 60 or 144 LEDs per metre; IP30 (bare), IP65 (coated) or IP67 (tube)
RAM per pixel
3 bytes on the microcontroller (100 LEDs use 300 of the Uno's 2,048 bytes)

From the WS2812B datasheet and the FastLED / Adafruit NeoPixel documentation. Strips vary by manufacturer: test yours and fuse the supply.

Pinout

PadNameDescription
15VPower. Feed from a dedicated 5 V supply sized for the whole strip
2GNDGround, shared with the microcontroller and the supply
3DINData in, through a 330 to 470 Ω resistor. The arrow points away from this end
4DOUTData out at the far end: feeds DIN of the next segment

Wiring & code

Setting up WS2812B Strip with ESP32

Library

FastLED by FastLED community

Library Manager: install "FastLED" (keep it updated for current ESP32 cores). Or flash WLED from install.wled.me for a no-code option

The ESP32 is the natural partner for a WS2812B strip: a hardware peripheral (RMT) generates the timing, so Wi-Fi keeps running during animations, and there is RAM for hundreds of pixels. This guide wires the strip with a 74AHCT125 level shifter, runs a rainbow, then builds a Wi-Fi colour picker you can open on your phone. The last section covers WLED, the ready-made firmware that turns the same hardware into a full smart light with no code. Background on power and injection is on the WS2812B overview.

What you need

  • 1ESP32 DevKit

    Notes
    ESP32-S3 and C3 work too with a different pin
  • 1WS2812B strip (60 LEDs in the examples)

    Notes
    Change NUM_LEDS for yours
  • 15 V power supply sized for the strip

    Notes
    60 LEDs: 4 A for full white, or limit the power in code
  • 174AHCT125 (or 74HCT245) level shifter

    Notes
    Must be AHCT or HCT, powered from 5 V
  • 1 each330 Ω resistor and 1000 µF / 6.3 V capacitor

    Notes
    Data-line resistor and supply smoothing

Wiring

Strip pinESP32 pinNote
5VExternal 5V supply (+)Do not power a strip of any real length from the ESP32's pins. Add a 1000 µF capacitor across 5V and GND at the strip.
GNDGNDJoin the ESP32's GND, the external supply's GND and the strip's GND.
DINGPIO18 via 74AHCT125Use a 74AHCT125 or 74HCT245 level shifter to raise the 3.3 V signal to 5 V, then a 330 Ω resistor to DIN. Avoid input-only pins GPIO34–39.

74AHCT125 connections (one of its four gates)

74AHCT125 pinConnect toNotes
14 (VCC)5 V supplyPowered at 5 V so its output is a full 5 V signal
7 (GND)GNDCommon ground
1 (1OE)GNDOutput enable is active LOW: tie low to enable gate 1
2 (1A)ESP32 GPIO183.3 V input, read as a valid HIGH by an AHCT part
3 (1Y)330 Ω → strip DINClean 5 V data
4, 10, 13 (other OE)5 VDisables the three unused gates

The ESP32's 3.3 V data signal is borderline for a strip powered at 5 V, whose input threshold is about 3.5 V. A 74AHCT125 or 74HCT245 buffer between the GPIO and the 330 Ω series resistor makes the signal clean and is the most reliable fix for flicker and wrong colours. It must be an AHCT or HCT part, not a plain HC.

GPIO18 is a free general-purpose pin on the common ESP32 DevKit boards. The older GPIO5 also works but is a strapping pin, so GPIO18 is a safer choice. Avoid GPIO34–39 because they are input-only.

The ESP32 drives the strip with a hardware peripheral, so Wi-Fi, MQTT and a web server can keep running during animations. That makes it a natural fit for remote or app-controlled lighting. Use the latest FastLED version for current ESP32 core support, and keep your power limit below your supply's rating.

Sketch 1 - Rainbow with a power limit

sketch.ino
#include <FastLED.h>

#define DATA_PIN   18        // GPIO18 -> level shifter -> 330 ohm -> DIN
#define NUM_LEDS   60
#define BRIGHTNESS 80

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 2000);   // set to a little below your supply's rating
  FastLED.clear(true);
}

void loop() {
  static uint8_t hue = 0;
  fill_rainbow(leds, NUM_LEDS, hue++, 4);
  FastLED.show();
  FastLED.delay(15);
}

Set setMaxPowerInVoltsAndMilliamps() a little below your supply's rating: FastLED then scales brightness down automatically whenever an effect would draw more. Line-by-line notes on these FastLED calls are in the Uno guide.

Sketch 2 - Wi-Fi colour picker on your phone

This sketch serves a page with a colour picker, a brightness slider and Rainbow and Off buttons. Each change sends a tiny request (/set?c=ff8800) and the strip updates at once. The animation runs from a timer in loop(), so the web server and the LEDs never wait for each other.

sketch.ino
#include <WiFi.h>
#include <WebServer.h>
#include <FastLED.h>

const char* WIFI_SSID     = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";

#define DATA_PIN 18          // through the 74AHCT125 and 330 ohm to DIN
#define NUM_LEDS 60

CRGB leds[NUM_LEDS];
WebServer server(80);

CRGB colour = CRGB::White;
uint8_t brightness = 60;
bool rainbow = false;

const char PAGE[] = R"HTML(<!DOCTYPE html><html><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>LED strip</title>
<style>
body{font-family:sans-serif;margin:1.5em;background:#0b1622;color:#e8f1fb}
input{width:100%;height:56px;margin:10px 0}
button{padding:12px 18px;font-size:1em;margin:8px 8px 0 0}
</style></head><body>
<h1>WS2812B strip</h1>
<label>Colour</label><input type="color" id="c" value="#ffffff">
<label>Brightness</label><input type="range" id="b" min="0" max="255" value="60">
<button onclick="send('rainbow=1')">Rainbow</button>
<button onclick="send('off=1')">Off</button>
<script>
const send = (q) => fetch('/set?' + q);
document.getElementById('c').oninput = (e) => send('c=' + e.target.value.slice(1));
document.getElementById('b').onchange = (e) => send('b=' + e.target.value);
</script></body></html>)HTML";

void handleSet() {
  if (server.hasArg("c")) {                         // hex colour, e.g. ff8800
    uint32_t rgb = strtoul(server.arg("c").c_str(), nullptr, 16);
    colour = CRGB(rgb >> 16, (rgb >> 8) & 0xFF, rgb & 0xFF);
    rainbow = false;
  }
  if (server.hasArg("b"))       brightness = constrain(server.arg("b").toInt(), 0, 255);
  if (server.hasArg("rainbow")) rainbow = true;
  if (server.hasArg("off"))     { colour = CRGB::Black; rainbow = false; }
  server.send(204);
}

void setup() {
  Serial.begin(115200);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setCorrection(TypicalLEDStrip);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 2000);  // below your supply's rating

  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.print("Open http://");
  Serial.println(WiFi.localIP());

  server.on("/", []() { server.send(200, "text/html", PAGE); });
  server.on("/set", handleSet);
  server.begin();
}

void loop() {
  server.handleClient();
  EVERY_N_MILLISECONDS(20) {
    static uint8_t hue = 0;
    if (rainbow) fill_rainbow(leds, NUM_LEDS, hue++, 4);
    else         fill_solid(leds, NUM_LEDS, colour);
    FastLED.setBrightness(brightness);
    FastLED.show();
  }
}

How it works. The page sends the colour as six hex digits; strtoul(..., 16) turns "ff8800" into one number, and the shifts split it into red, green and blue. server.send(204) answers "done, nothing to show", so the page never reloads. Settings reset on reboot; store them with the Preferences library if you want the lamp to remember its last colour. For Home Assistant or Node-RED, the same /set URL is easy to call from an automation.

Tip

The ESP32 only joins 2.4 GHz Wi-Fi. If the strip flickers only while the page is busy, update FastLED: current versions drive the strip through the ESP32's RMT peripheral, which Wi-Fi interrupts cannot disturb.

No code at all: WLED

If what you want is a smart light rather than a programming project, install WLED, a free open-source firmware for the ESP32 and ESP8266 made for exactly this wiring.

  1. 1Open install.wled.me in Chrome or Edge on a computer, plug in the ESP32 and click Install (the browser flashes it over USB).
  2. 2Join the WLED-AP Wi-Fi network from your phone (password wled1234) and enter your home Wi-Fi details.
  3. 3In Config > LED Preferences, set the data GPIO (18 in this wiring), the LED count and a current limit below your supply's rating.
  4. 4Control it from the WLED app or the web page: over 100 effects, palettes, schedules and presets, with Home Assistant discovery built in.

Your own code or WLED?

  • Time to a working light

    Your own sketch
    An evening
    WLED
    Ten minutes
  • Effects

    Your own sketch
    Whatever you write
    WLED
    100+ built in, plus palettes and presets
  • Phone app / Home Assistant

    Your own sketch
    Build it yourself
    WLED
    Included
  • Custom logic (sensors, games, data displays)

    Your own sketch
    Anything you like
    WLED
    Limited to what WLED supports
  • Learning value

    Your own sketch
    High
    WLED
    Low

Troubleshooting on the ESP32

  • Random colours or flicker

    Likely cause
    3.3 V data too low for the strip
    Fix
    Add the 74AHCT125 powered from 5 V; a plain 74HC part will not work
  • Nothing lights through the level shifter

    Likely cause
    OE pin not tied LOW, or VCC on 3.3 V
    Fix
    Pin 1 to GND, pin 14 to 5 V
  • ESP32 resets when the strip turns white

    Likely cause
    The strip and ESP32 share a weak supply
    Fix
    Separate supply for the strip (grounds joined), a lower power limit, 1000 µF at the strip
  • Compile errors with FastLED

    Likely cause
    Old FastLED with a new ESP32 core
    Fix
    Update FastLED from the Library Manager
  • Web page loads but the strip ignores it

    Likely cause
    Colour sent without the hex value
    Fix
    Check the URL in the Serial Monitor; /set?c=ff0000 should turn the strip red

ESP32 FAQ

Can I skip the level shifter? Often yes, with a short data wire and a clean 5 V supply, and many tutorials do. But 3.3 V is just under the strip's 3.5 V threshold, so it is marginal: if you see flicker or wrong colours, the 74AHCT125 is the fix. Powering the first pixel from slightly less than 5 V is a known hack, but the buffer is more reliable.

Which GPIO should I use? GPIO18 is a safe default on DevKits. Avoid the input-only GPIO34 to 39 and the flash pins 6 to 11; strapping pins such as GPIO5 work but are better avoided.

Can one ESP32 drive several strips? Yes. FastLED can run several strips on different pins, each with its own addLeds line, and the RMT peripheral has several channels.

Where next? Compare with the WS2812B Uno guide, or build a pixel display with the WS2812B matrix.

Keep learning

Related guides & projects