Arduino for Beginners · Sketch Programming Fundamentals
Sketch structure: setup() and loop()
Sketch Programming Fundamentals
Introduction
Every Arduino program (sketch) is built on two functions: setup() and loop(). setup() runs once after the board starts or resets and is used for configuration, while loop() is then called in an infinite loop. This lesson shows what happens "under the hood" — the hidden main() function in the Arduino core, the init() -> setup() -> loop() order, the role of the bootloader and the ATmega328P microcontroller, and common pitfalls (blocking code, an empty loop, missing required functions).