WS2812 LED bar/What it is/01. One wire, five LEDs
What it is · 01 of 9

One wire, five LEDs

Five LEDs, three colours in each, and one wire from your board. Each LED on the TK33 has its own small chip: it keeps the first 24 bits it hears, one colour for itself, and passes everything after them to the next LED down.

Each LED has its own chip

An ordinary RGB LED is three LEDs in one package, and your board drives each colour from its own pin. The five on the TK33 are WS2812B LEDs: the same three colours plus a small driver chip, all in a 5 mm square. The chip holds three brightness values, one per colour, and keeps the LEDs at them by itself.

So your board never drives an LED. It sends numbers down one wire, called DATA, and the chips do the rest.

The first 24 bits are yours, LED1

Each LED keeps 24 bits and passes the rest
queued
Bits sent
0 of 120
Time
0 µs
LEDs showing
0
Five colours wait in the sketch: 120 bits, the first LED's first. Nothing on the bar has changed yet.

A colour is three bytes, 24 bits: green, red, blue, 0 to 255 each. A frame for this bar is five of those, 120 bits, sent as one stream.

The top LED, LED1, keeps the first 24 bits that reach it. Everything after them it sends out of its own output pin, DOUT, rebuilt as a clean signal, into the next LED's input, DIN. LED2 does the same with what is left, and so on down. When the line then stays low for at least 80 µs, every LED shows what it kept.

That is why no LED has an address. Which colour an LED gets depends only on where it sits in the chain: LED1 is pixel 0 in a sketch, and the bottom LED is pixel 4.

Where the stream stops

LED5 keeps the last 24 bits and passes on whatever follows. On this board that goes nowhere: LED5's DOUT is soldered to a pad that no trace reaches. A sketch that sends ten colours lights these five and loses the other five. Where the chain ends is about what that means for a second bar.

What it costs

The timing is the price. A 0 and a 1 are told apart by a few hundred nanoseconds of pulse width, far too fine for digitalWrite(). A library does it: on an ESP32 it hands the bits to a peripheral built for exact pulses, so nothing else in the sketch can upset them. Bits as pulse widths shows the rule the LED reads by.

When it does not work

Why not three GPIOs per LED, like an ordinary RGB LED?

Five LEDs would take fifteen pins and fifteen PWM channels. Here the brightness control lives inside each LED, so one data pin sets all fifteen colours, and the pin is free again the moment a frame has been sent: the LEDs hold their colours until the next one.

Do the LEDs keep their colour if the sketch stops?

Yes, for as long as VCC stays up. Each LED's chip holds the last 24 bits it latched and keeps driving them. Pull the power and they remember nothing; they usually come back dark.

Can I set one LED without sending the others?

No. The LED you want is found by position: the third LED only sees the bits left over after the first two have taken theirs. To change one, the sketch sends all five, which is what a library's show() does. At five LEDs a frame takes 150 microseconds, so it costs nothing.

Where this goes next

Five LEDs, a header, and the parts a WS2812 design often has and this one does not.

What is on the board

Edit this page — content/books/ws2812-led-bar/one-wire-five-leds.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

WS2812 RGB LED Bar

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum