PRP 1
Digital output — Blink
Students will: Write and modify your first Arduino program. Make the D12 LED blink and explain what every line does.
void setup() { // runs once when you press reset or power the board
pinMode(12, OUTPUT); // make digital pin 12 an output
}
void loop() { // runs over and over again, forever
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for one second (1000 milliseconds)
digitalWrite(12, LOW); // turn the LED off (LOW)
delay(1000); // wait for one second
}
Common errors & fixes
- "It says error so my code is broken" — usually it's one missing
;or}. Look at the line ABOVE the red one. - "Why isn't my LED working?" — wrong pin (sketches use 12, not 13), wrong board/port, USB cable not fully seated.
- "It compiled but nothing happens" — did you press Upload (→), not just Verify (✓)? They're different buttons.