Arduino Tutorial 5: Understanding and Working With Binary Numbers

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 today with lesson number five and our new our improved our exciting tutorial series on the Arduino microcontroller I need you guys to go ahead and pour yourself a nice mug of iced coffee I need you to get your Arduino out and we are gonna learn a very important lesson today and what we're gonna learn about is we're gonna learn about working with binary numbers and this is one of the most important lessons that we're gonna do because kind of the theme of this neck this new series of our dueƱo lessons is I really want you to understand with an Arduino what's going on underneath the hood I don't want you to just think about this little board that I can send commands to and it does what I want like I can send it a series of commands and then it does what I want it to do I want you to start understanding how it does what it does and we started that really in lesson two where I started explaining to you how an LED works there's a lot of physics going on with an LED and we started talking a little bit about solid-state physics and we started talking about semiconductors and one of the things we learned about semiconductors is that all digital devices from arduino z' to digital cameras to cell phones they're all made of semiconductor devices and a lot of these are made out of silicon okay and what we learned about a semiconductor device is a semiconductor can be a conductor or it can be an insulator and you can switch it from being a conductor to an insulator by applying a voltage to it so you could see that the LED if you don't apply a voltage it's off if you apply a voltage you create it you cause it to become a conductor and it turns on so you can turn an LED on or off you can have it in a conducting or you can have it in a non conducting state that is kind of at the heart of how digital devices work digital devices operate based on tiny switches the switch can be on conducting or it can be off insulating and you can apply a signal to the switch to flip it either on or off and the way to think about it is if the switch is on think of it as a one if the switch is off think of it as a zero so LED on that's a one LED off that's a zero and this is the way to think about things again I'm trying to get you from you've got the real world as you're walking around and you're interacting with all of these physical objects and how do you map that on to something like a computer or an Arduino so the first thing that you have to see is anything around you whether it's colors or music or numbers or letters or words or pages they can all be represented by a number okay so first of all numbers can be represented by numbers right I got three fingers up okay three that's a number numbers can be represented by numbers how about letters letters can be represented by numbers you could say an a is a zero a B is a 1 C is a 2 a D is a 3 so I could represent any letters by numbers so if I can represent letters by numbers I can represent books I can represent words by numbers and if I can represent words by numbers I could represent a whole book by a number so I could take a book and I could change it into a number same thing with colors you can change colors into numbers same thing with music you can change music into a series of numbers so almost anything you interact with in the real world you can represent as a number and that's kind of how computers work you take all of these things around you and the only thing that a computer or an Arduino or a digital device understands is numbers everything is converted into numbers now the thing about a digital device like an Arduino or like a computer is they're kind of stupid they only understand two numbers a zero or a one right there's a bunch of little switches and those switches are either off or on there are zero or a one well you can't do much if you just have one switch like one diode one switch you could only do two things off or on so how would you do something more complicated like music or a page of text well you need more than one switch the good news is on these digital devices that switches are tiny the switches are tiny and so on something like a microcontroller chip you can have a billion 1 billion with a B or you can have 10 billion switches each which only knows whether it's on or off a zero or one but you can have many many many switches together and so you take something very simple like the concept of on or off 0 or 1 and all the sudden you can do magnificent things like having digital cameras or iPhones or music players and all of that stuff but it all comes down to zeros or zeros and ones because anything in the real world can be represented as a number and any number can be represented by a series of zeros and ones and a series of zeros and ones what this is known as is it's known as binary ok binary numbers so if you're gonna understand the Arduino if you're going to understand how computers work work what you have to do is you have to understand binary numbers now you know how I like to teach I like to teach by taking you back to something that you understand what is it that you understand you understand how to count and so I want to take you to your world of how you count and then understanding what you're really doing and then I'm going to show you how binary numbers work so when you count what is the first number no it's not 1 the first number is 0 ok so if you're going to count you're going to start with 0 and then the next number you add 1 and you get a 1 and then you add 1 and get a two and A three and a four and a five and a six and a seven and an eight and a nine stop stop don't go on cuz it's just gonna roll off your tongue but I don't want it to roll off your tongue I want you to understand what you're doing with the next number and if you understand what you're doing then you'll be able to understand how binary numbers work okay so what is the problem we start with zero and we go to none we have ten different characters and you've just used up all 10 characters but you need another number so what are you gonna do are you going to come in and make another character and then the squiggly and then the wavy and then the this and just come up with a new character for every number no because you want people to remember all those you can kind of remember ten characters which are zero through nine so that's one two three four five six seven eight nine ten do you understand how you have ten characters and starting with zero you counted to none you've looked used up all of your characters but you at want to add one more without coming up with a new symbol so what do you do 9 plus 1 is 0 carry the 1 so what you have to see is 10 is 9 plus 1 9 plus 1 is 0 and you carry the 1 and now you start cycling again now you can use this one again you can add 1 and the 0 becomes 1 and you still have this one here so what I want you to see is what you are doing you are adding 1 you run out of characters 9 plus 1 is 0 carry the 1 all right well if we are gonna instead of having 10 characters 0 through 9 new you only have 2 characters you're gonna use them up pretty quickly because you only have a 0 and a 1 but the exact same concept is gonna hold up here I think I should zoom in a little bit here so you can see okay let me come a little bit more because I really want you to see this clearly so what we're gonna do is instead of having be like if you look here we have two digits that we played with here we are going to have four digits so we're gonna have this this this and this we're gonna have four digits here that we are going to work with four digits and since its binary you're gonna think of these as four switches so where are you gonna start with your switches you're gonna start off off off off that zero zero zero zero what number is that it's zero okay it's zero now you have zero zero zero zero you want to add one to it so you do this at this least significant digit and you add a 1 0 plus 1 is 1 and then the rest of these remain 0 and so if you think back about switches this instead of off off off off this is on off off off and this is the number 1 ok now we're going to add another one 1 plus 1 is no it's not - what did we do here 9 plus 1 is 0 you've got to go all the way back to the top and you've got to carry the 1 so 1 plus 1 is what it is 0 carry the 1 and then the rest of these are 0 alright now I'm going to add another one well 0 & 1 become 1 you still have this you have zero and zero now this is where it gets a little harder so I'm gonna I'm just going to zoom in on this one problem right we had where did we end up zero zero one one and now we want to add one to that okay we have zero zero one one and we want to add one to that well how do we do that one plus one is no no one plus one is not two one plus one is what it's zero carry the 1 now I have 1 plus 1 is 0 carry the 1 and now 1 plus 1 is 1 all right and then 0 comes down so when you have 0 1 1 the next one is going to be 0 1 0 0 so the next one is 0 1 0 1 I mean 0 1 0 0 right 0 1 0 0 all right now it gets easy we add 1 to the 0 its 1 0 1 0 that was easy right now we add 1 1 plus 1 is 0 carry the 1 and then 1 & 0 that's still pretty easy we add 1 and so this becomes a 1 we still have this 1 we still have this one and then this is 0 here's where you've got to be careful so let's do this we have 0 1 1 1 and we're going to add 1 to it 1 plus 1 is 0 carry the 1 all right 1 plus 1 is 0 carry the 1 1 plus 1 is 0 carry the 1 and so now we have 1 0 0 0 so this becomes 1 0 0 0 now it's going to get easy again if we add another 1 it's going to be 1 0 0 1 we add a 1 1 + 1 is 0 carry the 1 and I've got 0 & 1 and now add a 1 it's going to be 1 0 1 1 okay let's keep going let's say we go 12 13 14 15 okay now if I add 1 1 plus 1 is 0 carry the 1 and then I've got a 1 and a 1 is 0 carry the 1 I bring this one down ok now I add 1 it's going to be easy 1 1 0 1 now 1 1 that 1 in 1 is 0 carry the 1 and now I add 1 I've got 1 1 1 1 ooh you kind of lost where you couldn't see that alright so then it's 1 1 1 1 now what if I added 1 well it's going to be 0 0 0 0 and carry the 1 I've run out of digits if I can't add another number I can't go to 16 with just 4 switches with just 4 bits so we'll just leave it here at 15 if I wanted to go to 16 if I wanted to go to 16 what it would be is it would be 0 0 0 0 and carry the 1 I would have to have another switch out here ok but we're just going to do the 4 switches what you have to see is I was counting by what's here by ones I was counting by what's here by ones and so the decimal number 0 is the binary number 0 0 0 0 the decimal number 1 is 0 0 0 1 the number 2 is 0 0 1 0 okay these are the same numbers 15 as 1 1 1 1 and so if you start looking here you see a pattern right there's a pattern 0 1 0 1 0 1 0 1 because you're adding one and then you go 0 0 1 1 0 0 1 1 0 0 1 1 then you go 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 and then 8 zeros and then 8 1 see see there's a pattern of how these binary numbers work but this is a way like let's say if I just give you a binary number and then I want you to go from binary so this is decimal this is binary and now let's go back to decimal so this is what I want you to see how would you figure out that this binary number is the decimal number 8 well what you have to see is just like this is a number times 1 plus a number times 10 you can see this digit is worth 10 times the number this digit is worth 1 times the number what's the same thing only a little different this column is worth 1 times the number so every time you have a 1 it's worth 1 this one is worth 2 times the number this one is worth 4 times the number this one is worth 8 times the numbers 16 32 64 if you went on so let's see zero zero zero zero is the decimal number zero because there's not a one there's not a two there's not a four there's not an eight the number one is the number one because this place is worth what 1 all right how about zero zero one zero well this one is worth how much to he's starting to see it how about let's do this one okay this is worth one this is worth eight eight and one is 9 which you have there how about 15 well that's an 8 plus a 4 plus a 2 plus a 1 fifteen and do you see that with just four switches we've been able to represent 16 different numbers 0 to 15 is 16 different numbers if we had 5 switches we could represent 32 numbers if we had 6 switches we could represent 64 numbers so just by stacking a certain number of switches together we can really quickly represent incredibly huge numbers so if you said 1 million two hundred and thirty four thousand more switches and then you could go in and use this project process and you could turn any number into a series of zeros and ones if you can turn any number into a series of zeros and ones then you can deal with it with something like an Arduino or any digital device because you're turning a number into zeros and ones which then at the hardware working level on the Arduino or the computer or whatever it's going to be switches that are on or off and so like we have off off off off we have on off off off we have on off on on CC switches like the diode remember how we turn the diode on and off remember in solid-state physics in lesson two we were switching the diode from conducting to non conducting on off zero one so this is how a computer works any color any music any letter any book any number can be represented by a number and any decimal number can be represented by a binary number and any binary number can be realized with something really simple a series of on and off switches and that is what happens on the silicon it is a bunch of on and off switches there are only there only one thing on a digital device and that is a switch and then there are many many many many copies of that switch but digital computers devices are nothing but humongous numbers of switches it's like a modern microprocessor would have billions and billions of switches but that's all it is billions and billions of switches connected together cleverly so that it can represent anything as a series of zeros and ones okay guys this is your assignment for next week what I want you to do is I want you to make a digital counter using your Arduino remember your most excellent EAL eggo super Arduino kit you have LEDs in it and I want you to make an LED counter that will count from 0 to 15 now how would that work well how many LEDs will you need you will need 4 all right so how many pins will you have to connect those LEDs to on the Arduino you'll have to connect to 4 pins how many resistors will you need for this circuit you will need 4 because each LED will need its own current limiting resistor in your program how many pin modes will you need you'll need 4 be sure and use variables because you are going to have 4 LEDs you'll have 4 pins you're using you'll have to do 4 pin modes then what would you do well I'll give you kind of a little hint you'll do did you toll right and then you'll use your PIN whatever your PIN is your first pin you will write it low right you'll write the first one load the second one load the third one load the fourth one low and then you'll do that then you need to put a delay in because if you don't you won't be able to see it so you'll need to write all of these low and then you will need to have a delay then what you'll need to do is write the LEDs low low low high and then put a delay right and then you will need to write them low low high low and then put a delay and so what I want you to do is I want you to make a counter where it will be off off off off wait a second and then off off off on and then wait a second and then off off on off right like that off off on off so really we could look at it like off off off off off off what on on on on I want you to cycle through these put the LEDs like like this wait a second then put them like this wait a second then put them like this wait a second then put them like this wait a second and then cycle all the way down through all fifteen numbers and then if you do that in the void loop it will just start over again okay guys this is really exciting stuff to me because you know even though I'm trying to do this quickly it's really the essence of how an Arduino and every other digital electronic devices work everything is just a bunch of zeros and ones and that's a bunch of switches that are on and off and you are going to do this first binary assignment by writing the code and building the circuit to make a binary counter with the Arduino okay guys if you like this video think about giving us a thumbs up think about subscribing to this channel maybe sharing with other people this is palma quarter from top tech boy comm I will talk to you guys later
Info
Channel: Paul McWhorter
Views: 443,932
Rating: undefined out of 5
Keywords: Arduino, Binary, Base 2
Id: rTuKKVcYeMg
Channel Id: undefined
Length: 24min 48sec (1488 seconds)
Published: Thu Jun 13 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.