16 MHzUSB13220 ΩMCU · ATmega328PflashDDRB5PORTB5LEDArduino IDE1void setup() {2 pinMode(13, OUTPUT);3}4void loop() {5 digitalWrite(13, HIGH);6 delay(1000);7 digitalWrite(13, LOW);8 delay(1000);9}110200
0123405time (s)VPIN 13 · delay(1000)0123405time (s)VPIN 13 · delay(200)
Back: the board (microcontroller, clock, USB, pin 13, resistor, LED, ground)Front: your computer and the Blink sketchTokens: the program, the bits written to the pin's registers, and clock ticksAn Arduino Uno R3: the ATmega328P with its flash and the two bits that control pin 13 (DDRB5 and PORTB5), a 16 MHz clock, a USB port, and pin 13 wired through a 220 Ω resistor and an LED to ground. The Blink sketch is uploaded into flash, makes pin 13 an output, then sets it HIGH (5 V, LED on) and LOW (0 V, LED off) with a 1000 ms delay after each: one blink every 2 s. The plots show pin 13's voltage over time for delay(1000) and delay(200).

The program

  1. Blink is the first firmware most people write: an LED goes on for a second, off for a second, forever. If it blinks, your board, cable and tools all work. Ours is an Arduino Uno R3 with an LED on pin 13.

One blink

Forever, and faster

What happens

;; step 1/10 · hello
Blink  the "hello, world" of microcontrollers
board  Arduino Uno R3  (ATmega328P, 16 MHz)
LED    on pin 13, through a 220 ohm resistor
       (the board's own "L" LED is on pin 13 too)
it blinks  ->  board, cable and toolchain all work

The original Blink example writes LED_BUILTIN instead of 13. On the Uno, LED_BUILTIN is defined as 13, so the board's own "L" LED blinks along with yours. On other boards it can be a different pin. The resistor keeps the current safely low. An ATmega328P pin must never carry more than 40 mA (the datasheet's absolute maximum); the lesson "Pin current limits and driving loads with a transistor" shows how to work out the resistor.