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: Arduino USB cable
1 If the Arduino IDE program has not been installed on your computer, you can click here to download and install the program. Otherwise, go to step 2.
2 Double-click on the Arduino icon to start the Arduino IDE program.

Click here if you are using the Arduino Nano instead of the Uno.
Click here for fast track, or continue on to step 3.
Arduino icon
3 Create a new program by selecting File from the menu
  • then select Examples
  • then select Basics
  • then select BareMinimum
Bare minimum
4 You will see this Bare Minimum template.







Commands that you put inside the void setup() routine are executed only once on startup or on reset.

"Inside" means between the two curly brackets { and }.


Commands that you put inside the void loop() routine are executed repeatedly forever (or until you turn off the power)


Lines starting with the two slashes // are comments, and they are ignored by the computer. In other words, to save time, you don't need to type anything that follows the two slashes.

Comments are there to tell you what the code is doing.
BareMinimum template
5 There is a built-in light (LED) on the Arduino board that is connected to digital I/O pin 13. Arduino digital I/O pins and built-in LED
6 To control the LED we need to issue two commands to the Arduino:







First, we use the pinMode command to tell the Arduino that we will be controlling the LED that is connected to pin 13 for OUTPUT.

Second, we use the digitalWrite command to send a HIGH signal to pin 13.
HIGH means to turn on the LED.

Type in these two commands inside the void setup() routine as shown.
commands to turn on LED
7 Connect your Arduino board to your computer using the USB cable. USB cable
8 From the Arduino IDE program menu, select Tools
  • then select Serial Port
  • then select the COM port that your Arduino is connected to. This usually is the COM port with the largest number.
If you don't see one, then you need to follow these instructions to install the driver.
selecting COM port
9 Press the upload button to upload the program onto the Arduino board. Upload icon

If the upload is successful you should see the words Done uploading at the bottom, and the Arduino will automatically run the program.


You should see the LED on the Arduino board turned on.

Done uploading

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 the error(s) and then upload your program again.

COM port error
10 To make the LED blink, we need to turn on and then turn off the LED.










To turn off the LED, we use another digitalWrite command, but this time we send a LOW signal instead.
LOW means to turn off the LED.
commands to turn on and off LED
11 Upload the program again. Did you see the LED blink? --- NO

You only see the LED off because the Arduino executed the two digitalWrite commands (one to turn on the LED followed by the one to turn off the LED) so fast that you can't even see it when it is turned on for a fraction of a second.
12 To keep the LED on a little longer so that you can see it, we need to use the delay command to make the Arduino wait a bit before continuing.









The number specified in the delay command is the number of milliseconds to wait.

1000 ms = 1 sec
delay
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 keep repeating the on and off sequence.













To do that, you move the two digitalWrite commands and the delay command from the setup() routine to the loop() routine. Remember that commands inside the loop() routine are executed repeatedly forever.
half blink
15 Upload the program again. What do you see? --- The LED just stays on. Why?
16 We need another delay command after turning off the LED before it repeats the loop to turn the LED on again. blink
17 Upload the program again. This time you'll see the LED blink on for 1 second and then off for 1 second.


Congratulations! You've completed your first Arduino project to make a LED blink!

Now click on the Experiments button below to test yourself. After you have finished the experiments, come back here and click on the Next Project button to learn how to make music in the next project.