One-sentence summary
Blink is the first program that turns the board’s built-in LED on and off at set intervals, and it teaches the pinMode, digitalWrite and delay commands.
Why it matters
When you start a new instrument, you usually play a single note first. Coding has a similar beginning: Blink. The goal is not to build a complex robot, but to make sure your code really runs on the board.
Blink looks small, but it shows three big things at once:
- That the code you wrote was uploaded to the board,
- That the board can control a pin,
- That it can manage time.
In the previous lesson you installed and explored the Arduino IDE. Now we will produce a real output in that environment. When an LED starts blinking, it means “code and hardware are now talking to each other.” Every lesson after this builds on that first bridge.
The structure of Blink: setup and loop
Every Arduino program has two basic parts. Blink has them too.
void setup()
The setup block runs once when the board powers on. Here we make our starting settings. For example, we decide whether a pin will be an input or an output here.
It is like preparing your desk before an exam: you place your pen, eraser and water once. You do not set them up again and again during the exam.
void loop()
The loop block runs over and over forever after setup finishes. When it reaches the end, it starts again from the top. Blink’s on-and-off work happens here.
It is like a swing: you push it, it comes back, you push again. This cycle does not stop until the board is turned off.
The built-in LED and pin 13
On most Arduino Uno boards, a tiny LED is soldered to pin 13. It usually has an L printed next to it. Thanks to this LED, we can test our first code without connecting any external parts. Instead of writing the pin number, we can also use the ready-made name LED_BUILTIN.
The full Blink sketch
The code below turns the built-in LED on for one second and off for one second.
// Blink program that turns the built-in LED on and off
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // make pin 13 an output
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on
delay(1000); // 1000 ms = 1 second wait
digitalWrite(LED_BUILTIN, LOW); // turn the LED off
delay(1000); // wait 1 more second
}
Line by line, what happens?
pinMode(LED_BUILTIN, OUTPUT);→ Sets pin 13 as an output. Output means we can send electricity out through this pin.digitalWrite(LED_BUILTIN, HIGH);→ Applies voltage to the pin (about 5 volts). The LED turns on.HIGHmeans “on.”delay(1000);→ Pauses the program for 1000 milliseconds, that is 1 second. The LED stays on during this time.digitalWrite(LED_BUILTIN, LOW);→ Cuts the voltage on the pin (0 volts). The LED turns off.LOWmeans “off.”- The last
delay(1000);→ Waits 1 second while the LED is off.
Because the loop block automatically starts again when it ends, the LED keeps blinking.
Changing the timing
The number inside delay is in milliseconds. 1 second = 1000 milliseconds. You can adjust the speed by changing this number.
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(200); // on for a very short time
digitalWrite(LED_BUILTIN, LOW);
delay(200); // off for a very short time
}
If you write 200, the LED blinks several times per second, so it blinks faster. If you write 2000, it slows down.
Connecting an external LED (variation)
After the built-in LED works, you can connect your own LED on the outside. Instead of connecting an LED directly to the Arduino, we must always use a resistor. The resistor limits the current and prevents the LED from burning out.
Parts you need
- 1 LED
- 1 resistor of 220 Ω or 330 Ω (current limiter)
- A breadboard and a few jumper wires
Wiring
- The long leg of the LED (plus, anode) → to pin 8 through the resistor.
- The short leg of the LED (minus, cathode) → to the Arduino’s
GND(ground) pin. - Place the resistor between the LED and the pin; which leg you place it on does not matter, what matters is that it is in the circuit.
Code
The logic of the code is exactly the same as the built-in LED; only the pin number changes.
int ledPin = 8; // external LED on pin 8
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
If the LED does not light up, first check the long/short leg direction. An LED only works in one direction.
Mini practice
Write your own “heartbeat” pattern. Make the LED blink twice quickly, then pause for a long time. Try these steps:
- Open the Blink code.
- Add two quick blinks inside
loop(usedelay(150)). - Put a long
delay(800)at the end. - Upload it to the board and watch the pattern.
Starter template:
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(150);
digitalWrite(LED_BUILTIN, LOW);
delay(150);
digitalWrite(LED_BUILTIN, HIGH);
delay(150);
digitalWrite(LED_BUILTIN, LOW);
delay(800); // long pause
}
Change the numbers until you like the pattern. There is no single right answer; the goal is to practise building rhythm with digitalWrite and delay.
Common mistakes
Forgetting pinMode
If you do not write pinMode(..., OUTPUT) inside setup, the pin is not set as an output and the LED may not work as expected. Every output pin must be set up first.
Forgetting the semicolon
In Arduino, every command line ends with ;. If you write delay(1000) without a semicolon, the code will not compile and will give an error.
Never using delay
Without delay, the LED blinks so fast that it looks like it is always on. You must add a pause to see the blinking.
Connecting an external LED without a resistor
Without a resistor, too much current flows through the LED. The LED can be damaged or the pin can be strained. Always use a current-limiting resistor with an external LED.
Connecting the LED backwards
An LED has a direction. The long leg goes to plus and the short leg goes to ground (GND). If you connect it backwards, the LED will not light at all.
Safety note
- Power the Arduino only with a USB cable or a low-voltage battery pack. Never experiment with mains (wall socket) electricity.
- When connecting an external LED, always use a current-limiting resistor (220–330 Ω). A connection without a resistor can damage the LED and the pin.
- Avoid short circuits by not touching bare legs and wires together. Unplug the USB before changing any connections.
- This lesson is only about LEDs. Parts like motors and pumps are not covered here; they need a separate power source and a driver circuit.
- If you are unsure about the connections on your first try, ask an adult for help. Checking the wiring together is the safest way.
Lesson summary
- Every Arduino program has a
setupblock that runs once and aloopblock that repeats continuously. pinMode(pin, OUTPUT)sets a pin as an output; we can send electricity from an output pin.digitalWrite(pin, HIGH)turns the LED on, anddigitalWrite(pin, LOW)turns it off.delay(ms)pauses the program in milliseconds; 1000 ms = 1 second.- When connecting an external LED, you need a current-limiting resistor and the correct leg direction.
Check questions
- How many times does the
setupblock run, and how many times does theloopblock run? - What is the job of the line
pinMode(LED_BUILTIN, OUTPUT);? - What is the difference between
digitalWrite(LED_BUILTIN, HIGH)andLOW? - If you write
delay(2000), how does the LED’s blinking speed change? - Why do we use a resistor when connecting an external LED?
Answers
setupruns only once when the board powers on, andloopruns over and over forever aftersetupfinishes.- It sets the given pin as an output, so we can send voltage out through that pin and drive the LED.
HIGHapplies voltage to the pin and turns the LED on;LOWcuts the voltage and turns the LED off.- Because
delay(2000)waits two seconds, the LED blinks more slowly (2 seconds in each state). - The resistor limits the current; without it, too much current flows through the LED and the LED or the pin can be damaged.
Source and verification note
For “First Code: Blink”, verification focuses on whether the relationship between The structure of Blink: setup and loop and void loop() remains consistent across examples. Pin, voltage and current limits can differ between Arduino-compatible boards. Compiling code does not guarantee a safe circuit; loads such as motors and servos require a suitable driver and external power where appropriate.
Next lesson
Digital Input and Output: We will control an LED with a button and learn to read information from the board with digitalRead.