Arduino LED Blink Code with Wiring
easyDigital outputArduino (C++)
The Hello World of Arduino — and the first program in almost every PR-4 practical.
The question
Write a sketch that blinks an LED connected to digital pin 10: ON for 200 ms, then OFF for 200 ms, forever.
The sketch
sketch.ino
void setup() {
pinMode(10, OUTPUT);
}
void loop() {
digitalWrite(10, HIGH);
delay(200);
digitalWrite(10, LOW);
delay(200);
}Wiring
LED anode (long leg) → 220Ω resistor → pin 10; cathode → GND.
How it works
- 1setup() runs once: pinMode(pin, OUTPUT) makes the pin able to drive an LED.
- 2loop() runs forever: digitalWrite(pin, HIGH) turns the LED on, LOW turns it off.
- 3delay(ms) waits that many milliseconds; 1000 ms is one second.
Common mistakes
- Leaving out the resistor in a real circuit — the LED or the pin can be damaged.
- Forgetting the second delay, so the LED turns off and on again instantly and looks always on.
Now solve a similar question yourself
A new Arduino question every time, checked instantly.
