Blink: The Hello World of Hardware
Blink is the traditional first Arduino program — the hardware equivalent of printing 'Hello, World'. It turns an LED on and off at a fixed interval, proving your board, toolchain, and upload path all work end to end. The Uno has a built-in LED wired to digital pin 13, exposed through the named constant LED_BUILTIN, so Blink needs no external components. The whole program uses just three core functions: pinMode to configure a pin, digitalWrite to set it high or low, and delay to pause. Mastering these three unlocks the majority of simple digital-output projects.
Cricket analogy: Blink is like a batter facing a single gentle throwdown in the nets — the simplest possible test that confirms bat, pads, and eye all work before facing real pace.
// Blink the on-board LED once per second
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // configure pin 13 as an output
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // 5V -> LED on
delay(1000); // hold for 1000 ms
digitalWrite(LED_BUILTIN, LOW); // 0V -> LED off
delay(1000); // hold for 1000 ms
}Line by Line
In setup(), pinMode(LED_BUILTIN, OUTPUT) configures pin 13 to drive a voltage rather than read one — this runs once. In loop(), digitalWrite(LED_BUILTIN, HIGH) sets the pin to 5V (or 3.3V on 3.3V boards), sourcing current through the LED and lighting it; LOW sets it to 0V and turns it off. Between the writes, delay(1000) pauses execution for 1000 milliseconds. Because loop() repeats forever, the LED cycles on for a second and off for a second indefinitely. The 1000 values are the timing; change them to 100 and the LED blinks five times faster.
Cricket analogy: pinMode setting a pin as OUTPUT is like a captain designating a player as bowler rather than keeper — deciding the pin's role once before the over begins.
HIGH and LOW are just named constants for 1 and 0. Similarly OUTPUT, INPUT, and INPUT_PULLUP are constants for pinMode. Using the names instead of raw numbers makes sketches far more readable and is the recommended style throughout the Arduino ecosystem.
Adding an External LED
To blink your own LED, wire it from a digital pin to ground through a current-limiting resistor — typically 220 to 330 ohms for a standard LED on 5V. The resistor is mandatory: an LED is a diode with very low resistance, so connecting it directly across 5V lets excessive current flow, burning out the LED and possibly stressing the pin. Mind polarity too — the longer leg (anode) goes toward the positive pin side and the shorter leg (cathode) toward ground. Then change LED_BUILTIN in the sketch to your chosen pin number, for example pin 9.
Cricket analogy: The current-limiting resistor is like a helmet grille protecting the batter from a bouncer — an essential safety piece; skip it and the LED takes a blow it can't survive.
Never connect an LED directly between a 5V pin and ground without a resistor. The near-short-circuit current can instantly destroy the LED and may exceed the pin's ~20 mA limit, damaging the microcontroller. Always include a 220–330 ohm resistor in series.
Non-Blocking Blink with millis()
The delay() version is simple but freezes the whole processor while waiting, so it can't read a button or another sensor during the pause. A non-blocking version instead records the last time the LED toggled and checks on every loop() whether the interval has elapsed using millis(). Because loop() keeps spinning freely, other code can run alongside the blink. This millis() pattern is the foundation of every responsive Arduino sketch that must do several things seemingly at once, and it scales cleanly to controlling many outputs on independent schedules.
Cricket analogy: Non-blocking millis() is like a wicketkeeper who glances at the scoreboard between deliveries without stopping play — checking the clock without freezing the whole match.
const int ledPin = LED_BUILTIN;
const unsigned long interval = 1000; // ms
unsigned long previousMillis = 0;
int ledState = LOW;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
unsigned long now = millis();
if (now - previousMillis >= interval) {
previousMillis = now;
ledState = (ledState == LOW) ? HIGH : LOW;
digitalWrite(ledPin, ledState);
}
// other non-blocking code can run here every loop
}- Blink is the hardware 'Hello World' and needs no wiring thanks to the on-board LED on pin 13 (LED_BUILTIN).
- pinMode sets a pin's direction, digitalWrite sets it HIGH (5V) or LOW (0V), and delay pauses in milliseconds.
- HIGH/LOW and OUTPUT/INPUT are readable named constants for 1/0 and pin modes.
- An external LED needs a 220–330 ohm series resistor and correct anode/cathode polarity.
- delay() blocks the processor; the millis() pattern blinks without freezing other code.
- The millis() non-blocking approach is the basis for doing many timed things at once.
Practice what you learned
1. Which pin is the Uno's built-in LED connected to, exposed via LED_BUILTIN?
2. What does pinMode(LED_BUILTIN, OUTPUT) do?
3. Why must an external LED include a series resistor?
4. What is the main advantage of the millis() blink pattern over delay()?
5. In the Blink sketch, what do HIGH and LOW represent?
Was this page helpful?
You May Also Like
Arduino Sketch Structure
Understand the anatomy of an Arduino sketch: the mandatory setup() and loop() functions, global declarations, comments, and how the program executes from power-on onward.
Arduino Data Types and Variables
Learn the core Arduino/C++ data types, how much memory each uses on an 8-bit AVR, and how to declare variables and constants correctly to avoid overflow and wasted RAM.
What Is Arduino?
An introduction to Arduino as an open-source electronics platform combining a programmable microcontroller board with a simple software toolchain for building interactive projects.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics