Hello guys, this is Paul McWhorter from TopTechBoy.com and I am here today with the all new, the improved Arduino tutorials. Now those of you who are familiar with my channel know that I have a very popular series of lessons on the Arduino that I made several years ago. And a lot of people have watched them, a lot of people have really loved them, but it is time to redo those videos because a lot has changed.
The first thing that has changed, a lot of the hardware has changed. There's more sensors. There's all types of more things that we can do with the Arduino due to the new hardware.
Second thing is there's been some changes in the software. And so we really need to redo things with the newer integrated development environment. The third thing is that I have an improved studio. And so some of the production quality was pretty low.
I think the content in the first series of lessons was really good, but the production quality was pretty low. And so I've got... better production quality right now. So it's really time to remake the videos, but probably the most important change is that if you remember in the first set of videos, I would drink hot coffee from this cup.
For this series of lessons, I will be drinking iced coffee from this big mug. So I need you to go pour yourself a nice big mug of iced coffee and get ready to follow along. If you're new to Arduino, before we get to the end of this video, you're going to have not only written your first program, you're going to have written your first four programs, and then I'm going to give you some simple assignments of things to do on your own based on what you learned today. But today, you will get in and you will write your first set of programs.
Now, if you were here before, the first four or five lessons are going to be repeat. You can just kind of skip to the more advanced things. But I want to start... all the way back at the beginning so we can take a person off the street who knows absolutely nothing and we can teach them to program a microcontroller step one you need to get your hardware this series of lessons I will be using this super starter kit Uno R3 project by eLEGO available at the convenient link below in the description hook a brother up get your kit from there this kit cost $35 it includes an Arduino and then just a boat load of components. This kit is going to keep us busy for a long time because it's got sensors, it's got actuators, it's got circuit elements, it's got everything you need to do hundreds of projects.
So bargain at $35. Step one, order your Arduino kit. If you already have an Arduino, you can go ahead and start playing along right off the bat. Okay, so get your kit ordered. Step number two.
we have to install the software and that's that's what I'm gonna show you how to do today and the simplest thing is we can go to a Google browser I can make myself smaller to get out of your way and then what we just want to search on is Arduino download okay boom first result is the website www.arduino.cc slash en slash main slash software. We will go there. And this is where we download the most excellent and free software.
I am running on Windows 10 and I will download the latest version of the software. As of the time I'm making this video, the latest version is Arduino 1.8.9. You don't have to download this exact copy, this exact version.
Just download whenever you do whatever the latest version is. So whatever it says here, that's fine. There'll be little tweaks, but what I'm showing you here should work for a long, long, long time. Now, I'm on Windows 10, so I'm going to click on this link, which says Windows Installer for Windows XP and up. If you're on Windows 10, this is what you would click.
Or if you're on Windows XP or higher, this is where you will click. So we will click there. What they are asking you to do is hook a brother up and make a donation.
I have helped out already, and so I'm going to just say just download. So I click. And then down here, if you're in Chrome, in the lower left, you can see the little EXE installer is downloading. Happening pretty quickly, so we will just wait for it.
It has downloaded. So now we just click on that downloaded file. If you're not on Google Chrome, then you've got to kind of go hunt around and find where that file was downloaded to. But on Chrome, we just click on it. It is asking me, are you sure you want to let Arduino change your computer?
Well, yes. I will click yes. And now it's saying, do I agree with the terms of service?
Yes, I agree. I'm going to do a pretty standard installation, so I'll just leave it with everything checked there and click next. It's going to put it in a pretty standard location under program file slash Arduino, and then we click install. I'm not going to pause the video because if you're playing along at home, you can just download it right along with me.
I will enjoy a little coffee though. It is going pretty quickly here, and we're going to get this downloaded, we're going to get connected to the Arduino, and you are going to write your first program. I think you're going to find it's a whole lot easier than what you think. And you're going to be wondering, why have I waited so long to learn to program?
Why have I waited so long to learn a little engineering, a little computer science? Well, at least you're doing it now, okay? Happy Little Blue Bar is almost all the way across. It says completed, so now I will click close.
All right, now the software has been installed, so if I come down to the little search bar, or I guess on Windows 7 you could just click the button, but I'm going to say Arduino, and there is the Arduino app, the Happy Little Arduino app, and I am going to... Now, you just ignore what I'm doing here for a second. OK, I'm just going to put it on my put it on my taskbar. OK, so here we go.
Trying to get it. Yeah. Pin it to the taskbar.
And that way it'll be down here and be ready to roll when you need it. But I can just click it from here this time and you see it is starting to open. OK.
I'm going to switch over to a slightly different view here so that you will be able to see my code and my Arduino. Okay, this Arduino is an Arduino that I just had laying around, so I'm going to unplug it. And I'm going to get out of my Super Starter Kit. I'm going to open it up with the little orange tabs.
And then what you will see is, you will see right here on top is a little envelope. a little static envelope that has your Arduino in it. So let's get that out.
And then you will need a USB cable which I already have here. The other end of the USB cable is hooked to your PC, the PC that you just installed the code on. And then we have the Arduino. So I will come over here and I will plug the Arduino in and what I hope is when I plug it in I hope that I hear a happy little noise.
Okay, I hear the happy little noise. And what that means is the PC is recognizing something that it understands has been plugged into the USB. And so that means that things should really work from this point.
Okay, so now you have Arduino IDE open. You have the Arduino plugged in. And so you need to call up a program called bare minimum because bare minimum is where you always start when you're writing a program.
So it has things that you will use in every program that you write. So we will come to file. We will come to examples.
We will come to basic. We will come to bare minimum. Okay, now you get this program. This program shows you the two things that are part of every Arduino program. The first is called the void setup.
The void setup begins with the open curly and it ends with the closed curly. The commands that you put in void setup will be executed one time. So you set the Arduino up in the void setup. Then the things that you want to run over and over, those commands you put in the void loop. The void loop starts with the open curly and ends with the closed curly.
Every Arduino program has a void setup. Every Arduino program has a void loop. So this is what you're going to start with.
Now the next thing is we have to make sure that we are talking to the Arduino from the IDE. So we need to come up under Tools, and we need to come down to Port. And we can see that on mine, it sees a COM1. That might be the mouse or the keyboard or something. But then it sees connected to COM3 the Arduino or Genuino Uno.
So it sees an Uno connected to that port. Now, for you, it's probably not going to be port 3. It could be port 7 or it could be port 25. But the point is that it should be the one that recognizes that an Arduino is connected to it. Now let's just verify that that's true. So you see COM3 is Arduino Uno. Okay, I'm going to come over here, and I'm going to unplug the Arduino, right?
It's been unplugged. Now if I come to Tools, and I come to Port, COM1, but doesn't see the Arduino. Why? Because we unplugged it. Okay, things are working the way they should, so we plug it back in.
We get the happy little USB noise. And you can see some lights coming on on the Arduino, seeing that it is in fact powering up. And now if we come back to tools and we go to port, we can see that the COM3 is there.
Now you need to go across and you need to select whatever COM port has the Arduino connected to it. For me, it's port 3, so we select that. Now we're connected to it.
All right. The other thing that you need to do in your setup, you need to make sure that on your... board it matches the board that you're that you're using we're using the uno so we come down to arduino uno if you're using a nano you would come here or all the different arduinos just make sure that you select the board that you're using because if you don't you can have problems so we were on the arduino uno ladies and gentlemen we are ready to write our first program and it is as simple as this all right uh on this arduino you We want to do things without having to start building things. So let's just write the simplest program possible.
Do you see these pins along the edge of the Arduino? It goes from pin 0. They're labeled digital pins from pin 0 to pin 13. These pins we can interact with. We can send signals to the pins, or we can pull signals off of the pins.
OK? And so you can connect things up to these pins, and then you can make the magic happen. Okay, but I don't want to build circuits in this first lesson. So the most excellent thing is if you look here and see this pin 13, that pin 13 is already hooked up to this little LED on the board.
So any signal that we send a pin 13, we are going to be sending to that little LED. And so that allows us to write our first program without having to wire anything up or hook anything up. So. First thing we've got to do is we've got to set the Arduino up. What pins are we going to be working with?
We're going to be working with pin 13. So we have to tell Arduino we are working with pin 13. We do that in the void setup, and we do that with a pin mode. P-I-N, capital M-O-D-E, pin mode. You notice when I type in pin mode with the right capitalization, it turns orange?
That's a happy thing. That means that it recognizes the command. So I'm going to tell it.
what I'm gonna do in my pin mode command open parentheses now I have to put two parameters in the first parameter is which pin are you working with hmm which pin are we working with pin 13 uh huh then we put a comma and now we're gonna have to give the second parameter the second parameter is we're telling the Arduino are we gonna use pin 13 as an input or an output Well, we're going to send a signal to it so it is an output. Kind of like the printer, right? You send a document to the printer.
The printer is an output device. We're going to send a signal to pin 13. So pin 13 becomes an output. All caps.
O-U-T-P-U-T. Ah, when I type it in correctly, what does it do? It turns blue. That's a happy little blue saying that it recognizes that parameter. We now close our parentheses.
And almost all commands in Arduino end with the semicolon. We have now given our first command. We're going to execute it one time because it's in the void setup. It's just going to be telling Arduino, hey, we're working with pin 13. It's going to be an output. All right.
So this is set up for the first program. Now let's go down to the void loop. Huh. We're connected to that LED.
What would be neat if we did to that LED? Turn it on. We want to turn the LED on.
So how would we turn the LED on? Well, we've got to send a signal, and the command is digital write. Again, case is important. Digital is all lowercase. The first letter of the next word, W, is capitalized.
So digital write. This is called bumpy font, where the first letter of the words are capitalized because you don't want to use spaces. And so you can kind of read it better digital right. But notice that if I did it wrong digital right and capitalized wrong, we don't get the happy little orange color.
So if it doesn't light up, you know you've done something wrong. Ah, I didn't capitalize the W. W-R-I-T-E. Okay.
We have to give it, again, two parameters. We've got to open. Hmm. What pen are we going to write to?
that's the first parameter. Pin 13 And then second, do we want to turn it on or do we want to turn it off? Well, we want to turn the LED on, so the command that we would give the parameter we would use is high. We're going to set it.
High means 5 volts. We're going to set pin 13 to 5 volts. So I type in HIGH, all caps.
When I do it in all caps, it's happy. It turns blue. If you do this, you see no happy, no blue. So you've got to get your case right. High.
What do we do at the end of almost every command in Arduino? The semicolon. Boom. Okay, so what does this do in the Void setup?
It tells the Arduino that we will be using pin 13. It's going to be an output, and then in the loop we say, hey, take pin 13, turn it high. That should turn the LED on. Now, right now this program is here in your PC. We now want to send it down through the USB cable down. into the Arduino.
And you do that with this little arrow here, this little right arrow. You're going to click on that and then it's going to send your code down into your Arduino. So when I click on that, I look here and I get a happy little green bar, meaning that it's recognizing the commands, it's compiling it.
And when that green bar goes away, it means the program is down in the Arduino. And look what happened here on the Arduino. Boom! The LED turned on.
You have written your first program and you have controlled an item. You have turned an LED on. Maybe we should write a second program. What should the second program do? Turn the LED off.
I want you to guess. If Hyde turned it on, what do you think would turn it off? Low.
L-O-W. All. upper case. So now how do we download the program into the Arduino?
We come up to this little right arrow. We click on the right arrow. Boom, it goes down. And what happens? The LED was turned off.
You have written your second program. You can turn the LED on. You can turn the LED off.
Well, if you hooked other things up to pin 13 already today, you could be turning them on and off. And so even though this is really simple, it's very, very powerful. Now I want you to think, let's turn it back on.
So I'm going to go back high. OK, high, download it, and the LED is on. OK, if I can turn the LED on and I can turn the LED off, what could I do in program three?
I can make it blink. How would you make it blink? Well, you digital write 13 high, and then you have a new command, digital. Digital, right.
What pin are we working with? 13. And now we want to make it go low. So we're going to turn it on and off, and then it should blink.
So we come up, we download the program, and it goes. Ooh, wait a minute. It's not blinking.
No blinky. OK. Hmm, what could be wrong? All right.
think about this does a computer do things quickly or does the computer do things slowly it does it quickly very quickly so what are you doing with this program that you just wrote you're turning it on and off so quickly your eye cannot perceive that it's blinking it just looks like it's kinda dim okay and so the problem is you're blinking it so fast that you can't see it so you need a new command what command do you need You need to be able to put a delay in your program, where you turn the LED on, you delay, you turn the LED off, you delay. So let's add another command after the turn it on. What do we want to do? We want to delay.
The command is, wait for it, delay. Spell it right, you get the happy orange. Open parentheses, we've got to give it one parameter, and that's how many milliseconds you want to delay.
Okay? There's 1,000 milliseconds in a second, so if we want to leave it on for one second, that would be how many milliseconds? 1,000 milliseconds is one second.
Don't forget the semicolon. Okay? So we turn it on, we wait 1,000. We turn it off, and what should we do? Wait 1,000.
So what is this going to do? Turn the LED on. for a second, turn it off, wait a second, turn it on, wait a second, turn it off, wait a second. So it should be a pretty slow blink here.
How do we get this most excellent program down into the Arduino? We click the right arrow, we watch our little LED, and look at that off, on, off, on. It's blinking exactly like we told it to, okay?
Now do we have to blink balance like that? No. Let's leave it on for a tenth of a second and then let's leave it off for nine tenths of a second so the duty cycle is going to be one second but this the LED is going to be on for a tenth and off for a nine tenths what would a tenth of a second be well a thousand milliseconds is one second so a tenth of a second would be a thousand divided by ten which is a hundred and then we want it to be off for nine hundred So still, the duty cycle is going to be one second, but it's going to be on off, on off, on off, like that.
Okay, so let's download it and let's see what happens. On off, on off, on off. Okay, let's do it the other way. Let's have it mostly on.
900 on, 100 off. Let's download that. So this is going to be on, off, on, off, on, off, on, off.
You see, it's mainly on. It's mainly on. I might have messed that up a little bit, but I'm sorry.
All right. So hopefully yours is doing that. Man, you've written your first three programs, and it's just your first lesson, and you've already written three programs.
Okay. Let me give you a couple of assignments. I want you to, first of all. What I want you to do is I want you to write a program where it will blink fast.
And I want you to see how quickly you can make it blink where your eye still perceives that it's blinking. OK, so let's say let's say if I put 500 and 500, that's a half a second on and a half a second off. All right. And then if I look at it, I can clearly see that that's blinking. But as you make that number smaller and smaller, you're going to reach a point that your eye cannot perceive that it's blinking.
And it's just going to look like a constant, maybe somewhat dim LED. So what I want you to do is I want you to do that experiment and see how low you can make this number, how fast you can make it blink. You've got to change both of them. and still perceive that it's blinking and then put your results down in the comments.
And let's see if you guys are getting similar answers as far as your eye perceiving that the thing is blinking versus it just looks like it's constant. Okay, guys, this is Paul McWhirter from TopTechBoy.com. If you like this video, give us a thumbs up.
Think about subscribing to the channel, maybe sharing it with people. If you haven't already, get your kit and follow along with me. Leave your comments down below.
Really love to hear from you guys. Love to get your comments and your feedback. So hopefully you will do that. This is Paul McWhorter from toptechboy.com. I will talk to you guys later.