Blink an LED
Part of the First Circuits section of Coddy's Arduino journey. Lesson 1 of 22.
An Arduino Uno is a small computer called a microcontroller. You write a program for it, called a sketch, and the board runs it on its own, again and again, as long as it has power.
Every sketch has two parts:
void setup() {
// runs once, when the board starts
}
void loop() {
// runs again and again, forever
}The board talks to the world through its pins. Pin 13 has an LED wired to it. To light it, make the pin an output in setup(), then set it HIGH (5 volts, on) or LOW (0 volts, off):
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);delay(1000) pauses the sketch for 1000 milliseconds, one second. Put an on, a wait, an off and another wait in loop(), and the LED blinks forever.
Challenge
EasyThe board has an LED on pin 13. This sketch makes it blink: setup() makes pin 13 an output, and loop() turns the LED on, waits a second, turns it off and waits again, over and over.
Press Run on the board to watch it blink, then press Check.
Try it yourself
void setup() {
pinMode(13, OUTPUT); // pin 13 is an output
}
void loop() {
digitalWrite(13, HIGH); // LED on
delay(1000); // wait one second
digitalWrite(13, LOW); // LED off
delay(1000); // wait one second
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in First Circuits
1Hello, Board
Blink an LEDSetup and LoopChange the Blink SpeedAn LED of Your OwnTwo LEDs Taking TurnsComments in Your SketchPractice on your own: Arduino playground