How to connect a WS2812B strip to ESP32
5 V 4 A supply, 74AHCT125 and 330 Ω on DIN.
Wiring diagram
Open in the builderStep-by-step assembly
18 steps- 18 wires in order: ground, power, signals, parts.Click a wire on the diagram or a table row to open its step.The ← → arrow keys flip through the steps.
- Step 1: minus of the power supply to GND of the board
- Step 2: GND of the strip to minus of the power supply
- Step 3: GND of the chip to minus of the power supply
- Step 4: 1OE to GND of the chip
- Step 5: 2OE to GND of the chip
- Step 6: 2A to GND of the chip
- Step 7: 4OE to GND of the chip
- Step 8: plus of the power supply to VIN of the boardPower 5 V.
- Step 9: +5V of the strip to plus of the power supply5 V. The strip draws up to 3600 mA, the pin supplies about 4000 mA.
- Step 10: VCC of the chip to plus of the power supply5 V. The chip draws up to 2 mA, the pin supplies about 4000 mA.
- Step 11: 1A of the chip to D18 of the board
- Step 12: 3A to 3OE of the chip
- Step 13: 4A to 4OE of the chip
- Step 14: 3OE to 4OE of the chip
- Step 15: plus of the capacitor to plus of the power supplyCapacitor 1 000 µF 10 V place it at the strip: plus to power, minus to GND, minus is marked with a stripe on the can.
- Step 16: minus of the capacitor to minus of the power supplyCapacitor 1 000 µF 10 V place it at the strip: plus to power, minus to GND, minus is marked with a stripe on the can.
- Step 17: pin 1 of the 330 Ω resistor to 1Y of the chipPlace the 330 Ω resistor close to DIN of the strip.
- Step 18: pin 2 of the 330 Ω resistor to DIN of the stripPlace the 330 Ω resistor close to DIN of the strip.
- Done: 18 wires in place.Check against the connection table below.
Connections
| Step | From | To | Color |
|---|---|---|---|
| 1 | ESP32 DOIT GND | 5 V 4 A supply − | black |
| 2 | 5 V 4 A supply − | WS2812B GND | black |
| 3 | 5 V 4 A supply − | 74AHCT125 GND | black |
| 4 | 74AHCT125 1OE | 74AHCT125 GND | black |
| 5 | 74AHCT125 2OE | 74AHCT125 GND | black |
| 6 | 74AHCT125 2A | 74AHCT125 GND | black |
| 7 | 74AHCT125 4OE | 74AHCT125 GND | black |
| 8 | ESP32 DOIT VIN | 5 V 4 A supply + | red |
| 9 | 5 V 4 A supply + | WS2812B +5V | red |
| 10 | 5 V 4 A supply + | 74AHCT125 VCC | red |
| 11 | ESP32 DOIT D18 | 74AHCT125 1A | white |
| 12 | 74AHCT125 3A | 74AHCT125 3OE | white |
| 13 | 74AHCT125 4A | 74AHCT125 4OE | white |
| 14 | 74AHCT125 3OE | 74AHCT125 4OE | white |
| 15 | 5 V 4 A supply + | Electrolytic 1 000 µF 10 V + | red |
| 16 | 5 V 4 A supply − | Electrolytic 1 000 µF 10 V − | black |
| 17 | 74AHCT125 1Y | Resistor 330 Ω 1 | white |
| 18 | Resistor 330 Ω 2 | WS2812B DIN | white |
Parts
- ESP32 DOIT DevKit V1, 30 pins× 1
- 5 V 4 A power supply (5.5×2.1 plug, adapter to screw terminals)× 1
- WS2812B strip, 5 V, 60 LED/m (one segment)× 1
- 74AHCT125 buffer (DIP-14), 3.3 to 5 V level shifter× 1
- Through-hole resistor 0.25 W (metal film, 1 %), 330 Ω× 1
- Electrolytic capacitor (polarized, negative marked by a stripe), 1 000 µF 10 V× 1
- Wires18
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.