How to connect a WS2812B strip to ESP32

5 V 4 A supply, 74AHCT125 and 330 Ω on DIN.

Wiring diagram

Open in the builder

Connections

StepFromToColor
1ESP32 DOIT GND5 V 4 A supply −black
25 V 4 A supply −WS2812B GNDblack
35 V 4 A supply −74AHCT125 GNDblack
474AHCT125 1OE74AHCT125 GNDblack
574AHCT125 2OE74AHCT125 GNDblack
674AHCT125 2A74AHCT125 GNDblack
774AHCT125 4OE74AHCT125 GNDblack
8ESP32 DOIT VIN5 V 4 A supply +red
95 V 4 A supply +WS2812B +5Vred
105 V 4 A supply +74AHCT125 VCCred
11ESP32 DOIT D1874AHCT125 1Awhite
1274AHCT125 3A74AHCT125 3OEwhite
1374AHCT125 4A74AHCT125 4OEwhite
1474AHCT125 3OE74AHCT125 4OEwhite
155 V 4 A supply +Electrolytic 1 000 µF 10 V +red
165 V 4 A supply −Electrolytic 1 000 µF 10 V −black
1774AHCT125 1YResistor 330 Ω 1white
18Resistor 330 Ω 2WS2812B DINwhite

Power and wiring check

  • The schematic check, the same as in the builder, found no errors: pin voltages match, ground is common, buses are fully connected.
  • WS2812B draws up to 3600 mA (about 1200 typically) from the + pin of 5 V 4 A supply, the pin supplies about 4000 mA: 5 V 4 A supply (Mean Well GST25E05: 20 W).
  • 74AHCT125 draws up to 2 mA (about 1 typically) from the + pin of 5 V 4 A supply, the pin supplies about 4000 mA: 5 V 4 A supply (Mean Well GST25E05: 20 W).

Current of the whole circuit and how long it runs on a battery: power budget. Where to plug what: breadboard layout.

Example code

Arduino IDE, Adafruit NeoPixel 1.12.

#include <Adafruit_NeoPixel.h>

const int PIN = 18;    // GPIO18 through the 74AHCT125 and 330 Ω on DIN
const int COUNT = 60;  // LEDs on the strip

Adafruit_NeoPixel strip(COUNT, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  // 80 of 255: on white the strip draws about 1.1 A instead of 3.6 A
  strip.setBrightness(80);
  strip.show();
}

void loop() {
  static uint16_t hue = 0;
  strip.rainbow(hue);
  strip.show();
  hue += 256;
  delay(20);
}

Part pinouts

Next steps for this circuit

How it is connected

A 60-LED WS2812B strip is powered from a 5 V 4 A supply. At full-brightness white, one LED draws up to 60 mA (Adafruit's NeoPixel guide), and a meter of strip up to 3.6 A. The VIN pin of an ESP32 DevKit gives about 300 mA when powered from USB, so the strip's plus comes from the supply, and the board's VIN is powered from the same supply. The supply's minus is connected to the strip's GND and the ESP32's GND: without a common ground the strip doesn't receive data.

At 5 V power, a WS2812B strip takes a signal of 0.7 × 5 = 3.5 V and above as a one (Worldsemi datasheet), while an ESP32 GPIO outputs 3.3 V. For the strip to receive data reliably, a 74AHCT125 buffer powered from 5 V sits between GPIO18 and the strip. Its input counts 2 V as a one, and output 1Y gives 5 V and goes to DIN through a 330 Ω resistor at the start of the strip. Pin 1OE is tied to ground, which enables the output. The unused inputs 2A, 3A, 4A and pins 2OE, 3OE, 4OE are also grounded, as the TI datasheet requires.

A 1000 µF 10 V electrolytic capacitor sits between plus and minus at the start of the strip. Adafruit advises 500-1000 µF so that the inrush current when the supply is switched on doesn't damage the first LEDs. The capacitor's negative is marked with a stripe on the can.

Examples

  • In the sketch the brightness is 80 out of 255. At white the strip draws about 3.6 A × 80 / 255 = 1.1 A.

Common mistakes

  • People connect DIN to an ESP32 GPIO without a buffer. With some strips this works, but per the datasheet 3.3 V is below the 3.5 V threshold, and the first LEDs may get wrong data. The builder flags such a wire with a warning.
  • People power the strip from the board's 5V or VIN pin. The USB current flows through that pin, while 60 LEDs at white draw up to 3.6 A. The builder raises a current error.
  • People take a 74HC125 without the T. At 5 V supply it treats a signal from about 3.5 V as a one and doesn't reliably accept the ESP32's 3.3 V. The 74AHCT125, 74HCT125 and 74HCT245 work.
  • The data wire goes to DO at the end of a segment. Data passes along the strip only in the direction of the arrow, with the DIN input at the start.

FAQ

Can I do without the 74AHCT125?
With a short wire the strip often works from 3.3 V too, but the Worldsemi datasheet doesn't promise that level. Another way is to power the first LED through a 1N4007 diode. Then it has about 4.3 V supply and a one threshold of about 3 V, and its DO output gives about 4.3 V, which is enough for the following LEDs.
How many LEDs can a 5 V 4 A supply handle?
At full white brightness, 4 A / 60 mA = 66 LEDs. With a brightness of 80 out of 255, as in the example, the current is 3 times lower. For a long strip, the strip power supply calculator works out the supply and the wire gauge.
Can I flash an ESP32 over USB while the strip is connected to the supply?
Yes. On the DOIT board there is a diode between the USB connector and the VIN pin, and the supply's 5 V doesn't go into the computer.
Which GPIO should I use for the strip?
A GPIO with an output, except the strapping pins 0, 2, 5, 12 and 15 and the flash pins 6-11. GPIO34-39 are input only and don't work for a strip. In code you change the number in the PIN line.

You might also need