Arduino Uno R4 WiFi LESSON 10: Writing Analog Voltages With the Arduino

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is Paul McCarter with toptechboy do.com and we're here today with episode number 10 in our incredible n tutorial Series where you're learning how to think like an engineer using the Arduino Uno R4 WiFi what I will need you to do is pour yourself a nice tall glass of ice cold coffee that would be straight up black coffee pour it 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 most of you guys probably already have your gear but if you don't look down in the description there is a link over to Amazon on you can hop on over there and pick your kid 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 the 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 how to write analog values using the Arduino Uno R4 now what do I mean by analog values so far with our LED we have either turned it on with the digital right high or turned it off with the digital right low no in between you're either off or you're on but sometimes we might like those in between values maybe I don't feel like a full bright LED in my face maybe I would want a softer lower intensity brightness how would you do that you need to do an analog right now next next lesson next week I'm going to show you exactly how the analog right works but today I'm just going to show you how to use it and then next week's lesson I'll explain it to you in a little bit more detail if that makes sense okay enough of this jawboning with you guys let's jump in and let's start building a circuit let's start doing some coding so I will come over here and we will look at our Arduino I will get out of your way and what you're going to need is you're going to need your red LED remember don't use the blue LED that is only for special occasions and you're going to need your thousand Ohm resistor remember I use those little pliers those little Clippers to clip my legs off here so I can get a little bit more uh get a little bit neater builds and then you're going to have a red wire and a black wire now does the wire color matter no it really doesn't any wire color will work but I like to kind of help me as my circuits get more complicated kind of help me in troubleshooting and seeing what's going on for my power I like to use a red wire and for my ground I like to use a black wire and then like if I have a control signal or something like that maybe I'll use a white wire but just develop some convention so that you're always doing it the same and it makes it a little easier to troubleshoot your circuits later on okay so what are we going to do we are going to come back over here and build this circuit that we have been working with right in the past we've been using pin 13 uh as our uh voltage pin pin 13 to provide the voltage then we come to the Long Leg of the LED then the short leg of the LED to one leg of the th000 ohm resistor then we bring it on home with the other leg of that resistor coming back to gnd D ground on the uh on the Arduino now the first thing that I have to tell you is if we are going to do analog rights you can't just use any of those input output pins you see that we have the input output pins between pin one and pin 13 so you see that we've got between pen well actually between zero in pin 13 and for the digital rights we could use any of them we wanted really it's better not to use one and zero but we could use 2 through 13 okay to do the uh to do the digital right but if we want to do an analog write we can only use a pen that is designated for analog rights and those are the ones with the little squiggly with the little squiggly by them and you can see it's pen 11 109 65 and three have the squ squiggle and it's probably shows here as well yeah you can see clearly here 11 10 uh 9 65 and three can all be used for analog rights now you guys forget that in one in my earlier Arduino lessons one of the most common comments I have is it only turns on and off it's not doing the inbetween well that's because you didn't use your friend who's your friend the little Mr squiggly there by the uh pen number and so what we are going to do today is we're going to go ahead and build this circuit but we're going to use pen 11 why because pin 11 has a squiggly so I'm going to go ahead and I'm going to put this in pin 11 and since I think I might have missed it by one yeah you see I I would really like to put my head over that thing but I have to sort of stay up here where I am so yeah you see that's in pin 11 and then I think I'll go ahead and hook up my ground wire as well to G and D okay and then let's check that yep you can see that we've got ground and pin 11 now what do we need to do we need to put the uh we need to put put the uh LED in and what I'm going to do this time I'm going to kind of build it across this way so my led the long leg is facing down right the long leg is facing down now the long leg of the LED needs to go to what it needs to go to the voltage so in that same column in that same column I'm going to put my pin 11 now on the short leg of the led the short leg of the LED over here I'm going to put one leg of the resistor okay one leg of the resistor will go in the same column one leg of the resistor will go in the same column as the short leg of the LED okay and it's kind of hard for me to do this from way over here but I think I have one in okay there that was kind of pain painful probably it was more painful for you than it was for me watching me try to get it there okay so now what do we have we have one leg of the resistor in the same column in the same column and darn it I missed it let's try that again I think what I need to do is straighten these legs up a little bit okay so one leg of the resistor goes in the same column as the short leg of the LED and boom I got it that time okay you see one leg of the resistor in the same column as the short leg of the LED and if I said it wrong in there once or twice I'm sorry now the ground pin needs to come to that same column as the other leg of that resistor so we should be hooked up now now if you ever hook something up and it starts blinking it's probably because you're still running the last program that you put in the Arduino right we left some program in the Arduino and when you power the Arduino up the Arduino starts running the last program that you put in it but okay we are set up there I'm just going to glance at it make sure it looks good yep it looks good and so now what I am going to need to do is I am going to need to call up my Arduino I'm going to need to call up my ardu quo IDE and you know how to do that right you know how to do that and then what I'm going to need to do is I'm going to open up I'm going to open up bare minimum and I know you don't see what I'm doing but I'll switch over where you can see in just a minute okay so you called up your Arduino IDE and I think this is the view that you want and let me just adjust that window a little bit so I make sure that you can see what I'm seeing that looks good okay now what are we going to do we're going to go come in and we're going to try to set the brightness of the LED so what what I'm going to do is I'm going to come down here in the void setup and I need to still do a what anytime I'm going to work with one of those pins I need to do a pin mode so I'm going to do pin mode and then which pen am I working with I am working with what did we say that was I am working with pen 11 right no no never use constants in your program what should I use I should use a variable so I'm going to call that red pin okay you could call it red LED you could call it led pen you could call it anything but it needs to kind of describe what you're doing and what is that going to be it's going to be an output now if I'm going to use this variable red pin I have to what I have to declare it up here so I'm going to come up here and I'm going to call it is it going to be an integer or a float well would I have pin 12 and a half no I would have pen 11 12 13 so it needs to be what kind of variable in int which are our counting numbers what is the variable name we said it's it was red pin okay red pin and we're going to set that equal to 12 like that okay now we're going to come and uh we've got our pin mode done who is our friend our F friend is Mr semicolon don't forget that and now what are we going to do we are going to do a digital right no we're going to do a what analog write okay what are we going to write to we're going to write to pin 12 right no no we're going to write to pin what red pen you set the variable up don't be afraid to use it now we've got to give it a value and what you have to understand is the range that you can go to is 0 to 5 volts that is the output of that pin 12 on the Arduino it can go from 0er volts to 5 volts but here is the issue you see Arduino doesn't think in terms of Arduino doesn't think in terms of 0 to five it thinks in terms of what kind of numbers binary numbers okay and so it wants a number between 0 and 255 okay it wants a number between 0 and 255 because that's an even multiple of like two let's see what is that let me see I've got two 4 I've got 1 two 4 8 16 32 64 128 and 256 so that looks like 1 2 3 4 5 6 7 8 it looks like about uh it looks like about an 8bit number let's try that uh let me try that real quick 2 raised to the 8 yeah 2 raised to the 8 is 256 okay so you see this is an 8bit binary number presented to us in decimal but then you're going to ask why are you saying 255 if it's an 8bit number why don't you go to 256 because we started with zero and since we started with zero and we've got 256 numbers we can go from 0 to 255 if that makes sense so anyway here if I wanted it full brightness then I would come in and to get five volts I don't put in five I need to put in what the biggest number which is 25 5 like that no no I don't put constants down here what should I call this I should call this brightness like that there's your semicolon if I'm going to use it down here I need to set it up up here so I'm going to call it an integer and I'm going to call it bright and I'm going to set that equal to 255 like that and now if I want to change the brightness I just come up here because maybe I would have lots of different things that I'm doing in there and here I can just at the program by changing my constants up at the top and that is a good programming habit okay so now if we run this and if we did this right what should we expect we should expect this led to come on full brightness so what we're going to do is we are going to run this and now all eyes on the LED it looks like it's running well and it is now uploading and and and denied denied so why did that not work okay why did that not work H why did that not work ah yeah look at that we're not on pin 12 we're on pin what pin 11 now do I have to go searching through my code to see everywhere I use that no I just got to what I just got to change that to 11 now we'll run it again and 12 wouldn't have worked either even if i' had been plugged into 12 why because there's no squiggly there so all eyes on the LED Boom full brightness and man that is so bright you guys can probably hardly see it it is very bright let's see if I put that diffuser over it you can kind of see it a little better okay but it's kind of hard to see it's so bright it just washes out now what what I want to show you is if you go from 255 to 254 and run it again this thing is so bright your eye is not going to perceive the difference between 255 and 254 and so when this thing comes you see it comes back looking just like 255 254 looks just like 255 because when something's bright your eye saturates and it can't perceive small changes in very bright numbers so this is kind of how you want to do it I like to go by factors of two so I will go from 255 not to 254 but I would like to go to let's say 124 something like that about uh 125 127 would be about half so let's say I go to 120 let's go to 126 so we keep things as even numbers and now I want you to watch this and this time we should see it perceivably dimmer okay so it's downloading okay it is compiling and it is Boom okay now hopefully you can see that that is perceivably dimmer than it was before now you guys you'll do it at home and it'll be really really clear to you it's just kind of hard for me to show you here the camera doesn't pick this up well now if I want to try another one I think I would go to let's just say 64 like that another half okay I go to 64 and I download and it is compiling it is downloading and boom okay you see you can clearly see that that's stemmer we can go to 32 download [Music] that yeah and you can see that it's on but it's noticeably dim what if we go all the way down I don't want to Bar bore you guys but you can do it on your own okay I go all the way down to one all right and when I go to one uh when I go to one it's done now it's so dim you really can't see it you can't see it on the camera but I can perceive it just barely showing there at a one but it doesn't show up very much on the camera let's see if you can see a four so one double would be two two double would be four let's see if you can see four okay so this is four and uh yeah I can see it I think you can see it a little bit there on the camera if I hold it up like this and you're looking down on it you can sort of see it but again it's quite dramatic when you are doing it in person okay so what have we learned so far in these lessons number one we have learned how to do digital writes number two we've learned how to use variables and declare variables number three we've learned to Sprint things to the serial Monitor and then number four today we learned how to do analog rights and so next week what I'm going to show you is I'm going to show you how this analog right really works because if you remember if you remember computers only know know what zeros and ones for the Arduino zero would be 0er volts and a one would be 5 volts and so if the Arduino Only Knows zeros and ones or offs and on or Zer volts and 5 volts how are we getting this apparent analog out with all of those in between values using a board that knows nothing but 0o to five or you know on and off or a binary zero or binary one how is that done I will show you that next week but I do need to give you a homework workk assignment and what your homework assignment is for next week is to write a program that will start with the Arduino at its lowest setting you know like the dimmest possible a one and then ramp up to full brightness 256 and then ramp back down to a one and so the LED is going to start out just barely perceptible it's going to bloom to full value and then it's going to dim out back to barely perceptible and then you'll go through the loop again and so the LED will be sitting going like this now a couple of things you have to think about you've got to think about how much you want to increment each step of brightness you want to think about how you want to increment it do you want to go 1 2 3 4 5 6 7 8 9 10 up to 256 or would there be a better way to do it you're also going to have to think about timing because if you're going up and down too fast you're not going to see it okay so you got to think about those things so you write a program that will very beautifully let that led brightness Bloom and then fade and then Bloom and then fade then you need to make a short video these videos can be 30 seconds one minute something like that show me your code okay and then show me your LED working post it to YouTube in your video leave a link back to this video and in this video down in the comments post link over to your homework assignment so I can go over and take a look at it and comment because I like to look at your homework I like to know if you guys are picking up what I'm throwing down you know or just going right over your head so post that homework and I'll take a look at it guys I hope you're having as much fun taking this lesson as I am making it want to give a thank you a great big thank you to you guys that are helping me out over at patreon there's a link down in the description if you want to help me out in that way you can go over to patreon and hoga bro brother up okay or uh it helps me also if you give me a thumbs up helps if you leave a comment down below you can always subscribe to the channel when you do ring that Bell so you'll get notifications When Future lessons drop and most importantly share this video with other people because the world needs more people doing engineering and fewer people sitting around watching silly cat videos Paul mcorder with toptechboy dcom I will talk to you guys later [Music]
Info
Channel: Paul McWhorter
Views: 4,763
Rating: undefined out of 5
Keywords: STEM, LiveStream, TopTechBoy
Id: lTzOvBYNo3U
Channel Id: undefined
Length: 21min 31sec (1291 seconds)
Published: Thu Mar 28 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.