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:
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:
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.
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.
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.
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:
The loop() function runs repeatedly after setup() has finished.
Everything inside this function will continue executing as long as the Arduino is powered.
The result is:
ON → 1 second → OFF → 1 second → ON → 1 second → OFF → ...
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.
Change:
Can you modify the program so that the LED:
In this project, you learned the fundamentals of controlling an electronic component with an Arduino.
You learned how to:
Although blinking an LED is a simple project, the concepts introduced here are fundamental to many larger Arduino and embedded-systems projects.
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.
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.
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.
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
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.
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.
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.
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.
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:
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.
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:- Connect your Arduino Uno to your computer using the USB cable.
- Select the correct board.
- Select the correct port.
- Click Verify to compile the sketch.
- If the sketch compiles successfully, click Upload.
- Wait for the upload to finish.
- Observe the LED connected to digital pin D9.
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:
to:
delay(500);
The LED will change state every 0.5 seconds, making it blink faster.
Try:
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:
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.
The LED will remain ON and OFF for approximately two seconds at a time.
Challenge
Can you modify the program so that the LED:
- Blinks twice quickly.
- Remains OFF for two seconds.
- Repeats the pattern continuously?
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:
and:
pinMode(ledPin, OUTPUT);
Also verify that the LED is actually connected to D9.
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
Post a Comment