Skip to main content

How to Blink an LED with Arduino Uno - Beginner Tutorial

Learn how to make an LED blink using an Arduino Uno R3, a 220 Ω resistor, and a simple Arduino sketch.

Hello everyone!

If you are familiar with programming, you have probably encountered the classic “Hello, World!” program. It is traditionally one of the first programs used to introduce programming because it demonstrates how a computer can execute a simple instruction.

In physical computing, blinking an LED is often considered a similar first step. It introduces the fundamental idea of using software to control physical hardware.

In this project, we will connect an external LED to an Arduino Uno R3 and program it to turn ON and OFF repeatedly.


By the end of this tutorial, you will understand how to:
  • Connect an LED safely to an Arduino.
  • Use a resistor to limit current.
  • Configure a digital pin as an output.
  • Turn an LED ON and OFF using digitalWrite().
  • Control timing using delay().
  • Compile and upload an Arduino sketch.

What You Need

For this project, you will need:
  • Arduino Uno R3
  • 1 × LED
  • 1 × 220 Ω resistor
  • Solderless breadboard
  • Jumper wires
  • USB cable
  • Computer with the Arduino IDE installed

Understanding the LED

LED stands for Light Emitting Diode. It is a semiconductor device that emits light when current flows through it in the appropriate direction.

An LED is a type of diode, which means it has polarity. Therefore, it must be connected in the correct direction.

For a typical through-hole LED:
  • Longer leg → Anode (+)
  • Shorter leg → Cathode (−)
  • Flat edge of the LED body → Usually indicates the cathode

In this project, the anode will be connected to Arduino digital pin D9 through a 220 Ω resistor, while the cathode will be connected to GND.

Why do we need a resistor?

The 220 Ω resistor limits the current flowing through the LED.

A resistor is important because connecting an LED directly to an Arduino digital output can allow excessive current to flow, potentially damaging the LED or the Arduino's I/O pin.

Setting Up the Hardware

Circuit Connections

Connect the components as follows:
  • Arduino D9 → 220 Ω resistor
  • 220 Ω resistor → LED Anode (+)
  • LED Cathode (-) → Arduino GND

The complete connection is:

D9 → 220 Ω resistor → LED anode → LED cathode → GND

Make sure the LED is inserted into the breadboard correctly and that its polarity is not reversed.

Circuit Diagram



Programming the Arduino

The Arduino IDE includes a built-in Blink example that can be accessed through:

File → Examples → 01.Basics → Blink

The original Blink example is designed around the board's built-in LED, so because our external LED is connected to D9, we need to modify the program accordingly.

For this project, use the following sketch:

const int ledPin = 9; 

void setup() { 
pinMode(ledPin, OUTPUT); 
} 

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


Understanding the Code

Let's look at the program step by step.

1. Defining the LED Pin


const int ledPin = 9;

This creates a constant named ledPin and assigns it the value 9.
This tells our program that the external LED is connected to digital pin 9.
Using a descriptive name such as ledPin makes the code easier to understand than repeatedly writing the number 9.

2. The setup() Function


void setup() { 
pinMode(ledPin, OUTPUT); 
}

The setup() function runs once when the Arduino starts or resets.
The pinMode() function configures the LED pin as an output:pinMode(ledPin, OUTPUT);
Because the Arduino needs to control the LED, pin 9 must be configured as an OUTPUT.

3. The loop() Function

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

The loop() function runs repeatedly after setup() has finished.
Everything inside this function will continue executing as long as the Arduino is powered.

4. Turn the LED ON

digitalWrite(ledPin, HIGH);

The digitalWrite() function changes the state of a digital output.
Setting the pin to HIGH causes the Arduino to provide a high output level on pin 9, turning the LED ON.

5. Wait for One Second

delay(1000);

The delay() function pauses the program for a specified amount of time.
The value is measured in milliseconds.

Therefore:

1000 milliseconds = 1 second

The Arduino waits for approximately one second while the LED remains ON.

6. Turn the LED OFF

digitalWrite(ledPin, LOW);

Setting the pin to LOW turns the LED OFF.

The program then waits for another second:

delay(1000);

After this delay, the loop() function starts again.

How the Program Works

The Arduino repeatedly performs the following sequence: 

START 
↓ 
LED ON 
↓ 
Wait 1 second 
↓ 
LED OFF 
↓ 
Wait 1 second 
↓ 
Repeat 
↺

The result is:

ON → 1 second → OFF → 1 second → ON → 1 second → OFF → ...

Uploading the Program

Once you have entered the code into the Arduino IDE:
  1. Connect your Arduino Uno to your computer using the USB cable.
  2. Select the correct board.
  3. Select the correct port.
  4. Click Verify to compile the sketch.
  5. If the sketch compiles successfully, click Upload.
  6. Wait for the upload to finish.
  7. Observe the LED connected to digital pin D9.
Make sure the Arduino is connected to your computer before attempting to upload the sketch.

Final Result

After successfully uploading the program, the LED should:

Turn ON → stay ON for approximately 1 second → turn OFF → stay OFF for approximately 1 second → repeat continuously.

If your LED is blinking, congratulations!
You have successfully completed your first Arduino project.

Experiment: Change the Blink Speed

Now let's modify the program and see what happens.

Change:

delay(1000);

to:

delay(500);


The LED will change state every 0.5 seconds, making it blink faster.

Try:

delay(200);


