Blink - My First Arduino Project
In this project, you'll learn about the Arduino IDE programming environment and how to make a LED light blink.
Parts needed:
| ||
1 | If the Arduino IDE program has not been installed on your computer, you can click here for instructions on how to download and install the Arduino program. After installing the Arduino program and the driver, come back here and continue with step 2. | |
2 | Double-click on the Arduino icon to start the Arduino program. | |
3 | Create a new program by selecting File from the menu
and then select New.
You will see this template. You will be writing commands inside either the Commands that you put inside the "Inside" means between the two curly braces Commands that you put inside the Lines starting with the two slashes | |
4 | There is a built-in light (LED) on the Arduino board that is connected internally to digital I/O pin 13. | |
5 | To control this LED we need to issue two commands to the Arduino:
First, we use the Second, we use the Type in these two commands inside the A semicolon is placed after each command line; in this case the | |
6 | Connect your Arduino board to your computer using the USB cable. | |
7 | From the Arduino program menu, select Tools. On the Mac, the Tools menu is at the top left corner of the screen.
For Windows
| |
For Macs
| ||
8 | Click the Upload button (with the arrow pointing to the right) to upload the program onto the Arduino board. | |
If the upload is successful you should see the words Done uploading at the bottom, and the Arduino will automatically run your program. | ||
If you have selected the wrong COM port or if there are errors in your program, you will see an orange error message at the bottom. You'll have to correct ALL the error(s) and then upload your program again. Go back to step 5 and double check your work. | ||
9 | You should see this LED on the Arduino board blink several times and then stays on.
If you missed that or if you want to see it again then press the red reset button on the Arduino board to run the program again. After uploading a program or after pressing the red reset button, this LED will always blink several times at the beginning. This is caused by the initialization sequence and not from executing the commands in your program. You always ignore this initial sequence of blinks. What we are interested in is that this LED stays on afterwards because it executed the | |
10 | If we want to turn off the LED after turning it on, we add another
| |
11 | Click the Upload button to upload the program again.
Remember that you always need to press the Upload button everytime after you make some changes to your program. After the initial blinking sequence you should see the LED turn on very quickly and then turns off. Again, if you missed that or if you want to see it again then press the red reset button on the Arduino board to run the program again. The Arduino executes the commands very fast that's why the LED turned on just for a brief second from executing the first | |
12 | To keep the LED on a little longer so that you can see it, we need to use the
The number specified in the 1000 ms = 1 sec So to wait for 1 second, we put the number 1000 inside the | |
13 | Upload the program again. What do you see? --- The LED turns on for 1 second and then it turns off. | |
14 | To make the LED blink continuously, we need to tell the Arduino to keep repeating this on and off command sequence.
To do that, you move the two | |
15 | Upload the program again. What do you see? --- The LED just stays on. Why?
Because there's no delay after the digitalWrite LOW command and so the program goes back right away to the top of the loop and executes the digitalWrite HIGH command again. | |
16 | Solution, we need another
| |
17 | Upload the program again. This time you'll see the LED blink on for 1 second and then off for 1 second. | |
18 | If you like you can save your program by selecting File from the menu and then Save. Type in the name blink for this program.
Congratulations! You've completed your first Arduino project to make a LED blink! Now click on the Experiments button below to test yourself. | |