Bench NotesUno handbook

Your First Sketch: Blink

Upload a sketch that blinks the on-board LED and learn what setup() and loop() do.

BeginnerLEDArduino Uno

Overview

Every Arduino sketch has two functions. setup() runs once after power-up or reset; loop() then runs again and again forever. This sketch uses them to blink the LED that is already on the board, so you need no other parts.

You will need

  • Arduino Uno R3 and a USB data cable (some cables carry power only)

Wiring

Uno pinConnects toNotes
13 (LED_BUILTIN)On-board L LEDAlready connected on the board; nothing to wire.
Wiring for Your First Sketch: BlinkArduino Uno D13 to On-board LED L.Connections (each line is one wire)Arduino UnoOn-board LEDD13L
Original wiring diagram. Each line is one jumper wire; boxes on a line are series resistors.

Uploading

  1. Install the Arduino IDE from the official download page.
  2. Connect the board, then choose Tools → Board → Arduino Uno and the matching Port.
  3. Paste the sketch and click Upload (the right-arrow button). The TX and RX lights flicker while it transfers.

If the upload fails, go to Fixing upload errors.

Diagram

LED timingLED_BUILTIN: on 500 ms, then off 500 ms, then on 500 ms, then off 500 ms.LED_BUILTINON 500 msoff 500 msON 500 msoff 500 ms0 ms2000 ms
Two seconds of output.

The sketch

first_sketch_blink.ino
// Blink the on-board LED once per second.
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);   // pin 13 on the Uno
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // LED on
  delay(500);                        // wait half a second
  digitalWrite(LED_BUILTIN, LOW);    // LED off
  delay(500);
}

How the code works

LED_BUILTIN is a constant the board package defines, so the same sketch works on boards whose LED is on a different pin. delay() pauses the whole program; that is fine here, and millis() timing shows how to wait without stopping everything else.

What you should observe

  • The LED marked L blinks: half a second on, half a second off.
  • Change both 500s to 100 and upload again: it blinks five times faster.