The LED will blink even faster.

You can also try:

delay(2000);


The LED will remain ON and OFF for approximately two seconds at a time.

Challenge


Can you modify the program so that the LED:
  1. Blinks twice quickly.
  2. Remains OFF for two seconds.
  3. Repeats the pattern continuously?
Try solving the challenge yourself before looking for a solution.

Troubleshooting

The LED does not light up

Check the following:
  • Make sure the Arduino is powered.
  • Check that the LED is connected with the correct polarity.
  • Make sure the LED's anode is connected toward D9 through the resistor.
  • Make sure the cathode is connected to GND.
  • Check that the resistor is connected correctly.
  • Check that the jumper wires are firmly inserted.

The LED does not blink

Make sure the program contains:

const int ledPin = 9;

and:

pinMode(ledPin, OUTPUT);

Also verify that the LED is actually connected to D9.

The program will not upload

Check that:
  • The USB cable is connected correctly.
  • The correct Arduino board is selected.
  • The correct port is selected.
  • The Arduino IDE does not report a compilation error.
  • The Arduino is properly connected to the computer.

What You Learned


In this project, you learned the fundamentals of controlling an electronic component with an Arduino.

You learned how to:
  • Connect an LED to an Arduino.
  • Identify LED polarity.
  • Use a resistor to limit current.
  • Configure a digital pin using pinMode().
  • Control an LED using digitalWrite().
  • Create a time delay using delay().
  • Compile and upload an Arduino sketch.
  • Modify a program to change its behavior.

Although blinking an LED is a simple project, the concepts introduced here are fundamental to many larger Arduino and embedded-systems projects.

Going Further


The delay() function is simple and useful for learning how timing works. However, it pauses the execution of the program during the delay.

As your Arduino projects become more advanced, you may need the Arduino to perform several tasks at the same time. In those situations, a non-blocking timing technique such as millis() can be more appropriate.

Arduino provides another example called Blink Without Delay, which is a useful next step after completing this project.

Conclusion


Blinking an LED is a small project, but it introduces one of the most important concepts in physical computing:

software can control physical hardware.

You have now written a program that tells an Arduino exactly when to turn an electronic component ON and OFF.

From here, you can move on to projects involving buttons, sensors, buzzers, displays, motors, and robotics.

This is only the beginning of your Arduino journey.

What's Next?

In the next project, we will introduce an input component and learn how an Arduino can respond to a user's actions.

Stay tuned for more Arduino, electronics, robotics, and embedded-systems projects from RRRTechSolv.

If you have any questions about this project, feel free to leave a comment below.




Comments

Popular posts from this blog

Arduino Serial Communication Beginner Guide (UART Explained)

Serial communication is the backbone of most Arduino projects. It allows your Arduino to talk to your computer, Bluetooth modules, Wi-Fi modules, sensors, and even other Arduinos. If you have ever used the Serial Monitor, you have already used serial communication - now you will understand how it really works. By the end of this guide, you will learn: What serial communication is What UART means How Arduino communicates with devices How to send and receive data How baud rate works Common mistakes beginners make What is Serial Communication? Serial communication is a method of sending data one bit at a time over a single wire. Instead of sending many bits simultaneously (parallel communication), serial sends bits sequentially: Example: The letter A in binary = 01000001 These bits are sent one after another very quickly. This method is: Simple Reliable Perfect for microcontrollers What is UART? UART stands for: Universal Asynchronous Receiver Transmitter It is the hardware ins...

How to Connect HC-06 Bluetooth Module with Arduino (Step-by-Step Beginner Guide)

Bluetooth communication is one of the easiest ways to make Arduino projects wireless. Once you understand how to use a Bluetooth module, you can build robots, home automation systems, and smartphone-controlled devices. In this tutorial, you will learn how to interface the HC-06 Bluetooth module with Arduino and send data wirelessly using your phone.    By the end of this guide, you will be able to: Understand how the HC-06 Bluetooth module works Configure the module using AT commands Safely connect it to an Arduino Send and receive serial data over Bluetooth Build the foundation for wireless Arduino projects Watch the Project Overview What is the HC-06 Bluetooth Module? The HC-06 is a Bluetooth-to-Serial module designed to add wireless communication to microcontrollers such as Arduino. It uses Bluetooth 2.0 (SPP - Serial Port Protocol), which means it behaves like a wireless serial cable. Whatever is sent from the phone appears in Arduino’s Serial Monitor and vice versa. ...

How to Use SoftwareSerial on Arduino (Connect Multiple Serial Devices)

In the previous tutorial, you learned how Arduino uses hardware serial communication through pins 0 (RX) and 1 (TX). That built-in serial port is mainly used to communicate with your computer through the USB cable and Serial Monitor . But here is the problem beginners quickly face: Many popular modules use serial communication, such as: Bluetooth modules ( HC-05 / HC-06 ) GPS modules GSM modules Wi-Fi modules ( ESP8266 ) Arduino Uno has only one hardware serial port. So how can we connect these modules while still using the Serial Monitor? The solution is SoftwareSerial . In this tutorial you will learn how to create additional serial ports using normal digital pins. By the end, your Arduino will be able to talk to multiple serial devices. What is SoftwareSerial? SoftwareSerial is a special Arduino library that allows digital pins to behave like RX and TX pins. This means Arduino can create extra serial ports using software instead of hardware. Hardware Serial vs Software Seri...