Arduino Two LEDs Blinking Alternately
easyDigital outputArduino (C++)
Controlling two outputs at once — the step between a single blink and a traffic light.
The question
Two LEDs are on pins 11 and 3. Make them blink alternately: when one is ON the other is OFF. Switch every 300 ms.
The sketch
sketch.ino
void setup() {
pinMode(11, OUTPUT);
pinMode(3, OUTPUT);
}
void loop() {
digitalWrite(11, HIGH);
digitalWrite(3, LOW);
delay(300);
digitalWrite(11, LOW);
digitalWrite(3, HIGH);
delay(300);
}Wiring
LED 1 → 220Ω → pin 11; LED 2 → 220Ω → pin 3; both cathodes → GND.
How it works
- 1Both pins are set as OUTPUT in setup().
- 2In the first half of loop() one LED is HIGH and the other LOW.
- 3After the delay the states swap, so the LEDs take turns.
Common mistakes
- Setting only one pin as OUTPUT — the other LED glows dimly or not at all.
- Forgetting a delay after the second half, so one LED looks permanently on.
Now solve a similar question yourself
A new Arduino question every time, checked instantly.
