Skip to content

LED / Strip · Arduino Uno guide

Interfacing WS2812B Addressable RGB LED Strip with Arduino Uno

Individually addressable RGB LEDs on one data wire: wire it right, power it properly and every pixel is yours to control.

Updated November 16, 2026 Arduino C++FastLED / Adafruit NeoPixelAlso forESP32

What is the WS2812B Strip?

A normal RGB LED strip has three wires for colour, and every LED on it shows the same colour at the same time. A WS2812B strip is different: each tiny 5050 LED has its own controller chip built inside, so every pixel can show its own colour and brightness. You feed one data wire into the first pixel, and the pixels pass the information along the strip like a bucket brigade. The first pixel keeps its 24 bits of colour, passes the rest on, the second takes the next 24 bits, and so on to the end. This is what makes rainbow waves, chases, fire effects, scrolling text on matrices and music visualisers possible with a single pin on your Arduino or ESP32.

The same chip is sold under the name NeoPixel (Adafruit's brand) and is the engine behind most LED rings, matrices, sticks and strips. For you it means one thing: the code and wiring are the same whether you have a 30-LED strip or a 300-LED reel.

The WS2812B is easy to drive but unforgiving about three things: power, ground and the data signal level. Get those right and it just works. Get them wrong and you will meet flickering, wrong colours, a dead first pixel or a microcontroller that keeps resetting. This page walks through all of it: how the protocol works, how to size the power supply, power injection on long strips, the 3.3 V data problem on an ESP32, which library to choose, and a troubleshooting table. For wiring and code, see the Arduino Uno guide and the ESP32 guide.

Specifications

LED type
WS2812B: 5050 RGB LED with the driver chip built into every pixel
Supply voltage
5 V DC (about 3.5 to 5.3 V tolerated; 5 V is standard)
Current per pixel
Up to about 60 mA at full white (20 mA per colour); roughly 1 mA idle
Colour depth
24-bit: 8 bits each for red, green and blue
Data order
GRB (green first), not RGB
Data protocol
Single-wire, about 800 kHz; each pixel keeps 24 bits and forwards the rest
Bit timing
1.25 µs per bit: a 0 is a ~0.4 µs high pulse, a 1 is a ~0.8 µs high pulse
Latch / reset
Data held low for at least 280 µs (50 µs on older batches)
Update time
About 30 µs per pixel: 30 LEDs ≈ 1 ms, 144 LEDs ≈ 4.3 ms
Logic high threshold
About 0.7 × VDD, roughly 3.5 V at 5 V (marginal for 3.3 V logic)
Strip densities
30, 60 or 144 LEDs per metre; IP30 (bare), IP65 (coated) or IP67 (tube)
RAM per pixel
3 bytes on the microcontroller (100 LEDs use 300 of the Uno's 2,048 bytes)

From the WS2812B datasheet and the FastLED / Adafruit NeoPixel documentation. Strips vary by manufacturer: test yours and fuse the supply.

Pinout

PadNameDescription
15VPower. Feed from a dedicated 5 V supply sized for the whole strip
2GNDGround, shared with the microcontroller and the supply
3DINData in, through a 330 to 470 Ω resistor. The arrow points away from this end
4DOUTData out at the far end: feeds DIN of the next segment

Wiring & code

Setting up WS2812B Strip with Arduino Uno

Library

FastLED / Adafruit NeoPixel by FastLED community / Adafruit

Library Manager: install "FastLED" for the effects and "Adafruit NeoPixel" for the first test

This guide lights a WS2812B strip from an Arduino Uno, starting with eight pixels you can power from USB and ending with an effects controller: a button cycles through animations and a knob sets the brightness. The Uno drives the strip's data line directly at 5 V; what needs care is power. Background on the protocol, power budgeting and injection is on the WS2812B overview.

What you need

  • 1Arduino Uno R3 (or Nano)

    Notes
    Any 5 V Arduino
  • 1WS2812B strip, 30 LEDs (or a short test piece)

    Notes
    Sketch 1 lights only 8 pixels, safe from USB
  • 15 V power supply, 2 A or more

    Notes
    For the full strip at real brightness
  • 1 each330 Ω resistor and 1000 µF / 6.3 V capacitor

    Notes
    Data-line resistor and supply smoothing
  • 1 eachPush button and 10 kΩ potentiometer

    Notes
    Only for Sketch 3

Wiring

Strip pinArduino Uno pinNote
5VExternal 5V supply (+)For more than about 8 pixels, power the strip from its own supply, not the Uno's 5V pin. Add a 1000 µF capacitor across 5V and GND at the strip.
GNDGNDJoin the Uno's GND, the external supply's GND and the strip's GND.
DINPin 6Use a 330–470 Ω resistor in series, close to the strip. Make sure you connect to the DIN end (follow the arrow).

Each pixel can draw about 60 mA at full white, so a 30-LED strip may pull 1.8 A, far more than the Uno's regulator or a USB port can supply. Use an external 5 V supply, join the grounds and rely on setMaxPowerInVoltsAndMilliamps() as a safety net. If you test from USB only, keep the power limit near 400 mA and the pixel count low.

Connect ground first and power last. If the Uno is powered from USB and the strip from a separate supply, only the grounds should be shared, and nothing should feed 5 V back into the Uno's pin.

On the Uno's 2 KB of RAM every pixel costs 3 bytes, and interrupts are off while the strip updates. Stay under about 200 pixels for comfort and avoid mixing the strip with interrupt-heavy code such as IR receivers or software serial.

Warning

Connect ground first and power last, and never plug the strip into a powered supply with the data wire already attached to a running Uno: the voltage spike can kill the first pixel. If the first LED dies, cut it off and solder to the next one.

Sketch 1 - First test with Adafruit NeoPixel

Before writing effects, prove the wiring with the simplest library. This sketch lights only the first eight pixels at low brightness, which a USB-powered Uno can handle: red, green, blue, white, then four mixed colours. If they appear in that order, the data direction, colour order and grounds are all right.

  1. 1Sketch > Include Library > Manage Libraries, search "Adafruit NeoPixel" and install it.
  2. 2Wire DIN to pin 6 through the 330 Ω resistor, and join the grounds.
  3. 3Upload the sketch below.
sketch.ino
#include <Adafruit_NeoPixel.h>

#define DATA_PIN 6
#define NUM_LEDS 8          // only the first 8 pixels: safe from USB

Adafruit_NeoPixel strip(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.setBrightness(40);  // 0-255; keep it low while testing
  strip.setPixelColor(0, strip.Color(255, 0, 0));      // red
  strip.setPixelColor(1, strip.Color(0, 255, 0));      // green
  strip.setPixelColor(2, strip.Color(0, 0, 255));      // blue
  strip.setPixelColor(3, strip.Color(255, 255, 255));  // white
  strip.setPixelColor(4, strip.Color(255, 120, 0));    // orange
  strip.setPixelColor(5, strip.Color(180, 0, 255));    // purple
  strip.setPixelColor(6, strip.Color(0, 255, 180));    // aqua
  strip.setPixelColor(7, strip.Color(255, 0, 80));     // pink
  strip.show();             // nothing changes on the strip until show()
}

void loop() {}

Tip

Red and green swapped? Your strip uses a different colour order: change NEO_GRB to NEO_RGB. Only the first pixel lights, or none? Check you are on the DIN end and that the grounds are joined.

Sketch 2 - FastLED rainbow with a power limit

Now the whole strip, from the external supply. FastLED's setMaxPowerInVoltsAndMilliamps() keeps the strip within the current you allow, whatever the effect asks for.

sketch.ino
#include <FastLED.h>

#define DATA_PIN   6
#define NUM_LEDS   30
#define BRIGHTNESS 64

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000);   // ~1 A budget for a 30-pixel test strip
  FastLED.clear(true);
}

