LESSON 13: Controlling an RGB LED with Arduino

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is polemic order from top tech boy comm and we are here with Arduino tutorial number 13 hopefully you've been with us through the first 12 as we try to each lesson build a little bit on what we learned in the previous ones and today in Lesson number 13 we're going to be learning how to control an RGB LED okay if you think about some of our earlier lessons we learned how to control a simple LED like let's say a red LED and we learned that we could control its brightness by doing analog rights and we could also blink it on and off off by controlling delay times and so we played around quite a bit and we learned a lot about programming and circuits with our simple LEDs well today we're going to kind of take it to the next level and what we're going to do is we're going to look at this new component called an RGB LED now what I'm trying to do is I go through these tutorials is I'm trying to sort of go through one and learn a little bit about programming and then go through another one and learn a little bit more about circuits and we're sort of kind of learning circuits and programming at the same time well today I don't think we're really going to learn any new programming but we are going to learn about a new component and the component that we're going to learn about is the RGB LED now the thing about an RGB LED is is that you can turn it red you can turn it green or you can turn it blue the really cool thing is is that you can turn it all the in-between colors and we'll talk a little bit more about the in-between colors towards the last part of the video but for right now what we're going to do is we're going to be focusing on these three primary colors now in a simple LED you had two connections you had the control pin and then you had the ground well on the RGB LED you have four connections and the specific type of RGB LED that we're going to be talking about is the common cathode and what the common cathode LED is basically all of these three colors red green and blue they all share a common cathode or a common ground I tell you that because there's also common a node LEDs and what they do is they share a common High Line and each one comes out with its own separate ground I think those are much more confusing to work with and I really don't like them the only reason that I mention them is is that if you just go get an RGB LED out of a supply cabinet you need to make sure that it's a common cathode one for this tutorial to apply if you purchase the sparked fund and dinner kit the LEDs that come in the spark inventor kit are indeed the preferred common cathode LEDs and so I just say that so that you know that make sure that you're using a common cathode one so how does this work well you have four pins on this LED you have a ground that ground is common to the grid the green and the blue LED components they're sort of how you connect them up they're kind of coded by the length of the wires or the length of the leads the long lead is the ground okay if you have it oriented towards like this right to the left of the long ground is the shortest pin which is the red it's you've got the red control pin here you've got the ground and then you sort of go green and blue okay so our G B okay so look at that it's kind of good to lay your LED out because you really got to make sure that you keep it oriented the way that I'm doing it when I go through this video now what I've done is I have taken this our G be our ground green blue and I have moved it over and plugged it in like this into the into the breadboard now normally I just let you at this point you've got enough experience just to hook these things up but this one is a new component so I want to sort of take you through it a little bit more step-by-step so if you think about it when you were working with a simple LED how many control pins did you need on the Arduino you needed one well now we're going to be controlling three different colors so how many control pens are you going to need now yeah you're going to need three all right what's something else that we learned about LEDs you never hook an LED directly up to a control voltage you always run it through a what a current limiting resistor when we were just controlling one color we needed one current limiting resistor in controlling three colors we need what three current limiting resistors so each one of these colors needs its own series current limiting resistor so in your circuits are going to have three current limiting resistors instead of one so let's look at it this is the ground pin the second one over we come over here to the ground pin that needs to connect to ground we come up to our ground rail okay how do we make this the ground rail will we bring the ground from the Arduino so ground from the Arduino comes establishes this row as a ground rail and then we come off of that ground rail over to the second pin which corresponds to the ground okay now let's start hooking up the colors let's start with blue okay blue is over here to the right and I like to kind of color code my wires sometimes because that makes it easier that this blue pin on the LED I'm going to run blue wires to indicate that that comes over here to this current low resistor go through the current limiting resistor to pin six you could use a different pin but just make sure it's one of the ones with a squiggly line okay because we're going to want to do analog writes now the next pin over is green this is your green pin we connect green to its own current limiting resistor comes over goes up to pin 10 red comes over goes up to pin 11 the main thing is not to end up with these different legs in the same column okay so this resistor needs to have its own column to come up to pin 10 you shouldn't put this resistor in this resistor in the same column otherwise you've got them hooked up in parallel and you're not really getting the 330 ohms across that leg of the circuit like you want okay so blue is controlled by ten six through this LED I mean through this resistor coming to this blue pin okay then green right through this resistor up to pin ten and in red through this resistor up to pin 11 so hopefully that makes sense hopefully you sort of see what we're doing is kind of like cooking up three separate ones but they're all sort of three in one they are three and one okay so now with that and we need to kind of think about starting to set up our code okay we've got to set up our codes so that we can get this thing get this thing running so I need to call up an Arduino control environment all right and I need to start writing the code so what do we do up at the 12 we declare our variables so how many variables are we going to need well let's kind of think about our variables well first of all how many pins are we going to control we're going to control three so how many pin variables do we need we're going to need three and so what I'm going to do is we declare our pin variables since it's so I'm going to need a what I'm going to need a red and okay the red pen is going to be what let's go back and look and remind ourselves what that red pen is going to be to go back and look that red pin is going to be 1011 okay so red pin is going to be 11 and we're going to be good boys and girls we're going to declare it we're going to always comment our code so set red LED 10 to 11 okay we'll swing you green pin and green pen and you you can do this different ways but you just got to make sure they match you know make sure that you're getting these things to match so let's go back to this schematic the green pin goes up through this and goes to pin ten so we're going to set this green pen Iike pin 10 always put our comment in set green LED 10:00 to 10:00 okay okay what else do we need well we got a blue hint and that is going to be 10 6 on the Arduino set blue LED to 6 all right the only other thing that I think is is that I don't know if I want to turn these colors on full blast because the LED is pretty bright and it might be easier for you to see it on the camera if I toned it down a little bit so I'm going to have a variable that I'm going to call brightness and I'm going to set that to as an integer I'm going to make it an integer okay and what I'm going to do is I'm going to set it so it's not full brightness full brightness would be 255 that would be writing a 255 - it would be putting a full 5 volts on it I want something more like a you know more like a volt or so so it's not so bright so I'm going to set it to about 75 and then this is set brightness to 75 so that way I think you'll be able to see a little better right now what do we need to do in our void setup well I always turn the serial monitor on whether I'm going to use it or not because if there's a problem in the code we'll want to go in and we'll want to look at numbers and stuff and so for debugging it's always good to turn on a serial port okay what else do we need to do in our void setup what are we still in our void setup we do our ten modes let's set our pin modes so pen mode what's our first pin red 10 we're going to set that to what and because we're writing to it set read 1080p and output okay and mode what's the next pin green and and it's a what it's an output so far most of our stuffs have been outputs but remember when we did the potentiometry reading off of potentiometer the pins were input so we have done input pins before set green n2 TV and output okay and then we have one more pen mode remember these things about to turn orange because you go pin mode with a uppercase M in that you got to get the case just right we're going to do blue 10 and blue pen is going to be an output okay and then we're going to set blue n to be and out okay so those are our pin modes and we turn to our serial port on so I think that looks good now what do we do to get this thing to turn on we need to do some analog writes and odd I think I would like to turn the LED blue okay well if we do if we want it to be blue we need to write to all of the pins so that nothing is is happening that we don't know so analog right we're going to write read and what we going to want to write red pen to write want to write at zero because I want it to be blue I don't want any red getting into my blue LED so I want to set the red component to zero okay turn off red pen I don't want anything on my rig and I want it to be zero okay analog right how about green pin well I want that to be I don't want any green in my blue so I'm going to set that to zero okay turn off ring what do I want to write analog analog right I want blue pen and I want to set that to 255 right no no no you never write a constant down here you always use variables and we use our heart our brightness variable which we didn't want 255 anyway we wanted 75 because we don't want to be taught to write so we're going to say write 75 to blue pen so this is giving a little bit of a voltage 75 over 255 would be what the voltage would be a little bit of a voltage i times 5 would be a little bit of a voltage that we're going to put on blue pin and the red and the green are going to be 0 and so when we hit this let's see here I need to come over here and get this circuit where you can see it okay let's bring this over here where you can see it take a second to get this set up okay I just think this is going to work real well I need to knock off on my zoom a little bit so that you can see it Oh okay so you see this is my LED and then this circuit should be if I haven't made any mistakes it should be this circuit that we've this circuit that we got the schematic here should be the circuit that I've set up there then I've got some code and the code is going to turn to red pin off it's going to turn the green pin off but the blue pin of the LED I'm going to send a little bit of a signal to so we would expect this to light up blue if we haven't made a mistake but I have been known to make mistakes so let's download it we're getting lots of green that looks good it looks like everybody's happy and look down here this thing just turned blue okay and when I'm looking at it I can see it just the nicest prettiest blue but it looks like when you're looking at it there that you see more like white so I need to turn this down let's make it like 30 or something like that maybe if I turn it down you can see more clearly in the camera it's just it's so bright it's saturating the camera okay that's still let's see if I turn it what if I kind of point it over end it over a little bit okay I think maybe there you can see a little bit better that that's blue that blue still looks like it's kind of saturating the camera let's make take it down to 15 now with your eye you can turn it up bright and you can just see a beautiful blue color but to get the camera to to pick it up I'm having to kind of turn it down that looks pretty good let's see if I turn a lot off if you can kind of see it yeah you see we've got a nice pretty blue LED there with a lot off okay I apologize the camera doesn't show it up ever but there you can see that it's that it's a nice pretty blue okay well let's say that we wanted to turn it red what would we do well we would come in and do I want any blue in my red no I don't want any blue in my red so I'm going to turn the blue pin I'm going to analog I'm going to analog the right the blue pin to zero and I would need to take the red pen to write this okay and the brightness is 15 so this is just a very small voltage that I'm putting on there I'm barely turning it on so that you can see it nice and good on the camera okay you can see that that turned red read maybe we can take up a little bit let's take it up to 50 and see if you can still see it so we're still on the red pen and we're turning brightness up to 50 okay that looks that looks pretty good that looks pretty good I'll try to turn it back up like that that's just really when we try one thing on this camera see if I could set it a little bit better there let me try one more time there okay I really wish let's see if I take that off I really wish that you could see the colors are better because they really are just spectacular bright red color but on this darn camera it's just kind of saturating out and it's looking on it's looking quite okay I'm going to go see if I can take it to 150 make it brighter okay you can tell that that's red down here especially you can see that it's red okay well what if we want to make it green well we would come here and we would write to brightness okay and then we would turn we would analog right red pen to zero and we would analog right green pit and brightness and so let's see that should take this to green Green kid waiting for it it's a little slow to download today did not go down try it again I'm just having the darndest time with this with this cable that I have and it's just not happy with the cable I have but it's the only one that I have that's long enough so I can't really swap it out okay need to do a little bit of debugging make sure that we are on port 11 kind of come over here make sure that we don't have anybody else talking to that one okay make sure that we're on the right board the Arduino Uno that looks good the port is port 11 what I'm going to do is I'm going to unplug it and then I'm going to plug it back in to see if I can get it all happy again and usually you never have this problem unless you're trying to use a lot which is what I'm trying to do here okay it went that time it looks like and I am still not getting a green so I have the brightness set to 150 I have green pen set to 10 here let's see believe it or not I did not have green pen hooked into 10 now I have green can hook into 10 so I had a little bit of a problem with my circuit but that's called debugging that is called troubleshooting so let's see if we can get that down there like that I just really wish I could get you where you could see this a letter so I can put a little piece of paper over it and now that doesn't know much I'm going to turn that green bag down and see if I turn the green down see it is green a little bit better okay yeah that shows up better is great okay so you see with the brightness there I can turn the green on I can turn the the red off and the blue off and I have green okay now the interesting thing though is is that I'm only writing one of those pins at a time like I bring green up I braked I put the other two down or if I make red up I bring the other two down so I'm only putting one color at a time red green or blue and we talked a little bit played a little bit with the levels so that we wrote but what if I wanted a beautiful aqua sort of a beautiful turquoise color that would sort of be I would want a little bit of green but I would also want a little bit of blue and so what if I brought this to brightness here as well so I'm gonna have a little bit of green I'm gonna have a little bit of blue and let's see if we can sort of get a turquoise kind of aqua going there oh yeah that is sort of a turquoise aqua but you can see that it's a little bit too much blue and not quite enough green and so I'm going to get down and dirty here and I'm going to start just writing numbers in instead of dealing with my variables and so I want a little bit more green and not quite so much blue and so let's make this let's make this Nani on the green and let's make this 50 on the blue and see if we can get a little bit more of kind of a turquoise that is a little bit too blue for my taste and it is trying to download and it is trying to download and waiting for it did not like it let's try it again okay yeah that is getting to be more aqua it's still more blue than I like so I'm going to turn that blue down even further okay I'm going to turn the blue down even further because I want a little bit I really want a turquoise color okay this is really starting to get turquoise now I'm going to turn it down even a little bit further so you can see the blue is a little bit more powerful and so to kind of get a Bluegreen I'm having to put just a little bit of blue and a lot of green and that is the color that I was on that is really the color that I was looking for there see if you can kind of see it through there that's really a pretty aqua that I was trying for I was really shooting for okay so let's see what else we could do with this okay so we could get done we could get the green in the blue to make aqua what if we got red let's make a red of a hundred and let's bring green to zero and let's bring the blue up to 50 what if mix blue and red together what do you think when we get there okay blue in red you can see that we're kind of getting a purple there we're getting a nice purple color okay what if we mixed red and green together let's put blue to zero we did that okay I'm getting sort of it that's looking a whole lot of green there and so I'm going to turn to green down and just let that red come out a little bit more if I put red and just a little bit of green in with my red okay now I have orange okay so what you can see is that that you can start getting the in-between colors and really what you ought to do is you ought to come up here and what we ought to do is make like a red brightness of green brightness and a blue brightness and then write those variables down here and then up here what we should do is just change the values up here instead of changing down here but I just kind of got down here and started kind of doing some pretty ugly stuff that you really shouldn't do but it was more today not so much about programming but more about a new component the RGB LED so what's your assignment for tomorrow is is to go in and I want you to create a bright red a great brain a bright green and a bright blue so show me that you can do red green and blue then I also want to see cyan magenta and yellow input cyan magenta and yellow well you might have to go onto the internet and do a little bit of looking in fact you might even find write values that you could write to get a really nice pure cyan magenta and yellow and then what I would like to see is purple and pink and orange okay cyan magenta and yellow purple pink and orange and I really want you to I mean don't just get it sort of you really go in there and get beautiful colors and do some research and figure out how you would write those colors and try to sort of see how these mixing colors go okay let's try one other thing if I put 100 100 100 what if I put equal values of the red the green and the blue I mix red I mix green and that makes blue and look at that I pretty much get white maybe the blue is a little bit strong there we turn the blue down a little bit but if I mix red I mix green a bit mix blue I can get white so what you can do is you a lot of fun with this LED and you can really go in and try to get all of these different colors and so have fun I'll come around tomorrow for a grade or if you're doing this on your own remember it's for your own benefit to do this and so do your best to get these different colors this is polemic order from top tech boy comm hope you'll join us shortly for Arduino lesson number 14 on lesson number 14 we're going to come in and we're going to work more with this RGB LED but we're going to work more on the programming side to start programming it up to really do some of these different colors but tune in thanks a lot and we will see you shortly
Info
Channel: Paul McWhorter
Views: 137,262
Rating: 4.8967228 out of 5
Keywords: LED, RGB LED, Arduino, STEM, Tutorial, High School Lesson, Simple Step by Step, Engineering, Programming
Id: gqAHOoqo3OI
Channel Id: undefined
Length: 27min 24sec (1644 seconds)
Published: Wed Jul 09 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.