Read the code

Here is the whole sketch. A sketch is what Arduino calls a program10.

l1-blink-arduino.ino
// Lesson 1, Arduino version.
// Blinks the UNO R3's LED on pin 13: 1 s on, 1 s off.
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}

The first two lines start with //. They are notes for people, and the board ignores them11.

What each line does

  1. void setup()The lines inside setup run once, when the board starts or is reset7.
  2. pinMode(13, OUTPUT);Makes pin 13 an output: a pin your code turns on and off9.
  3. void loop()After setup, the lines inside loop run again and again8.
  4. digitalWrite(13, HIGH);Turns pin 13 on, to 5 volts, so the light comes on3.
  5. delay(1000);Waits 1000 milliseconds, which is one second4.
  6. digitalWrite(13, LOW);Turns pin 13 off, to 0 volts, so the light goes out3.
  7. delay(1000);Waits one more second. Then loop starts again from its first line.

Want to change it? The Write code page starts with a Blink like this one. Change a delay number, press Run, and watch the speed change.

Sources for this page

  1. Arduino reference: digitalWrite
  2. Arduino reference: delay
  3. Arduino reference: setup()
  4. Arduino reference: loop()
  5. Arduino reference: pinMode
  6. Arduino: How to upload a sketch with the Arduino IDE 2
  7. Arduino reference: // single line comment