setup and loop
Section 1: The start: the ArduinoLesson 1.2 · ⏱ 6 min
Every Arduino program has two parts:
- setup: runs once when the Arduino starts. We put the starting commands in it.
- loop: repeats forever, with no end, as long as the Arduino is on.
📌 Note
A robot works all the time, so most of the program is inside loop.
📌 Another example: setup runs once
The same blinking commands, but inside setup: the LED blinks only once, then stops.


🎯 Challenge yourself
Easy
Move the blinking commands to loop. How many times does it blink?
👀 Show the solution🙈 Hide the solution


Result: forever: loop repeats without stopping.
Medium
In setup: repeat the blink 3 times, then it stops.
👀 Show the solution🙈 Hide the solution


Result: blinked 3 times, then stopped.
Hard
In setup turn on for two seconds, and in loop blink fast (200).
👀 Show the solution🙈 Hide the solution


Result: a steady light first, then fast blinking.

