First steps with Arduino Uno · Lesson
10 min read
Your first sketch: Blink
setup(), loop(), pinMode, digitalWrite and delay — and a blinking LED.
What You Will Learn
- Explain setup() and loop()
- Configure a pin as an output
- Control timing with delay()
Every Arduino sketch has two functions. setup() runs once when the board powers up or resets. loop() then runs again and again, forever.
Arduino C++
void setup() {
pinMode(9, OUTPUT); // pin 9 will drive something
}
void loop() {
digitalWrite(9, HIGH); // 5 V
delay(500); // wait 500 ms
digitalWrite(9, LOW); // 0 V
delay(500);
}Blink an LEDarduino-uno
Note: Press Run. Change the delays to make it blink faster, then try a heartbeat pattern.
delay() stops everything else. That's fine for now; the Programming Patterns course shows how to do several things at once with millis().
Check Your Understanding
Test what you learned in this lesson