Skip to content
FLAVIO COPES
flaviocopes.com
2026

Arduino project: blink a LED

By Flavio Copes

Build your first Arduino project: blink a LED. You will wire a circuit and write a program with pinMode, digitalWrite, and delay, then upload it via USB.

~~~

I introduced Arduino in Introduction to Arduino.

In this tutorial I want to build the first Arduino project. We’ll turn a LED light ON and OFF.

You will learn how to create your first Arduino program, upload it to the Arduino board via USB, and how to write to a digital I/O pin.

It’s a very simple project, but you’ll learn a lot of stuff about Arduino if it’s your first time.

I will do the tutorial using an Arduino Uno rev 3 clone board.

If you already have an Arduino board, you can use the one you’ve got. The important thing to note here is that the board should work at 5V I/O pins.

Some boards, for example the Arduino MKR WiFi 1010, works exclusively with 3.3V I/O pins. If that’s your board, there’s no problem but take in mind there’s this difference in voltage.

Here’s the board:

Arduino Uno Rev 3 board on wooden surface showing blue PCB with USB-B port and power jack

We can power it with a USB-B port, or a battery (a 9V battery works great, as the recommended input voltage is 7-12V):

Side view of Arduino board showing USB-B port on left and barrel power jack on right

We have a set of power pins and analog I/O pins on one side:

Arduino power and analog pins section showing IOREF, RESET, 3.3V, 5V, GND, VIN pins and A0-A5 analog inputs

And a set of digital I/O pins on the other side:

Arduino digital pins section showing pins 0-13 labeled as DIGITAL PWM with USB-B connector visible on right

Let’s build a simple circuit that lights a LED. We use a 1kΩ resistor, a yellow 5mm LED, and we connect it to - and + as usual:

Breadboard circuit with yellow LED and blue resistor connected by black and red wires

The + and - are connected to the power pins of the Arduino that serve 5V and GND:

Complete Arduino circuit setup with board connected to breadboard LED circuit and 9V battery via red and black wires

As you can see, the LED turns on when we power the Arduino with a battery:

Breadboard with illuminated yellow LED connected to blue resistor showing the circuit in working state

Now in this circuit Arduino doesn’t do anything useful other than scaling the 9V in the input provided by the battery to 5V.

Let’s make the LED blink by writing our first Arduino program.

To do so, we must first install the Arduino IDE on our computer.

Go to https://www.arduino.cc/en/software and select your operating system version:

Arduino IDE download page showing version 1.8.13 with download options for Windows, Linux and Mac OS X

After the software is downloaded, on macOS you need to move the Arduino app to your Applications folder. Check the Windows and Linux installation instructions.

Start the program and you should see a blank program:

Arduino IDE interface showing empty setup and loop functions with default comments

As mentioned in the introduction to the Arduino Programming Language tutorial, the setup() function is executed once, right after the program starts, and it’s where we usually set up the pin modes for example.

The loop() function is executed continuously in a loop, forever.

In our program we’ll first set the digital I/O pin number 13 as an output pin:

#define LED_PIN 13

void setup() {
    // Configure pin 13 to be a digital output
    pinMode(LED_PIN, OUTPUT);
}

Then in loop() we tell our Arduino to write a HIGH level of tension (5V), wait 1 second, write a LOW level of tension (0V = ground) and wait 1 second, then repeat forever:

void loop() {
    digitalWrite(LED_PIN, HIGH);
    delay(1000);
    digitalWrite(LED_PIN, LOW);
    delay(1000);
}

HIGH and LOW are constants available by default in our Arduino programs.

digitalWrite() writes a HIGH or LOW value to a specific digital output pin. You pass the pin number and HIGH or LOW as parameters.

delay() pauses the program for a number of milliseconds specified as parameter.

The first time you start the program you might have to choose the Arduino board on the Tools -> Port menu.

Make sure the Arduino is connected to the computer.

I use a MacBook Pro with USB-C ports, and the Arduino has a USB-B port, so I use an adapter.

Before you can compile the program and write it on the Arduino you need to save the file. You can save it anywhere you like. I created an Arduino folder in my Documents folder, and there is where I store all the Arduino programs I write.

Click the Upload button (the one with a right arrow in it) and the program should be compiled and installed on the Arduino. The LED should start blinking.

Arduino IDE showing completed blink program with LED pin setup, digitalWrite HIGH/LOW commands and Done uploading message

Now if you disconnect the USB cable from the computer, you will see the LED will turn off because the Arduino is no longer powered.

But if you connect the USB cable to a normal USB charger, the LED will blink. The computer is no longer needed. The Arduino runs the program we loaded, just this program, no other software is running.

And as soon as it’s powered, the program starts and runs.

Tagged: Arduino · All topics
~~~

Related posts about electronics: