LED Blink and Two-LED Patterns
Start with one blinking LED, then use two digital outputs to alternate and create your own flash pattern.
Lesson 1 · Blink a single LED with delay()
Build with the USB cable unplugged. Use one 220–330 Ω resistor for each LED. The long LED leg is usually the anode; the short leg and flat edge mark the cathode.
1UNO D8 → 220–330 Ω resistor → LED anode (+)
2LED cathode (−) → GND
PHOTO TO ADDOne LED, resistor and jumper wires on the breadboard; show the UNO pin labels clearly.
const int led1 = 8;
void setup() {
pinMode(led1, OUTPUT);
}
void loop() {
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
}setup() runs once. loop() repeats. HIGH turns the LED on; LOW turns it off. delay(1000) waits one second.
Lesson 2 · Alternate two LEDs
1UNO D9 → its own 220–330 Ω resistor → second LED anode
2Second LED cathode → GND; keep LED 1 on D8
PHOTO TO ADDBoth LEDs on the breadboard, each with its own resistor and a shared GND rail.
const int led1 = 8;
const int led2 = 9;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
delay(500);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
delay(500);
}Practise the patterns
- Change both delays to 200 ms, then 1000 ms. Predict which version looks fastest before uploading.
- Make LED 1 flash twice quickly, then LED 2 stay on for one second. Write the HIGH, LOW and delay steps in order before coding.
- Create a short–short–long flash pattern, followed by a pause. Check that neither LED is connected without a resistor.
VIDEO TO ADDRecord the single LED, alternating LEDs, speed changes and final flash pattern.