void loop() {
  static uint8_t hue = 0;
  fill_rainbow(leds, NUM_LEDS, hue++, 7);
  FastLED.show();
  FastLED.delay(20);
}

How the FastLED sketch works

CRGB leds[NUM_LEDS]; is the array that holds the colour of every pixel in memory. Setting leds[5] = CRGB::Red; changes the array but not the strip. The strip only changes when you call FastLED.show(), which pushes the whole array out in one go. That is why animations are written as "change the array, then show".

FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); tells the library the chip type, the data pin (which must be a fixed number, not a variable) and the colour order. If red and green look swapped, change GRB to RGB.

FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000); is the safety net. You tell the library the supply voltage and the maximum current you want it to use, and it scales the brightness down automatically if an effect would draw more. On an Uno powered from USB, use about 400 to 500 mA. With a proper external supply, use a value a little below its rating.

fill_rainbow() fills the array with a smooth hue gradient, and fadeToBlackBy() dims every pixel slightly each frame, which is the trick behind comet and trail effects. FastLED.delay() waits while still letting the library do background tasks such as dithering.

Sketch 3 - Effects controller with a button and a brightness knob

A real lamp needs controls. Here a push button on D2 cycles through three effects (rainbow, comet with a fading tail, and a warm candle flicker) and a potentiometer on A0 sets the brightness. The animation runs from FastLED's EVERY_N_MILLISECONDS timer instead of delay(), so the button responds instantly.

