Index
Introduction
The “Hello World” of Arduino programming is the LED Blink example. This simple program makes an LED on the Arduino Uno blink on and off, helping beginners understand basic programming structure and upload code to the board.
Objective:
Create a program that blinks an LED on and off every second.
Required Components:
- Arduino Uno (or any Arduino board with a built-in LED on pin 13)
Note: Most Arduino boards have a built-in LED connected to digital pin 13, so you won’t need any external components for this example.
Code Structure in Arduino
An Arduino sketch (program) has two main functions:
setup()
: Runs once when the program starts.loop()
: Runs repeatedly aftersetup()
completes.
Code:
void setup() {
// Initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
void loop() {
// Turn the LED on by making pin 13 HIGH
digitalWrite(13, HIGH);
// Wait for 1 second (1000 milliseconds)
delay(1000);
// Turn the LED off by making pin 13 LOW
digitalWrite(13, LOW);
// Wait for 1 second
delay(1000);
}
Code Explanation
- setup() Function:
- This function runs once when the Arduino is powered on or reset.
pinMode(13, OUTPUT);
tells the Arduino to set pin 13 as an OUTPUT pin because we want to control an LED connected to it.
- loop() Function:
- This function runs continuously, over and over, as long as the Arduino is powered on.
digitalWrite(13, HIGH);
turns the LED on by sending HIGH (5V) to pin 13.delay(1000);
pauses the program for 1 second (1000 milliseconds).digitalWrite(13, LOW);
turns the LED off by sending LOW (0V) to pin 13.delay(1000);
pauses the program again for 1 second, so the LED stays off before the cycle repeats.
How to Upload the Code
- Connect the Arduino to your computer via USB.
- Open the Arduino IDE and paste the code into the editor.
- Select the Board and Port:
- Go to Tools > Board and choose Arduino Uno (or your specific board).
- Go to Tools > Port and select the port connected to your Arduino.
- Upload the Code:
- Click the Upload button (right arrow) in the Arduino IDE.
- After compiling, the code will be uploaded to your Arduino.
Result:
Once uploaded, the LED connected to pin 13 will blink on for 1 second, then off for 1 second, repeatedly. This introduces the basic structure of an Arduino program and how to upload it to the board.
This is a foundational program that helps beginners become comfortable with writing code, configuring pin modes, and controlling hardware through simple digital output.