Code with Step-by-Step Explanation

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Course Content
Introduction
The Blink LED project is the “Hello World” of Arduino. Just as a beginner programmer’s first task is to make a computer print “Hello World,” in electronics the first step is making an LED blink. This project helps you understand the three most important concepts in Arduino programming and electronics: 1. Digital Output – how a microcontroller pin can send a HIGH (5V) or LOW (0V) signal. 2. Timing Control – using the delay() function to pause the program. 3. Circuit Control – connecting a simple circuit with a resistor and LED, and controlling it through code. By completing this project, you will learn how hardware (the LED circuit) and software (the Arduino code) work together. This forms the foundation for controlling sensors, motors, and other components in future projects.
Hardware Required
Arduino Uno (or compatible board) • 1 × LED (any color, 5mm) • 1 × 220Ω resistor (limits current, prevents LED damage) • Breadboard • Jumper wires • USB cable (to connect Arduino to computer) (Tip: If you don’t have these, you can use the onboard LED already connected to pin 13 on most Arduino boards.)
0/3
Hello LED – Blinking with Arduino

After you build the circuit, plug your Arduino board into your computer, start the Arduino Software (IDE), and enter the code below. You may also load it from the menu:

File → Examples → 01.Basics → Blink.

Code

/*

Blink

*/

Turns an LED on for one second, then off for one second, repeatedly.

// Create a variable for the LED pin

int ledPin = 13; // Built-in LED pin on most Arduino boards

void setup() {

// This runs once when you power or reset the board

// Initialize pin 13 as an output pin

pinMode(ledPin, OUTPUT);

}

void loop() {

// This runs continuously in a loop

digitalWrite(ledPin, HIGH); delay(1000); // Turn LED on (apply 5V)

// Wait 1 second (1000 ms)

digitalWrite(ledPin, LOW); delay(1000); // Wait 1 second

// Turn LED off (apply 0V)

}

Line-by-Line Explanation

int ledPin = 13; → Defines the LED pin. Pin 13 is chosen because Arduino boards have an onboard LED

connected there.

void setup() → Runs once at startup. The first thing you do is to initialize the LED pin as an output using:

pinMode(LED_BUILTIN, OUTPUT);

This allows the Arduino to send current to the LED.

void loop() → Runs forever in a cycle.

  • digitalWrite(ledPin, HIGH); → Supplies 5 volts to the LED’s anode. That creates a voltage difference across the LED and lights it up.
  • delay(1000); → Waits for 1 second so the LED stays visibly ON.
  • digitalWrite(ledPin, LOW); → Brings the pin back to 0 volts, turning the LED off.
  • delay(1000); → Waits for another second with the LED OFF.

This sequence repeats endlessly, causing the LED to blink every second.