{"id":26734,"date":"2018-07-05T09:39:57","date_gmt":"2018-07-05T09:39:57","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=26734"},"modified":"2023-04-23T11:10:50","modified_gmt":"2023-04-23T11:10:50","slug":"guide-for-ws2812b-addressable-rgb-led-strip-with-arduino","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/guide-for-ws2812b-addressable-rgb-led-strip-with-arduino\/","title":{"rendered":"Guide for WS2812B Addressable RGB LED Strip with Arduino"},"content":{"rendered":"<p>This post is about the <strong>WS2812B LED<\/strong> strip, which is an addressable RGB LED strip. The information in this post also works with other similar LED&nbsp;strips, such as&nbsp;strips of the&nbsp;<strong>WS28XX <\/strong>family, Neopixel strip and others.<!--more--><\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-27132\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?resize=700%2C496&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"496\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?resize=150%2C106&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?resize=300%2C213&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?resize=80%2C57&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?resize=220%2C156&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?resize=141%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 141w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?resize=212%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 212w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?resize=336%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 336w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?resize=586%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 586w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?resize=687%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 687w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<h2>Introducing the WS2812B LED Strip<\/h2>\n<p><span style=\"font-weight: 400;\">The WS2812B addressable LED strip comes in several&nbsp;models that differ&nbsp;in size, sealant or&nbsp;LED density. Choose the one that best fits your purposes.&nbsp;<\/span><\/p>\n<p><strong>Where to buy?<\/strong><\/p>\n<p>You can visit <a href=\"https:\/\/makeradvisor.com\/tools\/ws2812b-addressable-rgb-led-strip\/\" target=\"_blank\" rel=\"noopener noreferrer\">Maker Advisor<\/a> and find the <a href=\"https:\/\/makeradvisor.com\/tools\/ws2812b-addressable-rgb-led-strip\/\" target=\"_blank\" rel=\"noopener noreferrer\">WS2812B RGB LED Strip<\/a> best price.<\/p>\n<p>In the following figure you can see my WS2812B LED strip. It is 5 meters long and the LEDs are enclosed in a weatherproof silicone. So, they can be left outside at the rain and dust without any problem.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\" wp-image-26735 aligncenter\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-strip.jpg?resize=624%2C490&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"led-strip\" width=\"624\" height=\"490\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-strip.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-strip.jpg?resize=150%2C118&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-strip.jpg?resize=300%2C236&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-strip.jpg?resize=80%2C63&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-strip.jpg?resize=220%2C173&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-strip.jpg?resize=127%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 127w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-strip.jpg?resize=191%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 191w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-strip.jpg?resize=303%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 303w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-strip.jpg?resize=528%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 528w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-strip.jpg?resize=620%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 620w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/p>\n<p>In my opinion, this is the coolest type of LED strips. You can control the <strong>brightness<\/strong> and the <strong>color<\/strong> of each LED <strong>individually<\/strong>, which&nbsp;allows you to produce amazing and complex effects in a simple way.<\/p>\n<p><span style=\"font-weight: 400;\">This LED strip is made&nbsp;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 <strong>lots of LEDs<\/strong> using just <strong>one digital pin<\/strong> of your Arduino.&nbsp;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the following figure you can see the chip inside the LED. The LED is an RGB LED and works like so.<\/span><\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-26962\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-with-arrow.png?resize=256%2C216&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"led-with-arrow\" width=\"256\" height=\"216\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-with-arrow.png?w=256&amp;quality=100&amp;strip=all&amp;ssl=1 256w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-with-arrow.png?resize=150%2C127&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-with-arrow.png?resize=80%2C68&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-with-arrow.png?resize=220%2C186&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-with-arrow.png?resize=119%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 119w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/LED-with-arrow.png?resize=178%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 178w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">This kind of strips are very flexible and can be cut to any length you want. As you can see, the strip is divided into segments, and each segment contains one RGB LED. &nbsp;<\/span><\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-27026\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/sections2.jpg?resize=587%2C198&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"sections2\" width=\"587\" height=\"198\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/sections2.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/sections2.jpg?resize=150%2C50&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/sections2.jpg?resize=300%2C101&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/sections2.jpg?resize=80%2C27&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/sections2.jpg?resize=220%2C74&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/sections2.jpg?resize=250%2C84&amp;quality=100&amp;strip=all&amp;ssl=1 250w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/sections2.jpg?resize=280%2C94&amp;quality=100&amp;strip=all&amp;ssl=1 280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/sections2.jpg?resize=510%2C171&amp;quality=100&amp;strip=all&amp;ssl=1 510w\" sizes=\"(max-width: 587px) 100vw, 587px\" \/><\/p>\n<p>You can adjust its size by cutting the strip with a scissors in the right place (the proper places to cut the strip are&nbsp;marked).<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-26798\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?resize=555%2C485&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"cutting-the-strip\" width=\"555\" height=\"485\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?resize=150%2C131&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?resize=300%2C262&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?resize=80%2C70&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?resize=220%2C192&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?resize=114%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 114w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?resize=172%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 172w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?resize=272%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 272w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?resize=475%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 475w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?resize=557%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 557w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/Cutting-the-strip.jpg?resize=681%2C595&amp;quality=100&amp;strip=all&amp;ssl=1 681w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/p>\n<p>These strips come with &nbsp;connectors &nbsp;at&nbsp;each end. I&#8217;ve decided to cut the connectors, and solder header pins. It&#8217;s more handy if you want to connect the strip to an&nbsp;Arduino or to a breadboard.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26973\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/stripheader.jpg?resize=673%2C235&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"stripheader\" width=\"673\" height=\"235\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/stripheader.jpg?w=673&amp;quality=100&amp;strip=all&amp;ssl=1 673w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/stripheader.jpg?resize=150%2C52&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/stripheader.jpg?resize=300%2C105&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/stripheader.jpg?resize=80%2C28&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/stripheader.jpg?resize=220%2C77&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/stripheader.jpg?resize=250%2C87&amp;quality=100&amp;strip=all&amp;ssl=1 250w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/stripheader.jpg?resize=280%2C98&amp;quality=100&amp;strip=all&amp;ssl=1 280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/stripheader.jpg?resize=510%2C178&amp;quality=100&amp;strip=all&amp;ssl=1 510w\" sizes=\"(max-width: 673px) 100vw, 673px\" \/><\/p>\n<h2>Powering the WS2812B LED Strip<\/h2>\n<p>The LED strip should&nbsp;be powered using a 5V power source. At 5V, each LED draws about 50mA, when set to its full brightness. &nbsp;This&nbsp;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&nbsp;the strip&#8217;s needs. An AC to DC power adapter that provides 5V and 2A should do the job:<\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/5v-2a-power-adaptor-dc-jack\/\" target=\"_blank\" rel=\"noopener noreferrer\">5V 2A power adapter<\/a><\/li>\n<\/ul>\n<p>If you use an external power source, don&#8217;t forget to connect the power source ground to the Arduino ground.<\/p>\n<h2>Schematics<\/h2>\n<p>In this example, the WS2812B LED strip will be powered using the 5V Arduino pin. In my case, I&#8217;m controlling 14 LEDs. If you want to control many&nbsp;LEDs, you&#8217;ll need to use an external&nbsp;power source.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27030\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/WS2812B-with-Arduino_bb.png?resize=700%2C423&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ws2812b-with-arduino_bb\" width=\"700\" height=\"423\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/WS2812B-with-Arduino_bb.png?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/WS2812B-with-Arduino_bb.png?resize=150%2C91&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/WS2812B-with-Arduino_bb.png?resize=300%2C181&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/WS2812B-with-Arduino_bb.png?resize=80%2C48&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/WS2812B-with-Arduino_bb.png?resize=220%2C133&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/WS2812B-with-Arduino_bb.png?resize=165%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 165w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/WS2812B-with-Arduino_bb.png?resize=248%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 248w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/WS2812B-with-Arduino_bb.png?resize=394%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 394w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/WS2812B-with-Arduino_bb.png?resize=687%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 687w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p><b>Useful<\/b><strong>&nbsp;tips:<\/strong><\/p>\n<ul>\n<li>Connect a capacitor with a capacitance between 100uF and 1000uF from power to ground to smooth out the power supply.<\/li>\n<li>Add a 220 or 470 Ohm resistor between the Arduino digital output pin and the strip data input pin&nbsp;to reduce noise on that line.<\/li>\n<li>Make your wires between the arduino, power supply and the strip as short as possible to minimize voltage loss.<\/li>\n<li>If your strip gets damaged and doesn&#8217;t work, check if the first LED is broken. If so, cut it, resolder the header pins, and it should work again.<\/li>\n<\/ul>\n<h2>Code<\/h2>\n<p>To control the WS2812B LED strip, you&#8217;ll need to download the <strong>FastLED<\/strong> library.<\/p>\n<p><strong>Installing the FastLED library<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/github.com\/FastLED\/FastLED\/archive\/master.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Click here to download the FastLED library<\/a>. You should have a .zip folder in your Downloads folder<\/li>\n<li>Unzip the .zip folder and you should get<strong> FastLED-maste<\/strong>r folder<\/li>\n<li>Rename your folder from <del><strong>FastLED-master<\/strong><\/del> to <strong>FastLED<\/strong><\/li>\n<li>Move the <strong>FastLED<\/strong> folder to your Arduino IDE installation <strong>libraries<\/strong> folder<\/li>\n<li>Finally, re-open your Arduino IDE<\/li>\n<\/ol>\n<p>After installing the needed library, upload the following code to your Arduino board (this is an example sketch provided in the library examples folder). Go to <strong>File<\/strong> &gt; <strong>Examples<\/strong> &gt; <strong>FastLED<\/strong> &gt; <strong>ColorPalette<\/strong> or copy the code below.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">#include &lt;FastLED.h&gt;\n\n#define LED_PIN     5\n#define NUM_LEDS    14\n#define BRIGHTNESS  64\n#define LED_TYPE    WS2811\n#define COLOR_ORDER GRB\nCRGB leds[NUM_LEDS];\n\n#define UPDATES_PER_SECOND 100\n\n\/\/ This example shows several ways to set up and use 'palettes' of colors\n\/\/ with FastLED.\n\/\/\n\/\/ These compact palettes provide an easy way to re-colorize your\n\/\/ animation on the fly, quickly, easily, and with low overhead.\n\/\/\n\/\/ USING palettes is MUCH simpler in practice than in theory, so first just\n\/\/ run this sketch, and watch the pretty lights as you then read through\n\/\/ the code.  Although this sketch has eight (or more) different color schemes,\n\/\/ the entire sketch compiles down to about 6.5K on AVR.\n\/\/\n\/\/ FastLED provides a few pre-configured color palettes, and makes it\n\/\/ extremely easy to make up your own color schemes with palettes.\n\/\/\n\/\/ Some notes on the more abstract 'theory and practice' of\n\/\/ FastLED compact palettes are at the bottom of this file.\n\n\n\nCRGBPalette16 currentPalette;\nTBlendType    currentBlending;\n\nextern CRGBPalette16 myRedWhiteBluePalette;\nextern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;\n\n\nvoid setup() {\n    delay( 3000 ); \/\/ power-up safety delay\n    FastLED.addLeds&lt;LED_TYPE, LED_PIN, COLOR_ORDER&gt;(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );\n    FastLED.setBrightness(  BRIGHTNESS );\n    \n    currentPalette = RainbowColors_p;\n    currentBlending = LINEARBLEND;\n}\n\n\nvoid loop()\n{\n    ChangePalettePeriodically();\n    \n    static uint8_t startIndex = 0;\n    startIndex = startIndex + 1; \/* motion speed *\/\n    \n    FillLEDsFromPaletteColors( startIndex);\n    \n    FastLED.show();\n    FastLED.delay(1000 \/ UPDATES_PER_SECOND);\n}\n\nvoid FillLEDsFromPaletteColors( uint8_t colorIndex)\n{\n    uint8_t brightness = 255;\n    \n    for( int i = 0; i &lt; NUM_LEDS; i++) {\n        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);\n        colorIndex += 3;\n    }\n}\n\n\n\/\/ There are several different palettes of colors demonstrated here.\n\/\/\n\/\/ FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,\n\/\/ OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.\n\/\/\n\/\/ Additionally, you can manually define your own color palettes, or you can write\n\/\/ code that creates color palettes on the fly.  All are shown here.\n\nvoid ChangePalettePeriodically()\n{\n    uint8_t secondHand = (millis() \/ 1000) % 60;\n    static uint8_t lastSecond = 99;\n    \n    if( lastSecond != secondHand) {\n        lastSecond = secondHand;\n        if( secondHand ==  0)  { currentPalette = RainbowColors_p;         currentBlending = LINEARBLEND; }\n        if( secondHand == 10)  { currentPalette = RainbowStripeColors_p;   currentBlending = NOBLEND;  }\n        if( secondHand == 15)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }\n        if( secondHand == 20)  { SetupPurpleAndGreenPalette();             currentBlending = LINEARBLEND; }\n        if( secondHand == 25)  { SetupTotallyRandomPalette();              currentBlending = LINEARBLEND; }\n        if( secondHand == 30)  { SetupBlackAndWhiteStripedPalette();       currentBlending = NOBLEND; }\n        if( secondHand == 35)  { SetupBlackAndWhiteStripedPalette();       currentBlending = LINEARBLEND; }\n        if( secondHand == 40)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }\n        if( secondHand == 45)  { currentPalette = PartyColors_p;           currentBlending = LINEARBLEND; }\n        if( secondHand == 50)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }\n        if( secondHand == 55)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }\n    }\n}\n\n\/\/ This function fills the palette with totally random colors.\nvoid SetupTotallyRandomPalette()\n{\n    for( int i = 0; i &lt; 16; i++) {\n        currentPalette[i] = CHSV( random8(), 255, random8());\n    }\n}\n\n\/\/ This function sets up a palette of black and white stripes,\n\/\/ using code.  Since the palette is effectively an array of\n\/\/ sixteen CRGB colors, the various fill_* functions can be used\n\/\/ to set them up.\nvoid SetupBlackAndWhiteStripedPalette()\n{\n    \/\/ 'black out' all 16 palette entries...\n    fill_solid( currentPalette, 16, CRGB::Black);\n    \/\/ and set every fourth one to white.\n    currentPalette[0] = CRGB::White;\n    currentPalette[4] = CRGB::White;\n    currentPalette[8] = CRGB::White;\n    currentPalette[12] = CRGB::White;\n    \n}\n\n\/\/ This function sets up a palette of purple and green stripes.\nvoid SetupPurpleAndGreenPalette()\n{\n    CRGB purple = CHSV( HUE_PURPLE, 255, 255);\n    CRGB green  = CHSV( HUE_GREEN, 255, 255);\n    CRGB black  = CRGB::Black;\n    \n    currentPalette = CRGBPalette16(\n                                   green,  green,  black,  black,\n                                   purple, purple, black,  black,\n                                   green,  green,  black,  black,\n                                   purple, purple, black,  black );\n}\n\n\n\/\/ This example shows how to set up a static color palette\n\/\/ which is stored in PROGMEM (flash), which is almost always more\n\/\/ plentiful than RAM.  A static PROGMEM palette like this\n\/\/ takes up 64 bytes of flash.\nconst TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =\n{\n    CRGB::Red,\n    CRGB::Gray, \/\/ 'white' is too bright compared to red and blue\n    CRGB::Blue,\n    CRGB::Black,\n    \n    CRGB::Red,\n    CRGB::Gray,\n    CRGB::Blue,\n    CRGB::Black,\n    \n    CRGB::Red,\n    CRGB::Red,\n    CRGB::Gray,\n    CRGB::Gray,\n    CRGB::Blue,\n    CRGB::Blue,\n    CRGB::Black,\n    CRGB::Black\n};\n\n\n\n\/\/ Additionl notes on FastLED compact palettes:\n\/\/\n\/\/ Normally, in computer graphics, the palette (or &quot;color lookup table&quot;)\n\/\/ has 256 entries, each containing a specific 24-bit RGB color.  You can then\n\/\/ index into the color palette using a simple 8-bit (one byte) value.\n\/\/ A 256-entry color palette takes up 768 bytes of RAM, which on Arduino\n\/\/ is quite possibly &quot;too many&quot; bytes.\n\/\/\n\/\/ FastLED does offer traditional 256-element palettes, for setups that\n\/\/ can afford the 768-byte cost in RAM.\n\/\/\n\/\/ However, FastLED also offers a compact alternative.  FastLED offers\n\/\/ palettes that store 16 distinct entries, but can be accessed AS IF\n\/\/ they actually have 256 entries; this is accomplished by interpolating\n\/\/ between the 16 explicit entries to create fifteen intermediate palette\n\/\/ entries between each pair.\n\/\/\n\/\/ So for example, if you set the first two explicit entries of a compact \n\/\/ palette to Green (0,255,0) and Blue (0,0,255), and then retrieved \n\/\/ the first sixteen entries from the virtual palette (of 256), you'd get\n\/\/ Green, followed by a smooth gradient from green-to-blue, and then Blue.\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Arduino_WS2812B_Color_Palette.ino\" target=\"_blank\">View raw code<\/a><\/p>\n<p>You have to change <em>NUM_LEDS <\/em>variable to the number of LEDs in your LED strip. In our example, the LED strip is 14 LEDs long.<\/p>\n<pre>#define NUM_LEDS 14<\/pre>\n<p>If you want to use another pin of the Arduino to control the LED strip, you need to change the <em>LED_PIN<\/em> variable:<\/p>\n<pre>#define LED_PIN 5<\/pre>\n<h2>Demonstration<\/h2>\n<p>In the end, this is what you&#8217;ll have. Amazing effects like this one:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26738\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/GIF1.gif?resize=480%2C270&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"gif1\" width=\"480\" height=\"270\"><\/p>\n<p>And this one:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26764\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/GIF2.gif?resize=480%2C270&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"gif2\" width=\"480\" height=\"270\"><\/p>\n<p>And&nbsp;this one:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-26796\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/GIF3.gif?resize=480%2C270&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"gif3\" width=\"480\" height=\"270\"><\/p>\n<p>And so on (&#8230;)<\/p>\n<h2>Using an LED Strip Case<\/h2>\n<p><span style=\"font-weight: 400;\">These LED strips usually come with a removable tape, so that you can stick them wherever you want. The problem is that they don&#8217;t stick very well, so c<\/span><span style=\"font-weight: 400;\">hances are that you\u2019ll find your strip in the floor the following&nbsp;day. <\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>The solution<\/strong>: I found this strip case that diffuses the light well and you can screw it to a shelf, for example, if you want a permanent solution.<\/span><\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-27128\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/foto1.png?resize=700%2C386&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"foto1\" width=\"700\" height=\"386\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/foto1.png?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/foto1.png?resize=150%2C83&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/foto1.png?resize=300%2C165&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/foto1.png?resize=80%2C44&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/foto1.png?resize=220%2C121&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/foto1.png?resize=181%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 181w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/foto1.png?resize=272%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 272w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/foto1.png?resize=432%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 432w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<h2>Wrapping Up<\/h2>\n<p>This post is an introduction to the addressable RGB LED strip with the Arduino. We&#8217;ve just experimented with the library example. You should modify the example to only display the effects you want. We hope you&#8217;ve found this guide useful.<\/p>\n<p>If like this post, you may also like:<\/p>\n<ul>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/10-diy-wifi-rgb-led-mood-light-with-esp8266-step-by-step\/\" target=\"_blank\" rel=\"noopener noreferrer\">$10 DIY WiFi RGB LED Mood Light with ESP8266 (Step by Step)<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-rgb-color-picker\/\" target=\"_blank\" rel=\"noopener noreferrer\">ESP8266 RGB Color Picker<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/electronics-basics-how-do-rgb-leds-work\/\" target=\"_blank\" rel=\"noopener noreferrer\">Electronics Basics \u2013 How do RGB LEDs work?<\/a><\/li>\n<\/ul>\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is about the WS2812B LED strip, which is an addressable RGB LED strip. The information in this post also works with other similar LED&nbsp;strips, such as&nbsp;strips of the&nbsp;WS28XX &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Guide for WS2812B Addressable RGB LED Strip with Arduino\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/guide-for-ws2812b-addressable-rgb-led-strip-with-arduino\/#more-26734\" aria-label=\"Read more about Guide for WS2812B Addressable RGB LED Strip with Arduino\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":27132,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[303,267,2,302,269,230,264,274,10],"tags":[],"class_list":["post-26734","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino","category-arduino-project","category-arduino","category-0-guide","category-guide-project","category-guide","category-project","category-rgb-led-strip","category-a-tutorials"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2016\/09\/featured-image.png?fit=700%2C496&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/26734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=26734"}],"version-history":[{"count":1,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/26734\/revisions"}],"predecessor-version":[{"id":130645,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/26734\/revisions\/130645"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/27132"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=26734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=26734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=26734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}