ESP32-C3 · NeoPixel

ESP32-C3 NeoPixel Simulator: Wiring, Code and a Live Circuit

This is a strip of eight WS2812B NeoPixels wired to an ESP32-C3 DevKitM-1, running a rainbow live in your browser with the Adafruit NeoPixel library. Each pixel on the drawing shows the color the board sent it.

Three wires: 5 V, ground, and DIN to GPIO 4. The ESP32-C3 is a 3.3 V board, so the wiring notes cover the level shift a real strip may need.

  • 3.3 V logic
  • Library: Adafruit_NeoPixel.h
  • DIN on GPIO 4
  • 8 pixels, brightness 40
ESP32-C3 · NeoPixellive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.

Wiring the NeoPixel to the ESP32-C3

Every connection in the circuit above, with the board’s own pin names.

NeoPixel pinESP32-C3 pinWhy
VDD (5V)5VWS2812B pixels are 5 V parts; each can draw up to 60 mA at full white.
VSS (GND)GNDCommon ground, or the data line has no reference.
DINGPIO 4The data line into the first pixel. Each pixel keeps 24 bits and passes the rest on.

The strip runs from 5V while DIN comes from a 3.3 V pin. A WS2812B wants about 0.7 times its supply, 3.5 V, to see a high, so on a real bench a 3.3 V signal works on some strips and flickers on others. A 74AHCT125 level shifter on DIN fixes it for good. Add a 330 ohm resistor in series with DIN and a 1000 uF capacitor across the supply on any strip longer than a few pixels.

Pins to leave alone on the ESP32-C3

GPIO 8 carries the onboard LED and GPIO 9 is the BOOT button, and both are also the default I2C pins. GPIO 2, 8 and 9 are strapping pins, and only GPIO 0 to 4 can read an analog voltage.

On a real bench

The ESP32-C3 DevKitM-1 is small enough to sit on one breadboard with room for the NeoPixel beside it. Its USB port goes through a USB-to-serial chip; the cheaper SuperMini boards use the C3’s own USB, where Serial needs USB CDC on boot turned on in the IDE.

The code

The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.

NeoPixel rainbow on ESP32-C3 GPIO 4
#include <Adafruit_NeoPixel.h>

const int PIXEL_PIN = 4;    // DIN, GPIO 4
const int PIXELS = 8;

Adafruit_NeoPixel strip(PIXELS, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(115200);
  strip.begin();
  strip.setBrightness(40);   // of 255: easy on the eyes and on the supply
  strip.show();              // all off
  Serial.println("Rainbow");
}

void loop() {
  static uint16_t hue = 0;
  for (int i = 0; i < PIXELS; i++) {
    uint16_t h = hue + i * (65536L / PIXELS);
    strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(h)));
  }
  strip.show();
  hue += 512;
  delay(20);
}

Adafruit_NeoPixel strip(PIXELS, PIXEL_PIN, NEO_GRB + NEO_KHZ800) describes eight WS2812B pixels on GPIO 4, which take their colors green first at 800 kHz. On the ESP32-C3 the library times each bit on the RISC-V core.

ColorHSV() turns a hue from 0 to 65535 into red, green and blue, and gamma32() corrects it for how the eye sees brightness. Each pixel is offset by an eighth of the color wheel, so the eight make a full rainbow.

setPixelColor() only changes the library’s buffer; show() sends all 24 bits per pixel down the line at once. setBrightness(40) scales everything to about a sixth, which is also a sixth of the current.

Common mistakes with the NeoPixel on the ESP32-C3

Forgetting show()

setPixelColor() writes to memory only. Nothing changes on the strip until show() sends the buffer, so a sketch without it leaves every pixel dark.

Wiring the wrong end

Data flows one way. DIN is the input end, marked with an arrow on most strips; wired to DOUT at the far end, nothing lights. In the editor the part’s DIN pin is the one on the left.

Expecting 3.3 V data to always work

It works on the simulated strip and on many real ones. When a real strip flickers or shows random colors on the first pixel, the 3.3 V data line is the first suspect: add a 74AHCT125 level shifter.

Questions and answers

Can I simulate NeoPixels with an ESP32-C3 DevKitM-1?

Yes. The circuit at the top of this page is an ESP32-C3 DevKitM-1 with a WS2812B strip, running in your browser on a simulated ESP32-C3 (RISC-V). The simulated pixels decode the real 800 kHz bit stream from the pin, so a timing or color-order mistake shows up as it would on a desk. Press Run it in the editor to change the wiring or the code; it is free and needs no account.

Does FastLED work too?

Yes, FastLED.h compiles and runs on an ESP32-C3 DevKitM-1 in the simulator. Use FastLED.addLeds<WS2812B, 4, GRB>(leds, 8) and FastLED.show().

Why are my colors wrong?

Most WS2812B strips take green first, which is what NEO_GRB says. A strip whose red and green are swapped is an RGB one: change NEO_GRB to NEO_RGB.

Which boards can drive NeoPixels in this simulator?

The AVR boards (Uno, Nano, Mega), the ESP32-C3 and the ESP32-C6. On the other boards the WS2812B bit is too short for the simulated core to time by hand, and the library stops at compile time with a message saying so.

Build your own NeoPixel project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.