WS2812B Introduction

The WS2812B is a bit addressable RGB LED. The WS2812B (don’t confuse this with a WS2812 which has six pins) is a four pin device that is very simple to wire up to an Arduino. The LEDs can be daisy chained and are available as LED strips or discrete parts. Notice that no resistors are required because the WS2812B drives the physical LEDs with a pulse width modulated current source.

To program the LEDs a serial bit stream is sent to the input of the firsts WS2812B in the chain. The bit stream data contains three byte messages indicating the RGB intensity for each of the LEDs in the chain. For example to set the colours for a chain of three WS2812Bs we need to send 3*24 bits = 72 bits out from the Arduino. Each of the WS2812B devices replicates the input stream on its output pin so that at the end of the 72 bits each of the WS2812Bs will have a 24 bit RGB colour pattern. To update all of the LEDs the Arduino needs to send a synchronize pattern that signals the WS2812B to latch there current bit patterns; these are then updated on all of the LEDs simultaneously in effect displaying the colour messages that were shifted into the WS2812B chain.

The timing of the bit stream out of the Arduino is critical. If it is not correct the WS2812Bs will not recognize the colour messages with unpredictable results. To ensure that the timing is accurate the library uses assembly language instructions to accurately generate the required bit sequence. In order to ensure the clocking sequence is not altered the Arduino interrupts are also turned off temporarily. In the previous example 72bits were sent and each bit takes 1.25uS so the interrupts are off for 90uS which is quite short. Now imagine a LED strip with 100 RGB LEDs; the delay becomes 100LEDs*24bits/LED*1.25uS/bit= 3ms. which is a long time for interrupts to be off.WS2812B_timing


Installing the library is simply a matter of copying the folder into your Arduino project folder in the library directory. The next time you open the Arduino environment you will see the WS2812 library and examples in the Examples menu.Arduino_library_example

Things to know

  1. Each WS2812B draws 60mA when fully on so you can calculate the current draw as the #ofWS2812B*0.06A. Notice you can cut this current in half by only driving each colour from 0..127 which looks pretty much the same as full current.
  2. The WS2812B can be driven from a 3.3V source but make sure that the data input is also driven at 3.3V.
  3. Each WS2812B requires 24*1.25uS= 30uS to clock out the colour data. During this time the interrupts are off and this can effect your code if you run with interrupts. The Arduino millis() function uses interrupts.

Leave a Reply

Your email address will not be published. Required fields are marked *