A WS2812B strip on the Nano ESP32 uses the same Adafruit NeoPixel code as a classic Nano. Data goes from D6 through 330 Ω; power comes from a separate 5 V adapter, with the grounds joined.
One Nano ESP32 setting matters here: switch Tools → Pin Numbering to “By GPIO number (legacy)”, or the NeoPixel library fails to link. The sketch runs a rainbow at about 25 % brightness and prints which GPIO D6 is.
Wiring
| Arduino Nano ESP32 | WS2812B addressable RGB LED strip (NeoPixel) | Wire | Notes |
|---|---|---|---|
| D6 | DIN | green | Via 330 Ω |
| 5 V 2 A adapter · +5V | 5V | red | 1000 µF capacitor across 5V/GND at the strip. |
| 5 V 2 A adapter · GND | GND | black | |
| GND | GND | black | Common ground with the Nano. |
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
- There is no 5V pin on the Nano ESP32, and VBUS is raw USB power. A strip needs its own 5 V supply; join only the grounds.
- Set Tools → Pin Numbering → “By GPIO number (legacy)” for this sketch. In the default “By Arduino pin” mode, Adafruit NeoPixel 1.15.5 fails to link with
undefined reference to digitalPinToGPIONumber: its ESP32 driver is a C file and can’t call the core’s C++ pin-remap function. - Keep writing
D6in code: in GPIO mode the D6 name still points at the D6 pad (it becomes GPIO9). Only bare numbers change meaning, so6would then be GPIO6 = the pad labelled D3. - The data signal is 3.3 V — fine for a short wire into a 5 V strip. For long runs add a 74AHCT125 buffer.
- Don’t confuse the strip with the board’s own RGB LED: that one is a plain common-anode LED on LED_RED/GREEN/BLUE, not a WS2812.
Code
// WS2812B strip on an Arduino Nano ESP32.
// DIN → D6 through 330 Ω. Strip 5V/GND → its own 5 V supply; supply GND → Nano GND.
// Needs Tools → Pin Numbering → "By GPIO number (legacy)" (set in this sketch's profile):
// Adafruit NeoPixel's ESP32 driver is plain C and can't link to the core's pin-remap function,
// so the default "By Arduino pin" mode fails with "undefined reference to digitalPinToGPIONumber".
// Keep writing D6: in GPIO mode the D6 name still means the D6 pad (GPIO9).
#include <Adafruit_NeoPixel.h>
constexpr uint16_t COUNT = 30;
Adafruit_NeoPixel strip(COUNT, D6, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
uint32_t t0 = millis();
while (!Serial && millis() - t0 < 3000) {}
strip.begin();
strip.setBrightness(60);
strip.show();
Serial.printf("WS2812B: %u LEDs on D6 (GPIO%u)\n", COUNT, D6);
}
void loop() {
static uint16_t hue = 0;
for (uint16_t i = 0; i < COUNT; i++) {
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(hue + i * 65536UL / COUNT)));
}
strip.show();
hue += 256;
delay(20);
}// WS2812B strip on an Arduino Nano ESP32.
// DIN → D6 through 330 Ω. Strip 5V/GND → its own 5 V supply; supply GND → Nano GND.
// Needs Tools → Pin Numbering → "By GPIO number (legacy)" (set in this sketch's profile):
// Adafruit NeoPixel's ESP32 driver is plain C and can't link to the core's pin-remap function,
// so the default "By Arduino pin" mode fails with "undefined reference to digitalPinToGPIONumber".
// Keep writing D6: in GPIO mode the D6 name still means the D6 pad (GPIO9).
#include <Adafruit_NeoPixel.h>
constexpr uint16_t COUNT = 30;
Adafruit_NeoPixel strip(COUNT, D6, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
uint32_t t0 = millis();
while (!Serial && millis() - t0 < 3000) {}
strip.begin();
strip.setBrightness(60);
strip.show();
Serial.printf("WS2812B: %u LEDs on D6 (GPIO%u)\n", COUNT, D6);
}
void loop() {
static uint16_t hue = 0;
for (uint16_t i = 0; i < COUNT; i++) {
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(hue + i * 65536UL / COUNT)));
}
strip.show();
hue += 256;
delay(20);
}Library: Adafruit NeoPixel (Adafruit) — compiled with Adafruit NeoPixel 1.15.5.
Expected serial output
WS2812B: 30 LEDs on D6 (GPIO9)WS2812B: 30 LEDs on D6 (GPIO9)
Common errors
“undefined reference to digitalPinToGPIONumber” when compiling
Pin Numbering is still “By Arduino pin”. Switch Tools → Pin Numbering to “By GPIO number (legacy)” and compile again.
Nothing lights
No common GND, or data into DOUT.
Board resets
Strip powered from VBUS. Brownout fix.