انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Maker: home
0. Lab tour1
1. The start: the Arduino6
2. Wiring and the traffic light4
3. Inputs: the button4
4. Sound and movement5
5. Sensors and numbers5
6. Distance, the screen and colours5
7. Motors and the car4
8. The project: the city's smart gate3
9. From blocks to C++ code5
10. Sensors and screens in code5
11. Smart systems5
12. Bluetooth: control from the phone1

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.

🧩 setup runs once
Blocks: setup — runs once
Blinked once, then stopped
Blinked once, then stopped

🎯 Challenge yourself

Easy

Move the blinking commands to loop. How many times does it blink?

👀 Show the solution
🧩 Solution
Blocks: loop — repeats forever
In the lab
In the lab

Result: forever: loop repeats without stopping.

Medium

In setup: repeat the blink 3 times, then it stops.

👀 Show the solution
🧩 Solution
Blocks: setup — runs once
In the lab
In the lab

Result: blinked 3 times, then stopped.

Hard

In setup turn on for two seconds, and in loop blink fast (200).

👀 Show the solution
🧩 Solution
Blocks: setup — runs once, loop — repeats forever
In the lab
In the lab

Result: a steady light first, then fast blinking.

Finished the lesson? Mark it so your progress counts.