Try Embedded

Chained NeoPixels

Chain three single NeoPixels DOUT to DIN and run a light along them.

Displays · Beginner

In a real product: Smart LED strip (Smart home): Addressable LEDs each take their own colour from one data line.

Single NeoPixels can be chained into a strip of any length: each one's data output (DOUT) feeds the next one's input (DIN). The first pixel keeps the first colour it receives and passes the rest down the line.

What you'll learn

  • How WS2812 pixels pass data along a chain
  • Pixel numbers follow the chain: the one wired to the board is pixel 0
  • Making a simple "chaser" animation

How it works

Pin 6 goes to the first pixel's DIN. Its DOUT goes to the second pixel's DIN, and so on. Every pixel also needs power: VDD to 5V and VSS to GND.

When the board sends three colours, pixel 0 takes the first and repeats the next two out of DOUT, pixel 1 takes the second, pixel 2 the third. The loop lights one pixel at a time in turn, in a different colour each.

Try this

  • Add more pixels to the chain and raise COUNT: nothing else changes.
  • Make the light bounce back and forth instead of wrapping around.
  • Light all three in the colours of a traffic light.

sketch.ino

// Three NeoPixels chained DOUT to DIN, starting from pin 6: a light runs along them.
#include <Adafruit_NeoPixel.h>

const int PIN = 6;
const int COUNT = 3;
Adafruit_NeoPixel pixels(COUNT, PIN, NEO_GRB + NEO_KHZ800);
const uint32_t COLORS[COUNT] = {0xFF0000, 0x00FF00, 0x0000FF};  // red, green, blue

void setup() {
  pixels.begin();
  pixels.setBrightness(100);
}

void loop() {
  for (int lit = 0; lit < COUNT; lit++) {
    pixels.clear();
    pixels.setPixelColor(lit, COLORS[lit]);
    pixels.show();
    delay(400);
  }
}

Lessons behind it