Arduino Uno R4 WiFi LESSON 18: Controlling RGB LED with an Arduino

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is Paul mcarter with toptechboy dcom and we're here today with episode number 18 in our incredible new tutorial Series where you're learning how to think like an engineer using the uino Uno R4 WiFi what I am going to need you to do is pour yourself a nice tall glass of ice cold coffee that would be straight up black coffee poured over ice no sugar no sweeteners none needed and as you're pouring your coffee as always I want to give a shout out to our friends over at sunfounder sunfounder is actually sponsoring this most excellent series of video lessons and in this class we will be using the sunfounder elite Explorer kit now hopefully most of you guys already have your gear but if you don't look down in the description there is a link over to Amazon you can hop on over there and pick your K up and believe me your life and my life are going to be a whole lot easier if we are working on identical Hardware but enough of this Shameless self-promotion let's jump in and talk about what I am going to teach you today and what I'm going to teach you is I'm going to teach you about the RGB L E D sound good I hope it does so I need you guys to open up your kit and I need you to find this little bag of led the little juicy bag bag of LED goodness here okay and I want you to look at those LEDs and I want you to tell me that there's one that is different from all the rest someone tell me leave a comment down below what do you see in this bag there is only one and that one LED is different than all the rest so I'll give you a second to look for that I will take a sip of coffee and get out of your way okay and then we'll switch over to our desktop view here and then I will show you that special that magic LED and what is different instead of having two legs it has four legs and so that's what we're going to learn today what is it with the four-legged LED what is it with the four-legged LED so we'll switch over here and what the RGB LED is it in one little package has a red a green and a blue LED so in one LED you can get red you can get green and you can get blue and the first thing that we need to kind of look at here is let me see if I can come back over here I need you to see and I'm going to put it very deliberately like this you see that there is one leg that is longer than the other legs this one leg is longer than the other legs and then left and right the two uh the two two legs are the same okay and then when you come over further to the right there is a shorter one okay so let's come in and let's see if we can figure out how this led works all right and so we will come back over here so we all agree that there is a long leg here that long leg that long leg is the ground and then the leg that is by itself to the left of the ground that is the red R LED and then to the right of the ground is the green LED and then over by itself to the complete right is the blue LED and so this is three LED in one and they share a common ground and so let's see if we can kind of draw it so we're going to have one LED that is the red LED and it's going to come down like this and then we are going to have another LED and that is the green LED like this and it's going to come down and then we're going to have what we're going to have the blue I don't like how I drew that we are going to have the blue I still don't like that okay much better then we're going to have the blue LED that comes down and then all of those are going to be connected together down here and then that is going to go to ground gnd D so we're going to hook this gnd D pin to ground but we still need we still need a what we still need a current limiting resistor we still need a current limiting resistor now this time we're going to need what three current limiting resistors so we're going to come and we're going to have a current limiting resistor for the red Channel a current limiting resistor for the green Channel and a current limiting resistor for the blue Channel okay so if I were going to number these pin this one on the left pin one then pin two then pin three then pin four the pen one the is the red one and so this would be pen one and then the pin two is the ground okay and then the pin three is the green and then the pen four is the blue okay so now what would we do would take the one two three up at the top and we would connect it to three different output pins on the Arduino okay and I would probably go ahead and hook it to pwm pins just in case we want to set the brightness I would use the little squiggly pins okay and then that center pin that long pin we are going to come down and we are going to hook to ground now one of the most common questions I get on these led is well can I just use one can't I just use one resistor and put it down at the ground pin and that would then limit the current for all of them no you can't do that because if I turn pin one on as current flows through that voltage is going to increase on that resistor down there now if I turn pin three on also it's going to increase the current and so I'm what's what's going to happen is I'm going to get cross talk between the channels what happens with what I'm doing on channel one is going to affect what happens on channel two so if I turn red on and then I turn green on the red color is going to get dimmer so to keep isolation between the two channels you have to use three different Uh current limiting resistors and remember these new arduinos have somewhat lower current capabilities and each one of those resistors then we're going to want to be a th000 ohms okay so that's kind of how it works let's see if we can jump over here and get this thing hooked up and see if we can make it do make it do its stuff all right now what I know is from that picture I'm going to put the resistors up above okay I'm going to put the resistors up above okay and so what I'm going to do is I'm going to come down and notice that I've got this oriented I've got this oriented like did in the picture where that long leg is kind of to the left the long leg is not kind of to the right the long leg is kind of to the left okay like that now this time I'm actually going to try to P plug all those pins into adjacent rows okay or I guess those are those are columns they're into adjacent columns and now I got to press it down a little bit okay so now let's go back over here and and let's remind ourselves what do we want we want to then hook the ground that ground pin directly to ground it's not going to go through anything it's just going to go directly to ground and I love using these little bow jack wires I hopefully you guys have had your chance to get these uh there's a link down in the description if you don't have these little straight wires it makes for neat builds now we know the second pin from the left was the ground pin and so what I need to do is I need to connect that I need to connect that to man it's hard to do this I can either look at it clearly for me or make it clear for you but it's hard for me to get it to be real clear and I missed it by one didn't I let's try it again man I keep getting off by one [Music] pin man how many times is that like four times boom fifth time was a charm okay and so now what I'm going to do is go ahead and make a ground rail down there even though I just need one ground I'm trying to get you guys comfortable with creating this ground rail down here so I'll take that over to g& D all right now up above this up above this I need to connect those resistors and I'll show you over here again right we need to connect those R resistors above and so we're going to jump over that trench to connect those things up but what is wrong what is wrong is I've got this all the way up at the top so I can't conveniently plug that in so I'm going to move this down I'm going to move this down by one row and so I'm going to pull it out and I'm going to move it down by one row and I know sometimes my fingers block you but I always want to come in okay so you see I've got it that second pen goes to the ground and then I have a place here to hook things up so now I've got a place to hook in my current limiting resistor so I'm going to go to the left I'm going to go to the left pen which is the r pin okay so you see how I have that long I have that I have that R pin going through this resistor now I want to skip I want to skip that uh I want to skip that next pen the second pen because that's ground and I now want to go to the third pen Okay the third pen let me just put it in where I can see it better and then I'll show it to you because I'm kind of operating a little bit blind here okay so now that third pen is in now let's get that fourth pen which is the blue pen okay that fourth pen is the blue pen I'll bring it up there like that okay so you see we got a really neat compact build Here and Now what do I know I know this needs to go to the r Channel this needs to go to the G Channel and this needs to go to the B Channel and I think what I'll do is I'll have RGB is going to be 9 10 11 Pin why am I using 9 10 and 11 because 9 10 and 11 are all pwm pens they have that squiggly in case we want to control brightness later on we can use those squigglies right and then 9 10 11 are all together so it's real simple 9 10 11 RGB so now now I do like to be neat and so for the red Channel I'm going to use a red wire and then that is going to come over to pin nine okay like that you see that now why did that come on that bugs me I had a program in there I must have been using that pen already but we'll kill that you got to remember when you power up the Arduino when you power up the Arduino it will go in and it will run whatever the last program was in there and so you see I must have had that that pin n turned on in the last program that I Ran So I have R now the next one's G but I remember I have to skip over that ground one and I've got to come right there and then I'm going to go from nine this green one's going to go to 10 like that see how neat that is okay and then the final one is B it's the blue Channel and I'm going to put it right there and then I'm going to come over to 11 RGB 9101 you like how I do you like how I uh coordinate those colors with the uh with the wires you can't always do that but anytime I can I like to try to be as logical as I can with what I'm doing and I'm just trying to check and make sure that that Center one is in the right one yeah you see it's just kind of been over there a little bit but it is in the right hole okay so now there we are so we got our circuit done and we've got our explanation done we're ready to what we're ready to code my friend we are ready to code so let's go ahead and what I need you to do is fire up your Arduino IDE and let's see if we can get some code written here this now is very similar to what we did last week and so hopefully you're com comfortable with that so we're going to be uh we're going to be turning these things on and off and so up at the top I've got to Define some variables so I'm going to have int I'm going to call it red pen red pen was equal to nine right and then int green pen is equal to 10 like that and then int blue pin is equal to 11 I always going to go back and check yep 9 10 11 that looks good now I'm going to use my B rate so I'm going to set my B rate equal what what what int int B rate BR is equal to 96 let's let's let's live dangerously let's say 11500 let's go faster this time and if I change it here I better remember to change it where and in fact I think I could go ahead and change it let's see yeah you see that's n 9600 we're going to go ahead and set this at 115200 as well okay and then our friend Mr semicolon goes there man we're just rushing through this okay that looks pretty good that looks pretty good okay so let's come down to our void setup and we're going to use the serial monitor so we're going to say serial. begin with the B rate and then we're going to do our pin modes so we're going to do a pin mode which pin the red pin and it is a what output like that pin mode and then we have a I really really don't like all this popup business going on Belo red green go in the right order green pin is an output semicolon pin mode blue pin is an output semicolon okay we've turned the serial monitor on we have done our pin modes okay so let's just come down here and let's just try something what if I come over here and I say digital right digital right what red pin and then I'm going to take that high like that semicolon and let's run it all eyes on the RGB LED please and we are running [Music] it okay it's almost done and boom look at that look at that my friend a beautiful red I got these diffusers I was trying to Hope I could get something that would allow you to see it better but alas it still doesn't show that good because well that's pretty good on the camera it's looking a little orange to where as I look at it in real life it really is a very very bright red and so it is a very very bright red if I can turn red on I can turn red what off so I'll go low there let's try again and it is off that's good well how about this what if we go green pin what if we take that high somebody predict what is going to happen here if we've hooked it ight and I do think I have we should see this turn green boom and it is a beautiful green let's let's turn green off low like that come over here send that on down we should turn it [Music] off and then we are going to do blue pin high like that what did I oh oh case does matter hi G like that let's see if that'll work I was doing so good we were sort of on a roll weren't we and it is downloading and we have a blue a beautiful blue a beautiful blue so boom red green blue uhuh that is pretty neat so one LED you can do RGB now this is your your homework assignment your homework assignment is to ask the user what color they want the LED what color they want the LED okay and these are the colors you're going to have to ask red green blue which you might expect but then you also have to do cyan magenta yellow orange white so red green blue cyan magenta yellow orange and white okay that is the assignment so you're I'm sorry I really apologize we we don't have a cyan leg and we don't have a magenta leg and we don't have a yellow leg so you're going to have to figure out how to do it then once you do it what you need to do is make a short video of your circuit and of your code and showing it work youve got to show it to me working post it to YouTube in your description link back to this video and then down below leave a comment that that links over to your homework solution so I can hop on over there and see what you did okay guys that uh I think that is a pretty I think that's a pretty cool lesson I really I really love the RGB LEDs and we're going to we're going to be playing around with a little bit more because there's just a lot of really uh really interesting things that you can uh that you can do with that rgbled and guys I hope you are enjoying taking this class as much as I am making these lessons I want to always give a big thank you to you guys who are supporting me on patreon it is your support and encouragement that is keeping these great lessons coming so I really thank you for it you all can also help me by giving me a thumbs up on this video and leaving a comment down below if you haven't already subscribe to the channel when you do make sure you ring that Bell so you'll get notification when future lessons drop and most importantly share this video with other people because the world needs more people thinking like an engineer and fewer people sitting around watching silly cat videos Paul mcarter with toptechboy do.com I will talk to you guys [Music] later
Info
Channel: Paul McWhorter
Views: 2,494
Rating: undefined out of 5
Keywords: STEM, LiveStream, TopTechBoy
Id: ASHBCGGeEPk
Channel Id: undefined
Length: 21min 20sec (1280 seconds)
Published: Thu May 23 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.