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: Software stuff you'll learn: 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 are inside the void setup() routine if they are placed between the open and close braces {  }. Do not put commands outside of the braces.

A semicolon is placed after each command line; in this case the pinMode and digitalWrite commands. Always remember to do this.
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 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
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 void setup() routine to the void loop() routine. Remember that commands inside the void loop() routine are executed repeatedly forever.
half blink
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 the loop goes back right away to the digitalWrite HIGH command.
16 Solution, 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.