empowering creative people

Videos / How to use WS2812B RGB LEDs with Arduino

This tutorial is aimed at getting some instant gratification from your WS2812 LEDs (trade name: NeoPixels). I'll briefly cover a bare-bones setup for Arduino.

Search Videos

Related Content



G'day, in this tutorial I'll show you how to get an example piece of code running to power your length of WS2812 the LED strips also known as in NeoPixels. Let's get started.

Okay so the first thing we need to do is wire up our Arduino just as it shows in the picture for this tutorial, so I don't have a DC barrel Jack adapter to some wires, what I have instead is a lab power supply but the result is just a red and a black wire that's going to power the LED strip. So these two connectors that I bring in here you can think of as the red and black leads coming off the power supply because that's all this is. So with my black lead I'll connect it to the to the white fly lead that's coming off the strip that's the ground and with the red lead I'll obviously connect that to the red on the strip. So these fly leads that are on the strip additionally to the plug, just allow you a convenient way to connect power connections, you can power the strip through the connector as well but if you need a little more current or you're doing something like what I'm doing on the bench it's convenient to use these ones, I'll just hold that down with some blue tack I think, here we go just to make sure we don't get any any leads flying away just like that one.

Okay so with our strip coward I just need to connect this signal wire and this black wire, this red one isn't necessary because I'm going to be powering my Arduino from usb this was just splitting off power to power the Arduino so I'll start by connecting the black ground lead, which again connects to the white, this time I'll just use a jumper and plug it straight into this plug that's on the lead that's nice and convenient, and if you were wondering yes of course these two white leads are connected together. And then the yellow which is our data signal goes from Pin 6, so I'll grab the digital six with my yellow lead and connect that to the center connection, which is the the data input for the strip. So you'll notice that there were the would be a 3rd connection into that plug which is the power to power the Arduino but of course I've omitted that for you because I'm powering by USB.

So because I'm pretty confident that's all wired up with no errors I'm going to plug in my Arduino, and enable my power supply. So now we have to open up Arduino, it's go to my downloads folder and open up Arduino, see here we are with an empty Arduino sketch and what we're going to do is first we have to download the NeoPixel library so we can go to sketch and include library and this is where we get the option to manage libraries, if you already have a Adafruit NeoPixel library showing here you won't need to follow this step but by opening up manage libraries I'm just going to waive that to enumerate and then in the filter I'm going to type neopixel and we can see the second result here is Adafruit NeoPixel by Adafruit so click on that and click install and that should happen really quickly and if I close that library manager I should now be able to go to file>examples and down the bottom we have Adafruit Neopixel so I can just open up the thing it's the Strand test that I want to open I think that's the one that I've used to you, yep.

So this is the Strand test this is already wired up to my straight away with strand test so let's just hit the upload button a way that goes and that's uploading and there's our instant gratification. We have the LED strip working on the table running that that cool strand test script, now if you if you didn't have a successful upload you may just have to check under tools that your board is selected correctly I'm using a Arduino Uno r3 today, so I've just selected Arduino Uno and that you have selected a valid COM port, and now just a bit of a muck around I've just scrolled to the top of the script so you can follow along if we scroll down past the setup routine into the loop routine this is where all the action happens and if you just really want to focus on one of the demos and learn how that works then you can click drag and comment the entire block so you can just click comment and I'm just going to focus on the rainbow so I'm going to comment out this is well I'm just going to comment that out so the only thing that we really have is the rainbow acting and if we upload that sketch now that will be the only demo that runs on the strip.

That's finished uploading so now you can see that we have just this this scrolling rainbow effect that goes all the way along the strip I'm not using the whole strip here that's easily changed by a single parameter just at the top of the sketch which is this first parameter which is the number of pixels in the strip. So when we go down to this line adafruit neopixel strip this 60 is the number of pixels that are going to be used if you want to run your whole roll you can just count up the number of LEDs you've got and change that number to suit if you set it to 5 only the first 5 pixels on the strip will work and there you go, just a quick start guide to get some instant gratification with some ws2812B or neopixel leds I'll see you next time.