Guide for WS2812B Addressable RGB LED Strip with Arduino


Introducing the WS2812B LED Strip

The WS2812B addressable LED strip comes in several models that differ in size, sealant or LED density. Choose the one that best fits your purposes. 

Where to buy?

You can visit Maker Advisor and find the WS2812B RGB LED Strip best price.




This LED strip is made by WS2812B LEDs wired in series. These LEDs have an IC built right into the LED. This allows a communication via a one-wire interface. This means that you can control lots of LEDs using just one digital pin of your Arduino. 









Powering the WS2812B LED Strip

The LED strip should be powered using a 5V power source. At 5V, each LED draws about 50mA, when set to its full brightness.  This means that for every 30 LEDs, the strip may draw as much as 1.5 A. Make sure you select a power source that matches the strip’s needs. An AC to DC power adapter that provides 5V and 2A should do the job:

If you use an external power source, don’t forget to connect the power source ground to the Arduino ground.


In this example, the WS2812B LED strip will be powered using the 5V Arduino pin. In my case, I’m controlling 14 LEDs. If you want to control many LEDs, you’ll need to use an external power source.


Useful tips:




Installing the FastLED library

  3. Rename your folder from FastLED-master to FastLED
  5. Finally, re-open your Arduino IDE


#include <FastLED.h>

#define LED_PIN     5
#define NUM_LEDS    14
#define BRIGHTNESS  64
#define LED_TYPE    WS2811


// This example shows several ways to set up and use 'palettes' of colors
// with FastLED.
// These compact palettes provide an easy way to re-colorize your
// animation on the fly, quickly, easily, and with low overhead.
// USING palettes is MUCH simpler in practice than in theory, so first just
// the code.  Although this sketch has eight (or more) different color schemes,
// the entire sketch compiles down to about 6.5K on AVR.
// FastLED provides a few pre-configured color palettes, and makes it
// extremely easy to make up your own color schemes with palettes.
// Some notes on the more abstract 'theory and practice' of
// FastLED compact palettes are at the bottom of this file.

CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;

void setup() {
    delay( 3000 ); // power-up safety delay
    FastLED.setBrightness(  BRIGHTNESS );
    currentPalette = RainbowColors_p;
    currentBlending = LINEARBLEND;

void loop()
    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; /* motion speed */
    FillLEDsFromPaletteColors( startIndex);;
    FastLED.delay(1000 / UPDATES_PER_SECOND);

void FillLEDsFromPaletteColors( uint8_t colorIndex)
    uint8_t brightness = 255;
        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;

// There are several different palettes of colors demonstrated here.
// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
// Additionally, you can manually define your own color palettes, or you can write
// code that creates color palettes on the fly.  All are shown here.

void ChangePalettePeriodically()
    uint8_t secondHand = (millis() / 1000) % 60;
    static uint8_t lastSecond = 99;
    if( lastSecond != secondHand) {
        lastSecond = secondHand;
        if( secondHand ==  0)  { currentPalette = RainbowColors_p;         currentBlending = LINEARBLEND; }
        if( secondHand == 10)  { currentPalette = RainbowStripeColors_p;   currentBlending = NOBLEND;  }
        if( secondHand == 15)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }
        if( secondHand == 20)  { SetupPurpleAndGreenPalette();             currentBlending = LINEARBLEND; }
        if( secondHand == 25)  { SetupTotallyRandomPalette();              currentBlending = LINEARBLEND; }
        if( secondHand == 30)  { SetupBlackAndWhiteStripedPalette();       currentBlending = NOBLEND; }
        if( secondHand == 35)  { SetupBlackAndWhiteStripedPalette();       currentBlending = LINEARBLEND; }
        if( secondHand == 40)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 45)  { currentPalette = PartyColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 50)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }
        if( secondHand == 55)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }

// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
        currentPalette[i] = CHSV( random8(), 255, random8());

