When we're working with LEDs, we often like to control their state (on/off), brightness, and color. There are many, many different ways of going about this, but none are as compact a solution as the WS2812 RGB LED. In its tiny 5mm x 5mm package, the WS2812 includes 3 super bright LEDs (Red, Green, and Blue) and a compact driver circuit (WS2811) that only requires one data input to control the state, brightness, and color of the 3 LEDs.

At the expense of needing only one data line to control 3 LEDs, there comes a demand for highly precise timing in the communication with the WS2811. For this reason, a real-time microcontroller (e.g., AVR, Arduino, PIC) is required. Sadly, a Linux-based microcomputer or an interpreted microcontroller such as the Netduino or Basic Stamp cannot provide the sufficient timing accuracy that is needed. And so, in this Instructable I walk through the process of setting up, and controlling one of these LEDs with an Arduino Uno. Then, I show how easy it is to connect several of them together for an awesome lighting display!

Difficulty level: Beginner
Time to completion: 10-15 Minutes

Step 1: List of materials

This wonderful RGB LED comes in a 5050 (5mm x 5mm) package with 6 pads that are fairly easy to solder onto a breakout board. As the only additional component needed is a de-coupling capacitor, the WS2812 honestly offers the best solution for controlling color and brightness of an RGB LED. The embedded constant-current LED driver (WS2811) is remarkably useful for two reasons:
- A constant current of ~18mA will drive each LED even if the voltage varies.
- There is no need to add current-limiting resistors (a.k.a choke resistors) between the power supply and the LEDs.

All we need is a very simple design to provide Power, Ground, and 1 Control Input in order to create an awesome lighting display consisting of not one, but a whole array of RGB LEDs. That's right! By connecting the Data Out pin of one of these LEDs, to the Data In pin of another, we can drive them both independently with the same Control Input! If it's not obvious how to do this, do not be troubled, by the end of this Instructable you'll be well on your way to adding WS2812 to any project you want!

For this Instructable here's a what we'll be using:

3 x WS2812 RGB LEDs (pre-soldered onto a tiny breakout board)
1 x Solderless Breadboard
Solid Core Wire (assorted colors; 28 AWG)
1 x Arduino Uno R3
1 x Break-away Pin Connector, 0.1" Pitch, 8-Pin Male (Right-Angle)
1 x Pin Connector, 0.1" Pitch, 8-Pin Female (Right-Angle)
1 x Breakaway Pin Connector, 0.1" Pitch, 8-Pin Male

USB A/B Cable
Wire Stripper
Soldering Iron

Depending on your project, the WS2812 RGB LEDs are also available without a breakout board for about $0.40 each, but the convenience of the pre-soldered option is attractive for simple applications.

<p>I cant understand this part of code:<br>void sendLEDs()</p><p>{</p><p> cli(); // what this funcion do?</p><p> for (byte i=0; i&lt;NUM_LEDS; ++i) {</p><p> ws2811.send();</p><p> }</p><p> sei();// what this funcion do?</p><p>}</p>
<p>/*</p><p><a href="http://playground.arduino.cc/Main/AVR" rel="nofollow">http://playground.arduino.cc/Main/AVR</a></p><p>*/</p><p><br>To disable interrupts:</p><p><br> cli(); // disable global interrupts</p><p>and to enable them: </p><p> <br> sei(); // enable interrupts<br></p>
<p>try the skecth<br>https://codebender.cc/sketch:314189</p>
<p>I don't have the modules, I have the component separately and I see that there is a capacitor in the module (I think in between the power and ground). What value is it, if I'm to make a module something like that? Is there any other component you'd suggest adding to the module?</p><p>Thanks.</p>
Hey! Thanks for the question. Yup, the only additional component is a capacitor. As we're only driving a few LED modules, 0.1uF is ok. The more modules you drive, the bigger power supply you'll need, so additional capacitor values may be necessary (bigger power supplies are often 'dirtier').<br><br>The only other component we'd suggest is a small resistor (100~300Ohm) on the DI line to prevent onrushing current to burn out the innards of the module.<br><br>Thanks for checking out our Instructable!
Thank you very much for your help ?
<p>good job</p>
<p>Is there a limit to the number of LEDs you can control using this method? I'm looking at using as much as 30 meters of LED strips in one continuous circuit. As long as I provide enough power to the strip, this controller circuit should still work the same right?</p>
<p>Yup, it should handle 30 meters without problem as long as you source enough power! Good luck with the project!</p>
Adafruit has has instructions for using these LEDs on a Netduino, although it involves replacing the firmware: <a href="http://learn.adafruit.com/using-neopixels-with-netduino/overview" rel="nofollow">http://learn.adafruit.com/using-neopixels-with-netduino/overview</a><br> <br> BTW, you can get them for much cheeper if you buy them in strips which can be cut to size. It also simplifies the wiring for some uses. &nbsp;These are about 50 cents per pixel (same LED but the site calls them NeoPixels): <a href="http://www.adafruit.com/products/1461" rel="nofollow">http://www.adafruit.com/products/1461</a><br> <br> Great instructible!
Thanks for the compliment! I completely agree that the strips are a much cheaper option (we also have them in stock now (:-):<br> <br> <a href="http://blog.acrobotic.com/post/announcing-rgb-led-strips" rel="nofollow">http://blog.acrobotic.com/post/announcing-rgb-led-strips </a><br> <br> However, sometimes people want a thick PCB rather than the flexible one used in the strips. This is especially useful if you're using a breadboard. Either way, we want you to have as many options as possible, so thanks for pointing it out, and for checking out the Instructable!
link ded
<p>Thanks for letting us know! Check out the direct link to the category page:</p><p><a href="https://acrobotic.com/categories/neopixels" rel="nofollow">https://acrobotic.com/categories/neopixels</a></p><p>Hope you found this Instructable useful!</p>
<p>In your modified code, you might want to change line 33 of the ino file (for-loop) to allow for more than three LEDs, easy since you defined them above :-)</p>
<p>Thanks for the bug report! I also fixed the color separation so that we get an even spread across the range (val = (val + 255/NUM_PIXELS) % 255;). Cheers!</p>
<p>I downloaded the fade, from step 6 (Which is great by the way!) but have the LED strip from you guys, (60) and I'm wondering if the code can be altered to run the fade across all 60 LEDS?</p>
<p>Thanks! Sorry for the late reply. I've made changes to the code (as pointed out by @ronix_de) so that you can do as many LEDs as you want. I also corrected a bug in the color-step spacing so that you always get an even distribution of colors across all LEDs.</p>
The link to your Ardunio Uno is dead... :(
Hi, there! Thanks so much for letting us know. We've recently upgraded the site so some URLs moved around a bit. It is all fixed now, thanks again!

About This Instructable




Bio: Designing fun, unique, and Open-Source electronic kits for education, DIY, hobby, art, science, and more. For the tinkerer in all of us!
More by acrobotic:Get Started with ESP8266 Using AT Commands, NodeMCU, or Arduino (ESP-12E)Raspberry Pi  Bluetooth LE Controller for WS2812B (NeoPixels)Control Bluetooth LE Devices From A Raspberry Pi
Add instructable to: