Board, pins and sketches
What happens when an Arduino sketch runs?
Understand it
A microcontroller runs one program repeatedly. setup() runs once after start or reset; loop() then repeats. Pins can be configured as inputs or outputs. The uploaded program continues without a full desktop operating system.
Choose a step to inspect it, or run the complete sequence.
A useful analogy
Opening a classroom happens once, but checking the room and doing tasks repeats throughout the day.
Worked example
Configure an LED pin in setup(), then turn it on and off with delays in loop().
const int ledPin = 9;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
} - Open the built-in Blink example.
- Point to setup and loop.
- Predict what changing the delay will do.
Quick checkHow many times does setup() normally run?
Answer: Once after power-up or reset.