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: Nano USB cable
1 Double-click on the Arduino icon to start the Arduino IDE program.

Click here for fast track, or continue on to step 2.
Arduino icon
2 Create a new program by selecting File from the menu
  • then select Examples
  • then select Basics
  • then select BareMinimum
Bare minimum
3 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 slashed // are comments, and they are ignored by the computer.
BareMinimum template
4 There is a built-in light (LED) on the Arduino board that is connected to digital I/O pin 13. Nano digital I/O pins and built-in LED
5 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
6 Connect your Arduino board to your computer using the USB cable. USB cable
7 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 greater than 3.
If you don't see one, then you need to follow these instructions to install the driver.
selecting COM port
8 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
9 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
10 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.
11 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
12 Upload the program again. What do you see? --- The LED turns on for 1 second and then it turns off.
13 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
14 Upload the program again. What do you see? --- The LED just stays on. Why?
15 We need another delay command after turning off the LED before it repeats the loop to turn the LED on again. blink
16 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.