It thinks and tells the two lights when to swap.
Arduino
The brain
alternating output states
Turn two LEDs on and off in opposite states.

Pin connections
| Part 1 | Part 2 | |
|---|---|---|
Arduino pin 12 | → | Red resistor pin 2 |
Red resistor pin 1 | → | Red LED anode (+) |
Red LED cathode (-) | → | Arduino GND |
Arduino pin 13 | → | Green resistor pin 2 |
Green resistor pin 1 | → | Green LED anode (+) |
Green LED cathode (-) | → | Arduino GND |
Let's make two lights take turns!
When the red light is on, the green one is off — they swap back and forth like a seesaw.
You see this in car turn signals and railway crossing lights!
The problem
We want two lights that are never on at the same time — they should take turns.
Think of it like
It's like a seesaw — when one side goes up, the other side goes down.
It thinks and tells the two lights when to swap.
Arduino
The brain
Glows red when it is its turn.
Red LED
The first light
Glows green when it is its turn.
Green LED
The second light
Keeps the red light safe from too much power.
Red resistor
The protector
Keeps the green light safe from too much power.
Green resistor
The protector
First light on
The first light (pin 12) turns on while the second light (pin 13) stays off.
digitalWrite(LED_A, HIGH); digitalWrite(LED_B, LOW);
Wait a little
Both lights hold still for a moment so you can see which one is glowing.
delay(300);
Swap to the other
Now they trade places — the first light goes off and the second one glows. Just like a seesaw!
digitalWrite(LED_A, LOW); digitalWrite(LED_B, HIGH);
Wait, then repeat
Another short wait, then loop() jumps back and swaps the lights again!
delay(300);
Then loop back to step 1
Follow these steps in order. Match the wires to the colors shown.
Place Arduino
Place the Arduino (uno) on the breadboard.
Arduino placed — ready to build!
Place Red LED
Place the Red LED (ledA) on the breadboard.
Place Green LED
Place the Green LED (ledB) on the breadboard.
Place Red resistor
Place the Red resistor (rA) on the breadboard.
Place Green resistor
Place the Green resistor (rB) on the breadboard.
Connect Arduino pin 12 to Red resistor (rA) 2
Connect Arduino pin 12 to Red resistor (rA) 2.
Connect Red resistor (rA) 1 to Red LED (ledA) anode (+)
Connect Red resistor (rA) 1 to Red LED (ledA) anode (+).
Connect Red LED (ledA) cathode (-) to Arduino GND
Connect Red LED (ledA) cathode (-) to Arduino GND.
Connect Arduino pin 13 to Green resistor (rB) 2
Connect Arduino pin 13 to Green resistor (rB) 2.
Connect Green resistor (rB) 1 to Green LED (ledB) anode (+)
Connect Green resistor (rB) 1 to Green LED (ledB) anode (+).
Connect Green LED (ledB) cathode (-) to Arduino GND
Connect Green LED (ledB) cathode (-) to Arduino GND.
The two light nicknames
const int LED_A = 12; const int LED_B = 13;
LED_A is pin 12 and LED_B is pin 13. These are the two lights that take turns.
Get both lights ready
void setup() {
pinMode(LED_A, OUTPUT);
pinMode(LED_B, OUTPUT);
}setup() gets both pins ready so we can turn each light on and off.
The swapping loop
void loop() {
digitalWrite(LED_A, HIGH);
digitalWrite(LED_B, LOW);
delay(300);
digitalWrite(LED_A, LOW);
digitalWrite(LED_B, HIGH);
delay(300);
}Each half of loop() turns one light on and the other off, with a short wait between swaps.
const int LED_A = 12;
const int LED_B = 13;
void setup() {
pinMode(LED_A, OUTPUT);
pinMode(LED_B, OUTPUT);
}
void loop() {
digitalWrite(LED_A, HIGH);
digitalWrite(LED_B, LOW);
delay(300);
digitalWrite(LED_A, LOW);
digitalWrite(LED_B, HIGH);
delay(300);
}
Q1. Which part runs again and again?
Q2. When the first light is ON, the second light should be…
Make the lights swap faster — change both delay(300) to delay(150).
Hint: There are two matching delay lines inside loop().
Add a little note (comment) on the line that turns the first light on.
Hint: Type // and your words at the end of line 8.
A line-by-line tour of the sketch — the same steps as in Robot Gurukul Studio.
Program overview
Big idea
Every Arduino program has a top part, a setup() part that runs once, and a loop() part that runs again and again.
In this project
Two lights take turns — one glows while the other is dark, again and again.
Tip
Read from the top to the bottom. Tap any word or line if you need help!
const int LED_A = 12; const int LED_B = 13;
setup()
Big idea
setup() runs one time when the board turns on.
In this project
It gets pin 12 and pin 13 ready for our two lights.
Why here
Things we do only once go inside setup().
void setup() {
pinMode(LED_A, OUTPUT);
pinMode(LED_B, OUTPUT);
}loop()
Big idea
loop() runs again and again, forever.
In this project
This is where the two lights swap turns over and over.
Why here
Things that repeat go inside loop().
void loop() {
digitalWrite(LED_A, HIGH);
digitalWrite(LED_B, LOW);
delay(300);
digitalWrite(LED_A, LOW);
digitalWrite(LED_B, HIGH);
delay(300);
}
Try this: Change a delay number inside loop(), then press Run to make the lights swap faster.
pinMode
Big idea
pinMode tells a pin if it will listen or push power out.
In this project
It makes pin 12 ready to push power to the first light.
Why here
It goes in setup() because we only set it once.
pinMode(LED_A, OUTPUT);
digitalWrite
Big idea
digitalWrite turns a pin ON or OFF.
In this project
ON lights up a light, OFF turns it dark. Here it turns the first light on.
Why here
It goes in loop() so the lights can keep changing.
digitalWrite(LED_A, HIGH);
delay
Big idea
delay means wait. Nothing else happens while it waits.
In this project
It holds the lights still long enough for you to see who is on.
Why here
Right after we set the two lights.
delay(300);