Arduino Nano · NeoPixel

Arduino Nano NeoPixel Simulator: Wiring, Code and a Live Circuit

This is a strip of eight WS2812B NeoPixels wired to an Arduino Nano, 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 pin 6. The Arduino Nano is a 5 V board, so the data line needs no level shifter.

  • 5 V logic
  • Library: Adafruit_NeoPixel.h
  • DIN on pin 6
  • 8 pixels, brightness 40
Arduino Nano · 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 Arduino Nano

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

NeoPixel pinArduino Nano 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.
DINpin 6The data line into the first pixel. Each pixel keeps 24 bits and passes the rest on.

The Arduino Nano drives DIN at 5 V, which is exactly what the pixels expect. Eight pixels at brightness 40 are well within what USB gives; a longer strip at full white needs its own 5 V supply, a 330 ohm resistor in series with DIN and a 1000 uF capacitor across the supply.

Pins to leave alone on the Arduino Nano

A6 and A7 are analog only: pinMode(A6, OUTPUT) does nothing and digitalRead(A7) is not there to call. D0 and D1 are the USB serial port.

On a real bench

The Nano plugs into the breadboard itself, straddling the center channel, so the NeoPixel goes in a few columns along and every connection is a short jumper. The silkscreen labels its pins D2 to D13 and A0 to A7; in code D2 is simply 2. A Nano clone with a CH340 USB chip needs that driver on a real computer.

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 Arduino Nano pin 6
#include <Adafruit_NeoPixel.h>

const int PIXEL_PIN = 6;    // DIN, pin 6
const int PIXELS = 8;

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

void setup() {
  Serial.begin(9600);
  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 pin 6, which take their colors green first at 800 kHz. On the ATmega328P the library sends each bit with counted instructions, interrupts off, exactly as the real library does.

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 Arduino Nano

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.

Running a long strip from the board

Sixty pixels at full white can draw 3.6 A, far beyond the 5V pin. Power the strip directly from a 5 V supply, join the grounds, and keep the brightness down in code.

Questions and answers

Can I simulate NeoPixels with an Arduino Nano?

Yes. The circuit at the top of this page is an Arduino Nano with a WS2812B strip, running in your browser on a simulated ATmega328P. 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 Arduino Nano in the simulator. Use FastLED.addLeds<WS2812B, 6, 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.