Extra wiring for Sketch 3

PartUno pinNotes
Push buttonD2 and GNDUses the internal pull-up: pressed reads LOW
Potentiometer wiperA0Outer legs to 5V and GND
sketch.ino
#include <FastLED.h>

#define DATA_PIN   6
#define NUM_LEDS   30
#define BUTTON_PIN 2       // to GND; internal pull-up
#define POT_PIN    A0

CRGB leds[NUM_LEDS];
uint8_t mode = 0;          // 0 = rainbow, 1 = comet, 2 = candle
const uint8_t MODES = 3;

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setCorrection(TypicalLEDStrip);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000);   // stay within a 1 A budget
}

// Next effect on each press, with a 30 ms debounce
void readButton() {
  static bool lastState = HIGH;
  static uint32_t lastChange = 0;
  bool state = digitalRead(BUTTON_PIN);
  if (state != lastState && millis() - lastChange > 30) {
    lastChange = millis();
    lastState = state;
    if (state == LOW) {
      mode = (mode + 1) % MODES;
      FastLED.clear();
    }
  }
}

void loop() {
  readButton();
  FastLED.setBrightness(map(analogRead(POT_PIN), 0, 1023, 5, 255));

  EVERY_N_MILLISECONDS(20) {
    static uint8_t hue = 0;
    static uint8_t pos = 0;
    switch (mode) {
      case 0:                                         // rainbow
      fill_rainbow(leds, NUM_LEDS, hue++, 7);
      break;
      case 1:                                         // comet with a fading tail
      fadeToBlackBy(leds, NUM_LEDS, 40);
      leds[pos] = CHSV(hue, 255, 255);
      pos = (pos + 1) % NUM_LEDS;
      hue += 2;
      break;
      case 2:                                         // candle: random warm flicker
      fadeToBlackBy(leds, NUM_LEDS, 8);
      leds[random8(NUM_LEDS)] = CHSV(random8(10, 30), 255, random8(120, 255));
      break;
    }
    FastLED.show();
  }
}

How it works. readButton() runs on every pass of loop(), so presses are caught immediately, and the 30 ms check ignores contact bounce. EVERY_N_MILLISECONDS(20) runs the animation 50 times a second without blocking. The comet's tail is just fadeToBlackBy() dimming every pixel a little each frame, while only the head is redrawn at full brightness. Add your own effect as case 3 and raise MODES.

Troubleshooting on the Uno

  • Nothing lights

    Likely cause
    Data on the DOUT end, or no common ground
    Fix
    Follow the arrow from DIN; join the Uno and supply grounds
  • Uno resets when the strip brightens

    Likely cause
    The strip is powered from the Uno, or the supply sags
    Fix
    External 5 V supply, 1000 µF at the strip, lower the power limit
  • Random flicker on the first pixel

    Likely cause
    No series resistor, or a long data wire
    Fix
    330 Ω at the strip end of the data wire; keep it under about 1 m
  • millis() runs slow or Serial drops characters

    Likely cause
    Interrupts are off during every show()
    Fix
    Fewer pixels, fewer show() calls, or move to an ESP32
  • Sketch stops working above ~200 LEDs

    Likely cause
    Out of RAM: 3 bytes per pixel plus your code
    Fix
    Reduce NUM_LEDS, or use an ESP32
  • Button changes mode twice

    Likely cause
    Switch bounce
    Fix
    Raise the 30 ms debounce time

Arduino Uno FAQ

Which pin should I use? Any digital pin works with both libraries; pin 6 is the convention. With FastLED the pin must be a constant, as in #define DATA_PIN 6.

Can I power the Uno from the same 5 V supply? Yes: connect the supply's 5 V to the Uno's 5V pin (not VIN) and do not plug in USB at the same time, or the two supplies fight. While developing, it is simpler to power the Uno from USB and share only ground.

How many LEDs can an Uno drive? A few hundred in theory, limited by RAM (3 bytes each) and by the interrupts-off time during updates. For smooth animation with other code running, stay under about 200.

Where next? Control the strip from your phone with the WS2812B ESP32 guide, or try a grid in the WS2812B matrix guide.

Keep learning

Related guides & projects