https://www.automationdirect.com/adc/home/home
(VID-BS-0008) Learn how to program an embedded processor so you can create your own electronic gadgets!
AutomationDirect donated time and equipment for the creation of these Boy Scouts of America Merit Badge videos.
think about it almost every electronic gadget you touch these days has a little itty bitty computer chip in it telephones digital cameras bluetooth earphones game controllers thermostats in your house coffee pots your computer mouse even your family car has dozens of these little computers controlling the anti-lock brakes radio windows air conditioning well you get the idea these little computers which we call embedded processors because they're embedded in the device are everywhere and in the next 10 minutes you are going to learn how easy it is to program one the one we're going to use is called an arduino and it's very popular because the software is free and the hardware is really inexpensive the arduino we're using here is available at radioshack for only 29 bucks in this video you'll program it to simply blink an led on and off then make it blink faster and then control the blinking with a switch input and given just those basic skills you'll be ready to go create your own new electronic gadget so let's get started your arduino board should be connected and the yellow led should be blinking one second on one second off this is being done by the blink program or sketch as they're called in arduino speak we see in here that there's a setup section and a loop section the arduino will execute everything in this setup section once when the arduino is turned on here we tell the arduino that pin 13 which we defined right here led equals 13 should be an output that's the pin number that the blinking led is connected to on this board if we needed to set up other pins we could do that in here also everything in this loop section gets run over and over and over again as fast as the processor can go in this program or sketch we turn on pin 13 by writing a high to pin 13 we wait one second or a thousand milliseconds then we write a low to pin 13 then we wait another thousand milliseconds and that gets repeated over and over and over again so we have an led that turns on and off on and off just like that now merit badge requirement 5a says take an existing program and modify it well let's modify this one to make the led blink faster well that's easy we just make this weight between led transitions shorter right let's make it uh if that was a thousand milliseconds let's only weight 250. that should run four times as fast we change it up there and we change it again down here now the light will turn on it'll wait only a quarter of a second then it'll turn off wait a quarter of a second turn back on repeat to download our new program which brings the led faster to the board just hit this arrow right here the program is downloaded to the board and if it's successful you see a message like this but more importantly if you look down at the board the yellow led is blinking a lot faster now isn't it now there's a note in the front of the merit badge book that defines what a program is for the purposes of this merit badge that is a program needs to have an input make a decision based on that input and then have some kind of output based on that decision we could consider waiting for this time to be kind of an input and we certainly have an output the led but we don't have any decision making do we so let's add something how about a switch that we can press to enable the blinking led when the switch is pressed we want the led to blink when it's not pressed we want the led to be off i'm using a couple parts from kits we got from radio shack but you can use whatever you want here's how it's wired the switch connects ground or logic low over here to pin 7 on your arduino so step one in the setup section we need to tell the arduino that we want that pin 7 to be an input pin that's pulled up that's because when we press the button it'll connect the pin to ground or low pause the video and type this line exactly as you see it down here in the loop section we want to read that pin and if it's low we want the led to blink if it's high we want the led to be off well that's easy we put an if statement in here and we say if when we read the digital pin 7 that's equal to a low then i want to do everything that's inside these brackets otherwise do everything inside of these brackets and let's see if the if the button is being pressed which is a low we're going to blink the leds over and over and over again if the button is not pressed then we just want the led to be off so i'm going to copy this guy put them right here and it says do a digital write to the led pin and force them to be a low and just to clean things up here a little bit i'm going to put a couple tabs in so it's real obvious if this condition is true if the button is pressed we're going to blink the led if it's not pressed we're going to turn it off go ahead and pause the video and add the if statement the two braces the else two more braces and then copy this statement down to here make it look exactly like this with the semicolons pause the video enter all this code and resume when you're ready okay well if we did it right we should be able to try and see what happens let's hit the button to download the program to the arduino i didn't get any error messages and if i look down at my board i see the led is not on right now but if i reach over and push the button sure enough i get my fast blinking led back let go my button the led turns off exactly what we expected now we have a program that has an input the switch in this example we make a decision based on that switch using this if statement and we have an output the led which is either toggling or it's just off perfect now let's try the opposite make the led blink when the button is not pressed but stop the blinking when the button is pressed how would you do that well it's the exact same thing except now if we read pin seven where the switch is and he's a high then make the leds blink otherwise turn him off go ahead and pause the video make that change yourself download the program and see if after you do that the led's blinking but when you press the button the led turns off well that's a good start on programming arduino embedded controller now understand we just barely scratched the surface with this little example there are tons of things you can do with these just look at all the examples that come with it these are already done for you got basics digital you can read analog things in like temperatures communications sensors all kinds of stuff you can do plus there are thousands of projects on youtube and google just do a search and you'll be amazed at all the fun things you can do now that you know how to program an embedded processor like the arduino and hopefully now when you look at a toy with a blinking light or a switch on it you'll be able to think hey i know how to do that you
Voted #1 mid-sized employer in Atlanta
Check out our
job openings