// This function sets up a palette of black and white stripes,
// using code.  Since the palette is effectively an array of
// sixteen CRGB colors, the various fill_* functions can be used
// to set them up.
void SetupBlackAndWhiteStripedPalette()
    // 'black out' all 16 palette entries...
    fill_solid( currentPalette, 16, CRGB::Black);
    // and set every fourth one to white.
    currentPalette[0] = CRGB::White;
    currentPalette[4] = CRGB::White;
    currentPalette[8] = CRGB::White;
    currentPalette[12] = CRGB::White;

// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
    CRGB purple = CHSV( HUE_PURPLE, 255, 255);
    CRGB green  = CHSV( HUE_GREEN, 255, 255);
    CRGB black  = CRGB::Black;
    currentPalette = CRGBPalette16(
                                   green,  green,  black,  black,
                                   purple, purple, black,  black,
                                   green,  green,  black,  black,
                                   purple, purple, black,  black );

// This example shows how to set up a static color palette
// which is stored in PROGMEM (flash), which is almost always more
// plentiful than RAM.  A static PROGMEM palette like this
// takes up 64 bytes of flash.
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
    CRGB::Gray, // 'white' is too bright compared to red and blue

// Additionl notes on FastLED compact palettes:
// Normally, in computer graphics, the palette (or "color lookup table")
// has 256 entries, each containing a specific 24-bit RGB color.  You can then
// index into the color palette using a simple 8-bit (one byte) value.
// A 256-entry color palette takes up 768 bytes of RAM, which on Arduino
// is quite possibly "too many" bytes.
// FastLED does offer traditional 256-element palettes, for setups that
// can afford the 768-byte cost in RAM.
// However, FastLED also offers a compact alternative.  FastLED offers
// palettes that store 16 distinct entries, but can be accessed AS IF
// they actually have 256 entries; this is accomplished by interpolating
// between the 16 explicit entries to create fifteen intermediate palette
// entries between each pair.
// So for example, if you set the first two explicit entries of a compact 
// palette to Green (0,255,0) and Blue (0,0,255), and then retrieved 
// the first sixteen entries from the virtual palette (of 256), you'd get
// Green, followed by a smooth gradient from green-to-blue, and then Blue.

View raw code

You have to change NUM_LEDS variable to the number of LEDs in your LED strip. In our example, the LED strip is 14 LEDs long.

#define NUM_LEDS 14

If you want to use another pin of the Arduino to control the LED strip, you need to change the LED_PIN variable:

#define LED_PIN 5




And this one:


And this one:


And so on (…)

Using an LED Strip Case




Wrapping Up

This post is an introduction to the addressable RGB LED strip with the Arduino. We’ve just experimented with the library example. You should modify the example to only display the effects you want. We hope you’ve found this guide useful.

If like this post, you may also like:

Thanks for reading.



Enjoyed this project? Stay updated by subscribing our newsletter!

