WS2812B strips turn a NodeMCU into a Wi-Fi lamp, a Diwali light controller or a status bar. One data pin drives the whole strip, so the choices that matter are which pin and where the 5 V comes from.
Pick D5: it stays quiet during boot. D4 and TX look tempting but both chatter at reset, which shows up as a flash of random colours every time the board restarts.
Wiring
| NodeMCU ESP8266 | WS2812B addressable RGB LED strip (NeoPixel) | Wire | Notes |
|---|---|---|---|
| D5 | DIN | green | Via 330 Ω — D5 is GPIO14. Put the resistor close to the first LED. |
| VIN | 5V | red | About 8 LEDs at low brightness from USB. Longer strips: their own 5 V supply with a 1000 µF capacitor, GND joined to the NodeMCU. |
| GND | GND | black |
5 V (about 60 mA per LED at full white) part, 3.3 V board. The strip expects a data HIGH of about 3.5 V at 5 V supply. From ESP32 or Pico the 3.3 V signal often works with short wires, but to be safe drive DIN through a 74AHCT125 (or 74HCT125) powered from 5 V.
Board quirks
- Don’t use D4 or TX for the strip. D4 (GPIO2) is the ESP8266’s debug serial (TXD1) and TX carries the boot log, so both send data at reset — the strip lights random colours every time the board starts.
- At 5 V the WS2812B wants about 3.5 V for a HIGH. The NodeMCU’s 3.3 V usually works on a short wire; if the first LED flickers, drop the strip supply to about 4.5 V or add a 74AHCT125 buffer powered from 5 V.
- Adafruit NeoPixel bit-bangs the data on the ESP8266 with interrupts off (about 30 µs per LED). For a few dozen LEDs Wi-Fi doesn’t notice; for hundreds, use the NeoPixelBus library’s DMA mode on the RX pin instead.
- Brightness is capped at 40/255 in the sketch. Full white is about 60 mA per LED, and VIN can only pass what the USB port gives — roughly 500 mA minus what the NodeMCU itself uses.
Code
// WS2812B strip (8 LEDs) on a NodeMCU (ESP8266).
// DIN → 330 Ω → D5 (GPIO14), 5V → VIN (short strips only), GND → GND.
#include <Adafruit_NeoPixel.h>
const uint8_t LED_PIN = D5; // GPIO14 — not D4/TX, which send boot messages and flash the LEDs at reset
const uint16_t NUM_LEDS = 8;
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
Serial.println();
strip.begin();
strip.setBrightness(40); // 8 LEDs at 40/255 stay well inside what USB can give through VIN
strip.show(); // all off
Serial.println("WS2812B rainbow on D5 (GPIO14)");
}
void loop() {
static uint16_t hue = 0;
for (uint16_t i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(hue + i * 65536UL / NUM_LEDS)));
}
strip.show(); // interrupts are off for ~30 µs per LED while the data goes out
hue += 256;
delay(20);
}// WS2812B strip (8 LEDs) on a NodeMCU (ESP8266).
// DIN → 330 Ω → D5 (GPIO14), 5V → VIN (short strips only), GND → GND.
#include <Adafruit_NeoPixel.h>
const uint8_t LED_PIN = D5; // GPIO14 — not D4/TX, which send boot messages and flash the LEDs at reset
const uint16_t NUM_LEDS = 8;
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
Serial.println();
strip.begin();
strip.setBrightness(40); // 8 LEDs at 40/255 stay well inside what USB can give through VIN
strip.show(); // all off
Serial.println("WS2812B rainbow on D5 (GPIO14)");
}
void loop() {
static uint16_t hue = 0;
for (uint16_t i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(hue + i * 65536UL / NUM_LEDS)));
}
strip.show(); // interrupts are off for ~30 µs per LED while the data goes out
hue += 256;
delay(20);
}Library: Adafruit NeoPixel (Adafruit) — compiled with Adafruit NeoPixel 1.15.5.
Expected serial output
WS2812B rainbow on D5 (GPIO14)WS2812B rainbow on D5 (GPIO14)
Common errors
LEDs flash random colours at power-up
DIN is on D4 or TX, which carry boot messages. Move it to D5.
First LED wrong, the rest fine
Marginal 3.3 V data. Shorten the data wire, keep the 330 Ω resistor, or add a 74AHCT125.
Board resets when the strip goes bright
The strip is pulling too much through VIN. Lower the brightness or give the strip its own 5 V supply.