WS2812 LEDs on an ESP32: power budget, brightness limits and a stable data line
A WS2812 draws up to about 60 mA at full white. Size the supply, cap brightness, add the data resistor and capacitor, and deal with 3.3 V data into 5 V pixels.
- One WS2812 can draw about 60 mA at full white, so 60 of them need 3.6 A. Never run that through USB or the board's 5V pin.
- Capping brightness in code cuts the current roughly in proportion and lets you use a smaller supply.
- Add a 300–500 Ω resistor on the data line near the first pixel and a 500–1000 µF capacitor across the supply.
- At 5 V a WS2812 wants a HIGH of at least 3.5 V, but an ESP32 only guarantees 2.64 V. Use a level shifter to be sure.
A WS2812 (often sold as NeoPixel) is an RGB LED with its own controller chip, so one data wire drives a whole strip. The problem nearly everyone hits isn’t code but power: each pixel can draw about 60 mA at full white, so a 60-pixel strip needs a 5 V supply of several amps. This article sizes the supply, shows how to cap brightness, and covers the three small parts that keep a strip stable.
The examples use a 5 V WS2812B strip driven by an ESP32 DevKit with the Adafruit NeoPixel library in Arduino IDE 2.
Current per pixel: 60 mA is the worst case
Each pixel holds a red, a green and a blue LED at roughly 20 mA each when fully on. All three at full (white) makes about 60 mA per pixel. The Adafruit and SparkFun guides both use this figure.
Most projects don’t hold every pixel at full white all the time, so Adafruit offers a rough rule of thumb of 20 mA per pixel on average (a third of the maximum) for typical colourful use. But if your code can ever command full white on the whole strip (a bug, or a “torch” mode), the supply must cope, or you must cap brightness in code.
| Pixels | 20 mA/pixel average | 60 mA/pixel full white | Power at 5 V (full white) |
|---|---|---|---|
| 8 | 0.16 A | 0.48 A | 2.4 W |
| 30 | 0.6 A | 1.8 A | 9 W |
| 60 | 1.2 A | 3.6 A | 18 W |
| 144 | 2.88 A | 8.64 A | 43.2 W |
Always count the worst case first, then decide whether to buy a bigger supply or cap the brightness in code.
Worked example: a 60-pixel strip on the desk
Step 1, worst case: 60 × 60 mA = 3,600 mA = 3.6 A at 5 V = 18 W.
Step 2, cap brightness: most libraries have a global brightness setting from 0 to 255. Setting 64 gives 64 ÷ 255 ≈ 25%, and the current falls roughly in proportion: 3.6 × 0.25 ≈ 0.9 A.
Step 3, add the board: the ESP32 can draw up to about 240 mA while transmitting Wi-Fi. On the same supply: 0.9 + 0.24 ≈ 1.14 A.
Step 4, pick the supply: leave headroom so it isn’t running at its limit; a 5 V, 2 A or larger adapter.
Compare a computer’s USB 2.0 port at about 500 mA: minus 240 mA for the board leaves 260 mA ÷ 60 mA ≈ 4 pixels at full white. That is why a long strip on USB makes the board reset.
Setting the brightness in code:
#include <Adafruit_NeoPixel.h>
const int LED_PIN = 13; // data, through the resistor, to DIN of the first pixel
const int NUM_LEDS = 60;
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.setBrightness(64); // about 25%: full white drops from 3.6 A to about 0.9 A
strip.show(); // start with every pixel off
}
void loop() {
strip.fill(strip.Color(255, 255, 255)); // worst case: measure the real current
strip.show();
delay(1000);
}
Set setBrightness() once at start-up, then measure the real current with a multimeter while the strip shows full white. That measured number is the one to size the supply by.
Wiring the power correctly
- Don’t route strip power through the board. Feed 5 V from the supply straight into the strip, not via the USB port or the board’s power rail.
- Join the grounds of the supply, the strip and the ESP32, or the data signal has no common reference.
- No overvoltage. Adafruit warns that extra current is fine but extra voltage kills the LEDs. The WS2812B datasheet gives a 3.5–5.3 V supply range, so four alkaline cells at about 6 V are too much.
- Long strips sag. The last pixels dim or shift colour; the usual fix is a second supply feed further along.
- Wire it with the power off. If you must connect to a live circuit, Adafruit’s order is ground first, then +5 V, then data, and the reverse to disconnect.
Small parts that keep a strip stable
| Part | Suggested value | Where | Why |
|---|---|---|---|
| Capacitor | 500–1000 µF, rated 6.3 V or more (SparkFun gives 100–1000 µF) | Across + and − near the start of the strip | Smooths the surge when brightness changes suddenly |
| Data resistor | 300–500 Ω (SparkFun gives 220–470 Ω) | In series with data, at the first-pixel end | Both guides recommend it; some products have one built in, and adding another is harmless |
| Level shifter | A chip such as 74AHCT125 or 74HCT245 | Between the ESP32 pin and DIN | Raises 3.3 V data to 5 V |
An electrolytic capacitor is polarised: the negative lead (marked with a stripe) goes to GND. Reversed, it can be damaged.
3.3 V data into 5 V pixels
The WS2812B datasheet says DIN counts as HIGH at 0.7 × VDD or more:
- 5.0 V supply: 0.7 × 5.0 = 3.5 V
- ESP32 minimum output HIGH, from its datasheet: 0.8 × VDD = 0.8 × 3.3 = 2.64 V
2.64 V is below the 3.5 V required, so a direct connection is outside spec. Many strips work anyway because individual parts beat the spec, but nothing guarantees it. Adafruit’s fixes:
- A level shifter that turns the data into 5 V (the sure option).
- Lower the pixel supply, for example run the strip from a 3.7 V lithium cell. The HIGH threshold drops with it (0.7 × 3.7 ≈ 2.6 V), but so does brightness, and the battery needs the care described in using lithium batteries safely.
Common mistakes
- Powering the strip from USB. Fine until full white, then the board resets or the pixels glitch.
- No common ground between an external supply and the board.
- Putting the data resistor at the board end instead of next to the first pixel as recommended.
- Trusting the 20 mA rule when the code has a full-white mode.
- Plugging the strip into a live supply without connecting ground first.
- Thin wire for several amps. It runs warm and the voltage drops a lot.
Sources
FAQ
I wired the ESP32's 3.3 V data straight in and it works. Is that fine?
It often works, but it is outside the datasheet. It may glitch when warm, over a longer wire, or with a different batch of pixels. For anything you install for real, add a level shifter such as a 74AHCT125.
The far end of the strip looks yellow or orange instead of white.
Voltage drops along the strip, so the last pixels get a lower supply. Lower the brightness or run an extra supply feed to another point on the strip, with all grounds joined.
Can I power the strip from 4 AA batteries?
Four alkaline cells give about 6 V, too much for 5 V pixels. Adafruit suggests four NiMH cells instead, which give about 4.8 V.
Circuits and code were tested on sample boards. Boards differ in pin layout, so check your board's pinout before you power anything.