Arduino Uno R4 WiFi LESSON 6: Create a Binary Counter With 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 six in our incredible new 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 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 by 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 you can hop on over there and pick your kit up and believe me my life and your 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 what I'm going to do is I'm going to show you my solution to the homework assignment which I gave you in lesson number five and that homework assignment was to create a 4bit LED counter a 4bit binary counter using LEDs with the Arduino now before I show you my solution I must pause and ask were you able to do the homework if you were successful leave a comment down below I Am Legend double chest bump and if you are not successful leave a comment down below I folded up like a cheap Walmart lawn chair well if you're new to this stuff and you're struggling don't worry about it we all fold up every once in a while and don't fear because I'm going to show you my solution today does that sound good I hope it does now let's review some of the stuff we've learned we've learned how to turn LEDs on and off from those digital input output pins on the Arduino we've learned that when you use an LED you need a th000 ohm current limiting resistor in your circuit we've learned how to do our pin modes we've learned how to do delays we've learned how to turn LEDs on we've learned how to turn LEDs off and last week we learned to count in binary so this week what we are going to do is we are going to take that circuit that circuit that we put together in lesson number four I think you'll see it better if I come over here we took that circuit that we put together in lesson number four and then what the assignment was the assignment was to count in binary using these LEDs so if you're just dropping into this lesson and you haven't taken lesson number four go back and watch it or very quickly I'll tell you how I have this circuit hooked up I have four LEDs each one of these LEDs has its long leg pointed back towards the Arduino so this is the long leg on the left long leg long leg long leg then we connected those long long legs to pin 13 on this one 12 on this one 11 on this one and 10 on this one so they go 13 12 1110 then on the short leg we have a resistor jumping over this trench and then connected to ground and so this to ground this to ground this to ground this to ground and then we create this ground rail by running this jumper from the ground over to G and D on the Arduino so hope hopefully you could follow that if I want a little fast go back and watch lesson number four all right now what do we want to do we want to make this count in binary and so what we've got to do is we've got to do kind of like this series that we wrote out last week remember this is counting in binary here we're counting 00000000 0000 1 00 0 1 right so it's like off off off off off off off on off off on off off off on on right and we've got to put this sequence in there uh in these uh uh program of these LEDs okay if we're going to do that we need to come over here now to our code view fire up that Arduino IDE we always start with what we always start with our friend in examples Basics bare minimum so you want to start with that we also want to make sure that our Arduino is hooked up so we're going to come to tools we're going to look under the comp port and ah M this is set to four but mine is on five so I got to select five yours might not be four or five but wherever you see the Arduino Uno R4 Wi-Fi you select that one and then under Tools we always want to just make sure that we have the right board so we go to tools board we come to Arduino R4 boards and we're going to go to the Arduino Uno R4 Wi-Fi which is the board that I'm using okay now if we are going to use those four pins that are connected to the four LEDs we are going to have to do what pin mode do we want to do that over and over or one time we want to do it one time so we'll do it in the void setup so we will come here and we will do a pin mode and what was our first one our first one was 13 pin 13 and that's what an output like that don't forget our friend Mr semicolon and then I think what I'm going to do is I'm just going to copy this we're going to go a little faster I'm going to copy it and then I'm going to come here paste uh p Ah try this again contrl C to copy control V to paste paste paste so now I have four of them so I've got pin 13 the next one was pin 12 pin 11 and pin 10 those are all outputs now to make this thing count what you want to do is you want to set all the LEDs and then wait because if you don't put a wait it's going to count so fast that you can't see it sort of like what we were doing in our first lesson our first program you can make something move so fast that you can't see it so we're going to set the four LEDs and then we're going to wait well how are we going to set them with a digital right and then what we have pin 13 so I'm starting on the left and working my way to the right we want that to be low okay how did I miss one semicolon up there my bad okay copying and pasting I'm not sure how that happened now I'm going to copy this contrl C and then I'm going to contrl V I like to keep my indentation good so then this will be pin 12 enter backspace contrl V tab 13 12 11 11 not 111 11 and then contrl V is going to be 10 so I've set these all what I've set them all low I've set them all off now what do we want to do we want to wait digital or not digital we want to delay and how many milliseconds we're going to count to 15 and so if we did a half second delay we would cycle through in about 8 seconds that sounds about right so a half second is what 0.5 seconds is what in milliseconds 500 in milliseconds why because there are a th000 milliseconds in a second okay now what I'm going to do is I'm going to copy this five lines of code so this will set the LEDs in the zero State now I want to go to the one state so I'm going to paste all of those again I thought I copied all of them I guess I didn't so I'm going to select these I'm going to contrl C to copy them then that block of code I'm going to leave a blank line so it makes it easier to read I'm going to paste and now I want to go to the number what one one is what low low low high off off off on so this then will become High okay and guys it'll make it easier for you to do this if you sort of write out your chart because it's hard to think about binary and think about programming at the same time I want to be thinking about programming so as I go through this what I'm doing is I'm looking at this little chart this little chart that I filled out over here and then that will make it easier for me to get through this is going to go low low low high and now I'm going to come down and now I'm going to paste again and now it is going to be what oh a a two is low low high low okay so we're going to come and we're going to go low low high high and this needs to be all uppercase okay and so we're going to go low low high low so I've done zero I've done one and now I've done two now I need to do three okay and so I'm going to come down here and I will paste again and this time it is going to be low low high high that is what that is the number three so I've done uh yeah I've done 0o one two now I've done three now what do I need to do I need to do four so we will do this again and this is going to be low high and then low low okay low high low low now we need to go low high low high so we will come here enter enter contrl V and then this is going to be low high low high like that okay now that was four now we want to do five and so five is going to be five is going to be low high high [Music] low does this make sense I hope it does low high high low okay now we need to do that was uh that was 0 1 2 3 4 five six that was six and so now we need to do seven which is going to be low high high high and we'll check this once we've uh once we get it all in and I found that it's easiest to check it just by watching it rather than looking at the code okay like that okay now I'm ready to do eight and you see I've kind of got to carry the one carry the one carry the one carry the one right and so this is going to be high low low low low like that okay that has got me up to number eight and so I'm going to go ahead and run this just to make sure I'm not copying and pasting a bunch of mistakes so let's run this and then let's watch our circuit and let's see what happens so I'm going to run it I'm going to take a sip of my Go Juice okay 0 1 2 3 4 5 six 78 hey we got that we got that pretty darn good and then you can see it repeats well when it repeats I'm going to give it a longer delay before we get to the bottom of the uh void Loop so I'm going to put an extra delay in here of let's say 2 seconds just so it'll pause before it starts over again okay so I counted to eight now I need to count to nine and I could copy one through eight and it would be simpler to do this but I'm just going to do them one at a time so now we had gotten to eight now we got to go to nine which would be high and then it would be high like like that nine now we're going to go 10 and the 10 would be an eight and a two okay that's a 10 and now I need to do the 11 so that would be an eight a two and a one okay now that was 11 12 is going to be an eight what was this 12 and this is going to be an eight and a [Music] four I'll get that okay that's 12 now we're going to go to 13 13 is high high how did I I must have copied that or something okay now I'm going to go high high low high is going to be 13 and then 14 would be an eight and a four is 12 and a two would be 14 let's see I got messed up here somewhere this is 8 and 4 is 12 and that is a 13 and now I need a 14 which is high high high low I believe that's right and then I need a 15 and if I messed up in the there we'll look at the display over here and then we'll figure it out okay so now we're going to go high high high high so I'll have an eight a four a two and a one and those will add up to 15 okay like that okay so now let's watch this let's watch this I'm going to run it and then let's watch it now this this one blinks because 1013 blinks while the program's downloading okay now you see I didn't get a clean start because I was talking so what I'm going to do is if you press this button it'll just start the program again from the start so watch I'm going to press it and now zero one 2 3 4 5 6 7 8 9 10 11 12 13 14 15 boom binary counter 0 to 15 all right guys okay hopefully you all were able to do that and hopefully you posted your uh homework to YouTube so that I could check it and make sure you guys are understanding and see if what I am sending out is getting caught by you guys and if you do your homework and post it it helps me to see if you guys are really understanding what I am saying okay I'm going to have another lesson next week on binary and what have we learned about binary so far we've learned that computers are nothing but a whole bunch of onoff switches we've learned that you can use an onoff switch to represent a one or a zero and then the onoff switches become like binary numbers and what did we do here we learn to count in binary but if we're really going to do things on the computer we've got to do more than just count we need to do things like what add numbers together subtract numbers from each other multiply numbers by each other and divide numbers by each other and so what I'm going to show you next week is I'm going to show you how to do binary math okay because once you go down onto that silicon everything's been forgotten except what zeros and ones so if you're going to add seven and four you've got a what first seven has to become binary then four has to become binary and then you've got to add those seven and four together so I'm going to show you next week how to do binary math but I do need to give you a homework assignment and I want you to get really comfortable with these binary numbers and this binary counting and so what's your homework assignment is is to add another LED so that you have five LEDs and then count in binary for five LEDs well how far could you count to okay how far could you count to let me see if I still have this over here okay let me see if I still have this over here give me just a second yeah I still have this over here let me come over here so let's look at this okay let's look at this so what did we do up here the first switch is worth one the next switch is worth two the next switch is worth four and the next switch is worth 8 so if I turn all of these on it's 8 + 4 + 2 + 1 is 15 well what would what would what would the next one be worth the next one would be worth 16 so if I have a 16 an eight a four a two and a one I could count to what 31 let's check and make sure that 16 + 8 + 4 + 2 + 1 this makes 10 this makes 20 and this makes one so I could count to 31 I could count to 32 and if I start at zero and I go all the way up to if I start at zero and I go all the way up to turning them all on I would be able to count to 31 just like these add up to 15 this would be this would be what this sounds strange this would be 20 + 10 is 30 + 1 is 31 I think I did it wrong the first time but 16 + 4 is 20 8 + 2 is 10 that's 30 and one is 31 so you should be able to count to 31 in binary and if you do it the way I did it you can kind of get through it pretty quickly and if you were a little smarter about how you did the copying and pasting you could probably make it go even faster okay and so that is your homework assignment make sure when you do your homework assignment you make a little video and you post it to YouTube in the description of in the description of your video link back to this video and then down below in this video put a comment that links over to your video so when that comment comes up I can go over I can look at your video I can comment on it and see again it it helps you see if you really understand this and it helps me to see if you're really absorbing the stuff that I'm spewing out at you okay guys I hope you're having as much fun taking these lessons as I am making them I want to give a shout out to you guys who are helping me out over at patreon you guys standing with me with patreon you're the ones that are keeping me in the game you're the ones that keep this great content coming I appreciate it it also helps if you give a thumbs up to the video comment down below that will help me with the old YouTube juice if you haven't already already subscribed to the channel when you do make sure that you ring that Bell so that you'll get notifications When Future lessons drop and most importantly share this video with other people because the world needs more people thinking like engineers and fewer people sitting around watching silly cat videos Paul mcarter with toptechboy do.com I will see you guys later
Info
Channel: Paul McWhorter
Views: 5,065
Rating: undefined out of 5
Keywords: STEM, LiveStream, TopTechBoy
Id: KEtut8pzXZA
Channel Id: undefined
Length: 22min 29sec (1349 seconds)
Published: Thu Feb 29 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.