Arduino LED Blink Tutorial – How to Blink an LED Using Digital Pin 2

 

Introduction

One of the first projects every Arduino beginner learns is the LED Blink project. It is simple, easy to understand, and helps you learn the basics of programming and controlling electronic components using an Arduino board.

In this tutorial, we will connect an LED to Digital Pin 2 of an Arduino Uno and make it blink continuously.


Components Required

  • Arduino Uno

  • LED

  • 220Ω Resistor

  • Breadboard

  • Jumper Wires

  • USB Cable


Circuit Connection

Connect the components as follows:

  • Arduino Digital Pin 2 → 220Ω Resistor → LED Positive (Long Leg)

  • LED Negative (Short Leg) → Arduino GND

The resistor is important because it limits the current flowing through the LED and protects it from damage.


Arduino Code

const int ledPin = 2;
void setup() {
  pinMode(ledPin, OUTPUT);
}
void loop() {
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
}

Code Explanation

1. Define the LED Pin

const int ledPin = 2;

This line tells Arduino that the LED is connected to Digital Pin 2.

2. Setup Function

pinMode(ledPin, OUTPUT);

The setup() function runs only once after the Arduino is powered on or reset. Here, Pin 2 is configured as an output.

3. Turn the LED ON

digitalWrite(ledPin, HIGH);

This sends a HIGH signal (5V) to Pin 2, turning the LED on.

4. Wait

delay(1000);

The program waits for 1000 milliseconds (1 second).

5. Turn the LED OFF

digitalWrite(ledPin, LOW);

This removes the voltage from Pin 2, turning the LED off.

6. Repeat Forever

The loop() function repeats continuously, causing the LED to blink every second.


Expected Output

After uploading the program:

  • The LED turns ON for 1 second.

  • The LED turns OFF for 1 second.

  • This process repeats continuously.


How to Change the Blink Speed

To make the LED blink faster:

delay(200);

To make it blink slower:

delay(2000);

Simply change the value inside the delay() function according to your requirement.


Conclusion

The LED Blink project is the perfect starting point for learning Arduino programming. It introduces important concepts such as digital output, variables, functions, and timing using the delay() function. Once you understand this project, you can move on to more advanced projects involving sensors, displays, motors, and IoT applications.

Comments

Popular posts from this blog

Basic Arduino Light System (LED ON/OFF)

Arduino Uno Connection Test – How to Verify Your Board is Working