BEGINNERS Guide to Individually Addressable RGB LED Programming with Arduino

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Blog version if you prefer to read instead of watching a video: http://www.thesmarthomehookup.com/beginners-guide-to-individually-addressable-rgb-led-strips/

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/DarkbunnySC πŸ“…οΈŽ︎ Sep 05 2018 πŸ—«︎ replies

The author really needs to indent his code.

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/Xarian0 πŸ“…οΈŽ︎ Sep 05 2018 πŸ—«︎ replies

fwiw - last year I did an Arduino project called LedString (github link) that uses FastLed to control WS2811 leds in a Christmas Town display (those little buildings you see at the Dollar Store - my wife collects them). You can make individual lights be always on, always off, on and off at semi-random times to give the impression of inhabitation, or a flickering fireplace effect. You can also add custom effects. I'm kind of proud of the fire effect - it's realistic looking, non-repetitive, and all fires flicker independently.

A control program using my library only takes about 10 lines of code, using a simple character string to indicate which effect you want for which light. I only wish I could find an led string with the leds physically farther apart, say 8 inches.

πŸ‘οΈŽ︎ 1 πŸ‘€οΈŽ︎ u/DougLeary πŸ“…οΈŽ︎ Sep 05 2018 πŸ—«︎ replies
Captions
today on the hookup we're gonna learn about individually addressable RGB LEDs and how to control them with a microcontroller like the esp8266 based node MCU RGV LEDs are super cool and fun and flashy and sometimes a bit tacky but they can actually be really useful too in this video I'm gonna cover the basics of writing programs for individually addressable RGB LEDs by programming a simple timer for my high school classroom the goal for this timer will be to count down from any custom time and gradually change color from green to yellow to red as the timer gets closer to zero I'll use this timer in my classroom to keep track of how much time is left in the period but the concepts that I'm going to talk about are applicable to any individually addressable RGB project RGB LED strips come in hundreds of shapes sizes and configurations but they can be broken into two major categories there's three Channel RGB strips and individually addressable RGB strips a three channel strip has three different ground circuits in one common voltage each different ground circuit controls a different color of light red green or blue by changing the resistance on those channels you can change the brightness of each Channel which allows you to produce a huge range of resulting colors the major downside to these strips is that you can't pick and choose which LEDs are lit the entire strip must be on or off in every LED will be the same color so you can't do any of the really cool effects with them by contrast individually addressable LEDs have a tiny microcontroller in each of the LEDs that allows each one to light up with a unique color and brightness the strip's have a positive voltage a ground and a data wire each time the data reaches an LED it's red and passed down the strip to the next LED the first chip reads the incoming message address as LED 0 and then performs the instructions for LED 0 it also passes the data on to the next chip after increasing the counter value by 1 in other words the first LED says ok I'm LED 0 the next guy who gets this message is LED 1 and this message continues down the strip until there's no more LEDs left the important thing for you to know here is that each LED in the strip needs to be given specific instructions with that specific address in order to turn on individually addressable RGB LED strips come in five volts and 12 volts and each strip has some unique advantages the 12-volt strips are less susceptible to voltage drop and are therefore able to travel longer distances before the LEDs become dim and the colors become inaccurate if you're planning on running your strip's any significant distance you'll probably want to inject power on each end of the strip at the very least and probably somewhere in the middle as well if you're using the 5 volt variety the upside to using a 5 volt strip is that you'll be able to power the whole thing from the same power source so you won't need a buck converter or some other voltage regulator for your node MCU for our project today I'm going to be using a 5 volt ws2812 B LED strip because I'm not worried about voltage drop since my project is only gonna have around 60 LEDs 57 to be exact in the arduino ide we're gonna use a very popular library for controlling these leds called fast LED to get started with your project you need to setup your LED strip in the sketch to do this you'll need to do three different things first you'll need to define how many LEDs you're gonna have in your strip this refers to the number of individually controllable nodes so if you bought one of those LED strips that only has one controller for every three LEDs you'll need to divide the total number of LEDs on your strip by three for our ws2812 B LEDs each led can be controlled individually so my 57 LEDs needs to be declared as 57 controllable nodes second you'll need to declare your LED matrix to do this you'll type C RGB and then give a name to your LED strip and then tell it how many LEDs are in that array using the variable that you define in step 1/3 you'll need to setup your LED strip in the void setup by using the fast LED add LEDs function you'll tell it the type of LED strip you're using the data pan that's connected to the order in which the red green and blue LEDs are addressed the name of the LED matrix and the number of LEDs it has that's a lot of information once you have your LED strips set up you can tell a specific LED to turn on at a specific color by calling the name of the LED strip and then the LED number that you want to light in the square brackets and then equals and then the color you want when selecting in color you a few different options the first one is classic RGB in this configuration you can turn on each of the red green and blue channels to 255 levels of brightness using this method you can generate around sixteen point eight million unique colors but the downside is that you need to manipulate three variables in order to change the color another option that allows us to manipulate the color while only changing one variable is called HSV or hue saturation and value hue refers to the base color zero is red and then all the other colors in the spectrum are represented as you go all the way back up to red again at 255 saturation refers to the vibrance of the color if you choose a saturation of zero there won't be any color just white light and 255 would be the richest or most saturated color the last value which is value is essentially just the brightness of the leds if it's your first time working with these strips I highly recommend that you compile and upload your project after making a single LED light up as a custom color I know that the first time I got my strip working I was beyond excited and it really helped me push through some of the issues that I ran into you later on in the project for my specific project I'm making a timer that transitions from green to yellow to red so you can see that I need to go from a hue value of about 96 down to a value of zero and I can keep my saturation and value numbers constant and that's nice because it means I only need to work with a single variable the trigger for my timer is going to be an MQTT message I always use the same code to receive my MQTT values and you can see that after receiving a new payload it converts the payload into both a string and an INT in separate variables so that I can decide which data type I want to use for my specific function I use home assistant and node-red for my home automation so I already had an easy way to send an mqtt message but if you don't already have an MQTT server setup you can easily just use IOA to fruit comm which offers a really nice web interface and it has IFFT integration without the need to run a separate Raspberry Pi at home once a new mqtt message comes in my code is going to do a few things the first thing we need to do is reset our LEDs remaining to the total number of LEDs in the string that's going to result in the bar filling all the way back up then we need to calculate how often an LED needs to disappear this calculation is pretty simple we just need to take the total number of minutes for the timer and then divide it by the total number of LEDs in the strip which will give us the fraction of a minute that each LED represents since the simple timer library in Arduino wants an input of milliseconds we'll also need to multiply this by 60,000 in order to convert the minutes to milliseconds we'll then use this number of seconds to tell our program how often it should subtract an LED from the LEDs remaining variable in the simplest situation if we had 60 LEDs total in our strip and we set our timer for one minute each LED would only last for one second to actually light up our LEDs we could type in each LEDs specific address in the matrix and tell it which color to turn that would take forever and it's way more work than we need to do instead of doing that we're gonna light them up using a for loop basically in a for loop you declare some variable I in this case and then you give it a condition that has to be true for the loop to continue which means this loop will continue as long as the variable I is less than my LEDs remaining variable and then last you need to tell it what to do every time the loop completes in this specific loop I have I plus plus which just means to add a value of one to the previous value of I every time the loop finishes you can see that each time the loop runs it will turn on a different LED based on the value of that variable I if the LEDs remaining variable is equal to 25 the for loop will run 25 times and turn on LEDs zero through 24 if my LED is remaining variable is equal to 8 it will run eight times and turn on LEDs 0 through 7 the last piece of the puzzle is color-changing as I mentioned before I'm gonna manipulate the hue value of my HSV color when the timer is full I want it to be at a value of around 96 and when it's empty I want it to be at a value of 0 but since I only have 57 LEDs I can't use my LEDs remaining variable because that would only go up to 57 instead I'm gonna use the map function for Arduino this compares two number ranges and results in the equivalent position on a number line for those two ranges I'll be changing my value from 0 to 57 to a range of 0 to 96 in order to adjust for my color there's a few other little lines of code in here to allow me to cancel a previous timer before inputting a new one but overall the code should be pretty easy for you to come through and figure out what's going on and modify it as needed here's what the timer looks like in action we can set the timer to one minute and then as the LEDs start to disappear we could send a different timer for say 5 minutes and overwrite the previous one and since no IOT project would be complete without voice control I can also say Alexis in my classroom time 2:10 and it will start a 10-minute timer for us I hope this video will be helpful for you in making your own RGB LED projects if you'd like to build this exact same project I've put the links down in the description for the specific products that I used I'd also like to hear in the comments if you prefer videos where I just build a project and then I leave the code in the description or if you'd rather see videos like this one where I explain how the code actually works as we get closer to Halloween and Christmas I'm gonna be making some more videos about my house LED projects then for brah Automation made a really good video about RGB LEDs that focuses on using pre-made animations so I'm going to look at different things like using separate LED arrays for different parts of the house and custom tailoring your LED arrays for the specific features of your house so that you can have animations that are custom to your house only thank you again to my awesome patrons from patreon for your continued support of my channel in my projects I only have these video ideas planned out around two weeks in advance so if you have an idea for a unique video that you'd love to see me make let me know down in the comments and if it sounds exciting and it hasn't already been done well on YouTube there's a good chance that I'll make it if you'd like to support my channel check out the links in the description if you enjoyed this video and you'd like to see more like it please consider subscribing and as always thanks for watching the hook-up [Music]
Info
Channel: The Hook Up
Views: 185,477
Rating: 4.9326854 out of 5
Keywords: home assistant, hassio, home automation, hass.io, smart home, diy, electronics, arduino, esp8266, nodemcu, wemos d1, automation, bruh, bruh automation, fastled, ws2812b, ws2812, ws2811, individually addressable, rgb, led, programming, classroom, timer, mqtt, adafruit, io.adafruit
Id: WS6FI_NyRzs
Channel Id: undefined
Length: 12min 25sec (745 seconds)
Published: Wed Sep 05 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.