73 thoughts on “Guide for WS2812B Addressable RGB LED Strip with Arduino”

  1. Is there any way to set a timer in the code, say for every 10 minutes the leds flash? Also could that be done on an ESP with arduino IDE, instead of lua?

  2. Hi, I was wondering how bright these LEDs are, and if they would be visible (in maybe an amber/orange color) during daylight hours, if flashing? thank you.

  3. Awesome! This is the first sample code I’ve gotten for some crazy new project that has just *worked* right off the bat!! I’m so excited to start playing with my LED strip.

  4. Although a competent assembly language programmer with Z80, 8085 & Microchip PIC’s for some reason I’d always shied away from using an Arduino but upon deciding to try found the web full of so much banter I felt it confusing but your website proved just the ticket!! Clearly presented, smoothing the way for my 10 LED’s sequence (using PL9823’s!) Nice work!!

  5. Hi, Thanks for the description. I always end up with an issue. Compiles and updates just fine, but the LED strip always ending up the first 5-7 (depending on the program) fully lit in white, and the rest of the strip is off. I tried to write simple command only for specific LED position to turn on to a set colour, but always the first LED is lit with some other (usually green or white) colour and I don’t know why… Any idea? I’m using a WS2812B chip strip.

    • I haven’t encountered that issue before. This example was tested (recently) and it works with any strip that has the WS2812B chip.
      I would report your exact problem on the Library github issues pages or use another LED strip to see if it’s a problem with your specific strip.


    • try changing the definition of where your data pin is and how many leds there are in the strip. it is at the top of the source code.

    • Hi, I’m having the same problem. Did you manage to find what is the problem and how did you fix it?

      Thank you for your help.

      • I had the same Issues as yourself and Levi Mixed with the strips never truly looking quite right.
        I had the Wallworts for both the Arduono Board and the WS2812B Strip plugged into the same wall socket. I switched the Arduino to battery leaving the Wallwort on the Strips and it was a HUGE change but not quite right still.
        Finally, I switched both to Batteries and The strips came alive with the colors and effects I had been pulling my hair out trying to get right.
        Later testing proved my AC was not properly grounded (Earth) and there was a TON of noise in my lines. Changing Capacitor values, new strips from different manufacturers was not the challenge all long.
        As you can imagine, I now have a TON more WS2812Bs than I originally intended to purchase but man oh man when working right, you jut can’t have enough of them!
        Hope that helps!

  6. Hi,
    I am trying to find the WS2812B LED strip that has GND, Din and 5V as shown in the example, but I can’t. Please, can you help?

  7. Dear Admin,
    This is a request :
    Can you show, how this strip works with Raspberry PI. Only code will be enough.

    Waiting for your reply..

  8. I am planning to purchase this item (the high density, 72 led/0.5m)

    Do you know if the channel you linked is the proper size for that strip?

    Also, how would i modify your example scripts to have just one light on at a time, for about 2-3 seconds? Any suggestions for how to do this or resources will be appreciated.

    Thanks so much.

    • Hi Anita.
      LED strips usually have a standard width. So, that channel should do the job for most LED strips.
      However, the LED strip you’re referring has an extra sealant protecting the strip. So, I’m not sure if it will fit on that channel.

      To make your own patterns on the strip, I recommend taking a look at the examples provided in the FastLED library, and modify them to achieve what you want.
      Here’s a link to the examples:
      I hope this helps.
      Sara 🙂

  9. Thanks for the tutorial. It’s my first Arduino project so I appreciate you putting this up.

    I am having a weird problem. I’ve cut a strip of SK6812 with 8 LEDs and I set NUM_LEDS to 8. The first 6 LEDs work as expected but the last 2 stay dark. If I change NUM_LEDS to 10 they all light up and work correctly.

    I suppose I could always set it +2 but I’d rather understand the underlying issue. Have you seen anything like this?

    • Hi John.
      Unfortunately, I have no idea why that happens with your strip.
      We’ve tested the code with a WS2812B LED strip, and it worked fine.
      I don’t know if it has something to do with the SK6812 LED strip (we don’t have one of those to test).
      Sara 🙂

  10. Hello – great tutorial & sample code. Unfortunately, on my Windows 10 box, trying to compile for Intel Edison board, upon loading I get compile error:

    \Documents\Arduino\libraries\FastLED/platforms/avr/led_sysdefs_avr.h:12:20: fatal error: avr/io.h: No such file or directory

    I searched quite a bit and found an io.h file in system directory
    and I COPIED io.h from the buried location into the path where led_sysdefs_avr.h is looking for it (I think..) but compilation continues to fail, complaining that io.h isn’t found.

    Any hints please?? Thanks, D.

    • Hi Dave.
      I’m not sure, but I think the problem is that this Arduino code is not compatible with the Intel Edison board :/
      Sara 🙂

  11. Hello i have a problem with the code or the version of fast Led
    Problem: pragma message “FastLED version 3.002.000”
    what means that ? im totally inexperienced. Need help

    • Hi Markus.
      I’ve never get that error. So, I’m not sure what that means.
      Take a look at this: and see if that solves your problem.

    • Hi Edward.
      The LEDs are addressable, but with a digital pin (not serial).
      You can find the datasheet if you search for its name online (“WS18B20 datasheet pdf”) or get it from your parts supplier.

  12. Thank you for the interesting article. I plan to build a lighting fixture which will be
    a) long (appx 10ft)
    b) not exactly close to a power outlet because
    c) it will be hanging halfway up in a corridor that is pretty high.
    So Ideally I’d like to connect the light fixture with those modern decorative trans-white electrical wiring harnesses. This will probably be close to 2 meters (6ft) long.
    Is there anything I should keep in mind in terms of power supply (i.e. do I have to compensate for that long electrical connection)?

    • Hi Paul.
      It will really depend on your setup, and how many LEDs your strip has.
      You need to test it yourself.
      Sorry that I can’t help you more.

  13. Great tutorial, simple and concise. Just one question. I have a one meter WS2812B that is powered directly by the Arduino Uno with an added capacitor. However, when I put in a 330Ω resistor, as described, I get no lights at all. Remove the resistor and everything works great. Does it really need the resistor since my understanding is the strip already has resistors?

    • Hi John.
      They may take some time to update (a few milliseconds) depending on the length of your strip.
      The first LEDs receive the signal first, so they will light up before the LEDs on the other end of the strip.

  14. Hi,

    I am using the same LEDs for some work.
    Components I am using: NodeMCU, Jumper Wires, 5V 5A Adapter since I am using 150 LEDs.
    I am having an issue with the LEDs that after some time the LED strip stops working. When I checked them through multimeter, I found that the GND pin and the 5V pin is short-circuited. I am not able to understand how this is possible.

    To confirm this, I checked a new LED Strip with the multimeter and it was not getting short-circuited.

    Can someone please tell me the reason for this? Right now, 5*5metres of LEDs got wasted by this reason.

    • I presume that one of the LEDs in your strip failed and got into short circuit. As a result, the entire strip measures short circuit. One can only speculate on the reason why – LED overheating, Overvoltage from power supply, premature failure are all possibilities. The good news is that you don’t have to throw away your LED strips. Procedure to find the faulty LED is A) Examine visually each single LED. The LED that looks odd will be the defective one. B) Apply power. Feel every LED. The LED that heats up will be defective. C) Cut the strip in half. Measure both halves for short circuit (one should be fine, the other short circuit). Again – Cut the defective part in half and proceed in the same way. Keep going as long as you deem useful. Then solder the good parts back together.

    • Make sure that current per LED is not greater than 15ma. When you drive them too bright, you end up damaging the LEDS. 5A for 50 leds would drive them at 5000/50 ie 100mA, at full brightness. So adjust it in the code…

      • hey my strip draws 1000mA on 12volt, it includes 60 diodes, so each diode uses 16,6 mA is that okay, a normal diode, should be under 20mA i have been told but i don’t know what the rule is for an RGB diode

    • Hi Kevin.
      Probably, the USB is not providing enough power to your strip.
      How many LEDs are you trying to light up?

  15. Hi Sara,
    Have a question can not find anywhere, I am In the process of downloading data into Adriano now, my question is can I hook up a controller specifically the SP108 E wifi controller to the Adriano, so I can change lighting sequences from my phone ?
    And if not the only way to change sequence is ?
    Thanks Sara

  16. Love your program you did a great job ! I plan to decorate my front window with 300 leds for Christmas , dont worry i an using a 5V 20A power supply .
    i will modify it to be controllable by wifi using Blynk . many thanks for your hard work !

  17. Dear Sara… I build business signs and recently got the hair brained idea to back light them with SK6812 rgbw led’s. My idea is to have some of the leds permanently on with solid colors (or white), while others flash at different areas on the sign. My question is; Is it possible to do this with these leds using an arduino uno or am I barking up the wrong tree?

    If it is possible, could you please steer me in the right direction to find a program that’s suitable for this type of application. Your help would be greatly appreciated. Thank you.
    Tim B

  18. Hi Sara.. Sorry I am so random in responding.. I got distracted with other projects and have come back to the SK6812 RGBW..
    I forgot to tell you that I had bought an Arduino Uno to accomplish what i wanted to do. Is programming groups of individual pixels possible with the Arduino or do i have to buy a micropython to accomplish what I need to do?
    eg: pixels 0-39 solid red, 40 -45 solid green, 46- 55 solid blue, 56-58 flashing white.
    Is there somewhere to find what the programming language means and how to get different colors from the pixels?
    As you can already tell I’m new to this, and your help is much appreciated. Thank You.


  19. Bonjour,
    J’ignore si ce fil est toujours “actif”, mais je ne le découvre qu’aujourd’hui.
    Félicitation pour la cordialité et la clarté des explications fournies.
    Je viens vers vous car, après ma découverte des WX2812 et des différents programmes, je butte sur un projet.
    Je recherche la possibilité de déclencher un effet (peu importe lequel) par une impulsion extérieure appliquée sur une entrée du microcontrôleur, j’utilise Arduino UNO ou NANO et une bande du type Néopixel.
    Mon choix d’ordre extérieur est dû au fait que j’ai besoin d’intervalles longs (1 à 2 heures) et d’une très grande précision.
    Je vous remercie de votre attention. Et de votre indulgence pour la traduction automatique, ma langue étant le Français…
    I don’t know if this thread is still “active”, but I’m only discovering it today.
    Congratulations for the cordiality and clarity of the explanations given.
    I am coming to you because, after my discovery of the WX2812 and the different programmes, I stumbled upon a project.
    I am looking for the possibility to trigger an effect (whatever it is) by an external impulse applied on an input of the microcontroller, I use Arduino UNO or NANO and a Neopixel type tape.
    My choice of external order is due to the fact that I need long intervals (1 to 2 hours) and very high precision.
    Thank you for your attention. And for your indulgence for the automatic translation, my language being French…

    • Hi.
      If you need to trigger something via an input, you can use an interrupt.
      Search for “Arduino Interrupt,” and you’ll find examples on how to use it to trigger functions.
      I hope this helps.

  20. I hope someone can clear this up for me, because I’m a little confused (I hope this has not been answered before, I can’t find it…)
    The LED strips we’re using are constantly referred to as “individually addressable”. My idea of something which is described as such, is that I can address any LED in the strip individually, and set it to whatever colour I want, but… that’s not the case is it? To set LED number 10, we have to also set LEDs 0 to 9 (and maybe 11 – max number), and 10 gets set when it receives the appropriately positioned part of the RGB bit stream.
    So rather than individually addressable, it’s more like “accurate Chinese whispers”, that being if you have a line of people in a room, you can’t walk up to person number 10 and talk to him directly (individually addressable), you have to talk to the first person in the line and ask him to “pass it on”.
    Have I got this wrong?

    • You can address to each led individualy with the count system… but I do not know how to. I know there are some softwares that do that (simhub as an example).

    • That’s right Nick, & I agree, a rather incorrect name for them.
      The data-stream comprises data [1st led R/G/B], [ 2nd led R/G/B]…..[nth led R/G/B].
      If there are say 15 leds, the;
      1st led passes forward the 14 subsequent data-packets,
      2nd one passes on 13,
      3rd one passes on 12.

      I’m presently using the tiny APA102-2020 led’s & [to most] argued this point on a forum, I’d say your naming analogy is more suited.

  21. I followed the steps and I have a fully working led strip, I already changed to just the effect I am looking for but I wanted to know if it is possible to add a button to “shut the led strip on/off”?


  22. I want to use an Arduino to run a RGB addressable neon strip to mimic car rear lights having the strip effectively broken up into 3 sections to build for a training aid for my friend. I need the controller to run two strips independently and accept a combination of 5 hi/low inputs and provide an output for each combination.

    Is it possible can you advise best way to do it.

  23. I have read and reread through this article, checked my connections verfiied no less than 6 times and every time I connect the RGB lights it restarts my arduino board with no lights.


Leave a Reply to Paul Cancel reply

Download our Free eBooks and Resources
