Arduino UNO & Sketch Structure (setup & loop)
Arduino UNO is an open-source microcontroller board (ATmega328P) widely used in school robotics and IoT projects. Every Arduino C++ sketch requires two functions: setup(), which runs once on power-up, and loop(), which repeats forever.
How It Works & Why It Matters
Unlike a Raspberry Pi or PC running an OS, an Arduino runs one compiled firmware sketch directly on hardware.
Declare pin directions with pinMode() inside setup() and read sensors or drive actuators continuously inside loop().
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
🏫 Classroom Example
Pin 13 on an Arduino UNO already includes a tiny onboard LED labeled "L" for instant testing without wires.
⚖️ Arduino UNO vs. Raspberry Pi
Arduino is a microcontroller ideal for real-time sensors, motors, and low-power hardware; Raspberry Pi is a full mini-computer running Linux.
Forgetting pinMode(pin, OUTPUT) in setup()—causing connected LEDs to glow barely visibly—or rewiring breadboards while USB power is plugged in.