Ultimate Guide to Programming LED Strips with Arduino | Wiring, Powering & Code with FastLED

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone and welcome to this live Workshop where we are going to be ditching these single color LEDs and instead upgrading to a whole strip it kind of knows how projects go in here and it was trying to make its last ditch attempt at escaping but oh no by the end of this I'm going to have you wired we are going to go through some first basic animations that you're going to be able to use as is or even modify to fit your projects this strip is an individually addressable LED strip which means you can individually control every little pixel on the Strip each little pixel has three LEDs in it a red a blue and a green now to connect to an Arduino what I normally do is cut it off and here is my version with it cut off it's got three main lines and then a duplicate of the ground and the power so we're just going to put those away and focus on the three now there are some four- wied ones but I highly recommend the three really easy to connect this particular chipset is the ws2812b we have our white ground our data line this is what connects to the Arduino and it's going to receive information from the Arduino and the red here and that's our power of course now in hooking this up to your Arduino it is super important because both ends kind of look the same so you want to look for this little arrow and that's the direction that the data is going to travel so you want to make sure you connect this end to the Arduino which is going to send the data if you connect it the other way there's going to be a jam up should you get the 5vt or should you get the 12vt the five is the easiest to power and many of you were like ooh we can power it off the Arduino no don't power it off the Arduino now the 12 really the advantage there is that you can do longer runs without so much voltage drop what kind of power supply do you use for Led strips you can certainly use batteries and if you are using the 5vt variety that makes battery operated a whole bunch simpler I actually like just using a wall adapter I have it set on 5 volts because that's what I'm powering if you have a 12vt strip you can just crank this up to 12 volts I have this nice little quick connector which is great for sticking bare wire in it all you do is just squeeze and it opens up the contact and you poke it in just like that and it's pretty secure it's not something that I would use permanently to smooth out any type of spikes that happen with the voltage capacitors have polarity so that is the negative side and the positive side and make sure you match it up and so I have a negative and positive wire and let's see if we can connect it to the strip we have power powering the strip we have ground for the strip and then we have a common ground that unites the power supply strip and Arduino we need to get our resistor on the data line and this is a 470 Ohm resistor getting creative here clamp this together so we have our resistor protecting our data line from any data spikes I'm going to connect this into pin number four so if we can all remember pin number four when you plug in your Arduino and your strip for the very first time don't be alarmed if it doesn't light up it's not supposed to it's getting power that data line is getting no program you didn't write a program for it so it doesn't know what to do time to code some animations there are so many different Arduino libraries that you can use to help program LED strips I personally like the fast LED Library so that's the one that we're going to use in order to install the fast LED Library you can go to sketch and include library now this is not going to be included by default in your Arduino IDE you just go under manage libraries start typing in fast LED see this very first result the fast LED Library I have it installed so let's include it and that is the very first step after we've included our fast LED Library how many pixels are we working with here let's define the number of LEDs so numb leads how many do we have 20 next we need to Define is what pin on the Arduino is that LED strip connected to so the LED pin is pin number four I think that's what it was so next we need to create an array you might have have different sections of the LED strip that you want to animate differently you may have many LED strips so we need to give these things their own unique names I'm going to be super creative and C ours leads LEDs and it needs to know a bit of information how many pixels are in this array you can put a hard number like 20 because that's what it is well since we defined it up top as numb Leeds I rather do it this way in the setup where the code runs one time we can set up a couple additional things that the library needs to make this strip work first bit of information what is the chipset so ours is the ws2812b and you can see it's green it's like I know exactly which one you're talking about which LED pin it's connected to we only have one so the LED pin what is the color order of the LEDs inside each pixel for this particular chipset the order goes green red blue we're going to close that whole statement and now what array does this information pertain to it's going to pertain to our leads array and how many LEDs is in our leads even though we keep telling it several times let's set a brightness from the get-go and I'm going to set mine to 50 this takes any number from 0 to 2 55 now for the Loop this is where the fun action happens let's start animating something well first no let's find out if my color order is correct we want to light up the leads array so which pixel do we want to light up I want to light up pixel Z with arrays that very first pixel is actually pixel zero it's not pixel one I want to light him off red and what I'm using here is a predefined color if you go to the fast LED reference here you can see information about how to set colors and there are numerous ways but if you keep scrolling to the bottom keep going oh you hit some color blocks all these colors are predefined that you can choose from to animate your strip with so I'm still scrolling and there's quite a few of them here for you to choose from here is pixel number two which is actually number one in the array so let's turn this one green let's turn that one blue we told each pixel what color we want them to shine but we never said okay now shine glow and the command for that is fast LED do show red green and blue that means we set our color order correctly why don't we blink that very first pixel our very first animation we are going to turn this red then we're going to show the red how long do we want it to be red for and I'm going to use delays for this so This pauses the program so it's going to show the red for 250 milliseconds and then we want to turn it off we're going to take that very same little first pixel and how do we turn it off well using the predefined colors it's just black and then we are going to show the black and we are also going to keep it off for 250 milliseconds then it will loop back up to the top and start the coat again so this should give us a little blinky effect let's see if it does you can see our very first led here blinking it's not very exciting why don't we try and move him along the strip and then move them back like a sylon or Night Rider you're going to see four Loops a lot with LED strip lighting because it's a great way to do a repetitive thing many times with minimum lines of code so the repetitive thing is just moving it to different positions for Loops take a couple parameters we need a starting position normally we like to set all of our variables up here I figured we'd do something a little bit different today and declare it right as we need it so pixel position and we're going to start it at position zero what is the condition that it must meet in order for this repetition to happen so long as the pixel position is less than the number of LEDs then what do we want to happen we want pixel position to increase by one I made up the name pixel position but because I know you guys are going to be looking at code online instead of pixel position what you're probably going to see the most is the letter i anytime you want to do a quick iteration writing code is about keeping things as short as possible so often time you'll see just single letter variables the most common ones being i k and l l is like extra evil if you look at it does it not look like a one have fun troubleshooting that that is just evil don't use the L after we're out of this function I can be reused for something else so it's it's one of the advantages of declaring it locally versus globally up here so how do we then show the light we do LEDs our array and here we were putting a number but now we're putting I because I is going to just change every time we loop around this and what color do we want to do I'm going to stick with red because it is like so sylon and Night Rider now that we specified the color show me that color and then turn it black so the only thing we didn't specify is how long do we want this pixel to remain we'll do 50 milliseconds to remain lit this pixel has traveled all the way to the end why don't we make it travel back to the beginning we're just going to reverse here what we did and we are going to set up another variable integer because once this is out of this this no longer exists it could be reused for something else so let's reuse it for kind of the same thing and now we're going to start it where we're going to started at the top but we have to remember that numb Leeds is 20 we don't have a position 20 we have a position 19 so I'm going to go numb Leeds minus one which will give us the 19 so long as the position is greater or equal to zero then what do we want to to do we want to subtract subtract those positions and here we're going to take our LEDs array and we are going to color it red and we are going to show it and at the same rate like you can have it go up one speed and then fast down another speed the LED in this statement here is going to go from position 0 to position 19 then here it's going to go from position 19 back to position zero and then keep repeating the whole thing until we just turn it off everybody give it side eye grimaces at this code oh here instead of a comma it's got to be a semicolon that thing's moving so this is at 50 milliseconds instead of turning the LED off why don't we keep it on let's move this a little faster faster at 50 every 50 milliseconds it's going to move up the strip but the preceding lights are not going to be turned off so it's going to leave a tail of red until it gets to position 19 and why don't we say when it comes back down it colors a different color let's do something that really stands out green so it's now going to start at position 19 work its way to position zero coloring it green and we're not going to turn off off the ones that move along covering the red LEDs with green now I see this in my head so now let's send another color let's do blue what we've done is red green blue now let's send it back down maybe we'll do a yellow all right red green blue yellow yes guys but what if you just want to light the strip of color fast LED also has another cool function and it's called fill solid first bit of information that it needs is what array are we filling solid well that's the leads array and how many pixels do we want to fill solid in that array all of them and what color do we want to light it so crgb can't talk and write crgb at the same time why don't we fill it red like that and then show me my red filled delicious LED strip and how long do we want to show it for we can show it for like a second let's fill the whole thing with another color aqua looks kind of neat we can pretty much just copy and paste and then finally let's pick a third one yellow we're cycling through these solid colors that we picked from red to Aqua aqua and then yellow and then back the f solids are nice it's a great way to get bright bold color but what if you want something more nuanced like a gradient of colors there is a function for that as well and it's called fill gradient very tricky there but the only thing is you have to add this RGB at the end similarly to the fill solid what array do you want to affect leads number of LEDs in that array that you want to work with and let's start picking some colors now the interesting thing about this function is that you can pick two colors four colors but do not pick three there is a weird little bug it freaks out it freezes let's fade from magenta to GP yellow and let's have it show for one one second I'm going to go ahead and just copy and paste this make our life easy or not that's when all the problems start happening is when you start copying and pasting so let's try and add four here four is a little much for 20 pixels something like real different than yellow maybe like red and then blue that'll show up like a nice contrast these are two colors and then the four colors you know what I stand corrected the four colors do look nice on this strip so you can experiment and you can see how nicely one color blends into the other color there is a fil rainbow fill rainbow and the syntax is very much similar to what we've been using the name of the array the number of LEDs in that array and now the starting color this specific function does not take that it takes instead a hue color a hue number and for that we're going to go back to our pixel reference we have this cool little Hue chart here and if you look closely zero corresponds to red and it goes all the way up to 255 well rainbows traditionally start with red so why don't we start with number zero we're going to make it zero then what's the color change Delta like how do you want this color to change or progress through the rainbow for your strip we want to fit the whole rainbow so how can we accomplish this well we know that there are 255 Hue values so why don't we divide that by our num leads we have 20 pixels so divide that 255 over our strip we have red it goes through the colors of the rainbow and ends in our Violet right before it would cycle back to Red we got to animate these rainbows because I mean you guys have been so awesome because we are working with numerical values just like we did for the for Loop we can now iterate through these values unlike the predefined colors why don't we change the starting Hue every so often so then the colors will keep adding and adding and adding and then colors that get to Violet will cycle back to red and start it again why don't we make a variable here like the start Hue maybe a new variable that you guys haven't seen before or a variable type uent 8core T this is an unsigned 8bit integer it can house any number or value from 0 to 255 which is magically kind of what the Hues are and because that's all it can house once it hits 255 it'll cycle back to zero for us we're going to call it start Hue because I think that's what we had at the bottom and let's start it at zero at the red color let's move the animation pretty quickly here and then we're going to take our start Hue and add one to it remember that plus plus the start hue is going to start at zero and divide the colors of the rainbow starting from zero on the Strip then it's going to add one to it and so it's going to come back up here this is going to be one which means that first pixel is going to be like off red and then it's going to divide that along the strip so you'll see the color of the strip is going to change because that very first pixel is going to cycle from Red all the way up to Violet and then back to red and that's going to affect how the other colors are laid out on the strip and they too will change it's already on Blue every 50 milliseconds this starting color keeps increasing and therefore the Delta that we created spreads across in a different way why don't we try 10 you get these undulations of colors going down the strip why don't we animate the Delta Hue I'll create a variable called Delta Hue and why don't we Define it up here so u in 8core t Delta q and why don't we start that at 02 every go around that first pixel is going to start at one Hue higher which causes the spread to be different why don't we also increase the spread every time see what that looks like sometimes you got to play around it's tough to sometimes Envision what it'll look like this looks like all all glittery and then there is a point where it flashes red real quick because both the Delta Hue and the starting Hue are zero and then it starts all over again just by using fast LEDs basic functions you can already create a lot of cool effects I always have a constantly updated written tutorial on the website link for that will be below and I invite you guys to join my community every week we have Live Events like these live workshops where you can interact in real time as well as our community build sessions where we get together via Zoom bust out our projects get to that completion unlike a lot of the projects I got going on here which are like half done so yeah they need a couple more Community build sessions so I had a great time tonight guys bye
Info
Channel: Rachel De Barros
Views: 13,004
Rating: undefined out of 5
Keywords:
Id: zj3sa5HV2Bg
Channel Id: undefined
Length: 21min 22sec (1282 seconds)
Published: Fri Apr 19 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.