Runs your sketch
Arduino
Brain
sequencing multiple outputs with timing
Cycle red, yellow, and green LEDs like a mini traffic signal.

Pin connections
| Part 1 | Part 2 | |
|---|---|---|
Arduino pin 13 | → | Red resistor pin 2 |
Red resistor pin 1 | → | Red LED anode (+) |
Red LED cathode (-) | → | Arduino GND |
Arduino pin 12 | → | Yellow resistor pin 2 |
Yellow resistor pin 1 | → | Yellow LED anode (+) |
Yellow LED cathode (-) | → | Arduino GND |
Arduino pin 11 | → | Green resistor pin 2 |
Green resistor pin 1 | → | Green LED anode (+) |
Green LED cathode (-) | → | Arduino GND |
Three lights, one sequence!
Red, yellow, green — only one color on at a time, in order.
Real traffic lights use the same timed sequence idea.
The problem
One LED is not enough — you need multiple outputs in a fixed order.
Think of it like
Like a conductor cueing musicians one at a time.
Runs your sketch
Arduino
Brain
Red light in the sequence
Red LED
Stop
Yellow light in the sequence
Yellow LED
Caution
Green light in the sequence
Green LED
Go
Protects the red LED
Red resistor
Safety
Protects the yellow LED
Yellow resistor
Safety
Protects the green LED
Green resistor
Safety
Red light
Turn every light off first, then only red stays on for 2 seconds.
allOff(); digitalWrite(PIN_RED, HIGH); delay(2000);
Yellow light
Red goes off; yellow warns for a shorter 800 ms.
allOff(); digitalWrite(PIN_YELLOW, HIGH); delay(800);
Green light
Yellow off, green on — then loop() repeats from red again.
allOff(); digitalWrite(PIN_GREEN, HIGH); delay(2000);
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!
Place Red LED
Place the Red LED (ledRed) on the breadboard.
Place Yellow LED
Place the Yellow LED (ledYellow) on the breadboard.
Place Green LED
Place the Green LED (ledGreen) on the breadboard.
Place Red resistor
Place the Red resistor (rRed) on the breadboard.
Place Yellow resistor
Place the Yellow resistor (rYellow) on the breadboard.
Place Green resistor
Place the Green resistor (rGreen) on the breadboard.
Connect Arduino pin 13 to Red resistor (rRed) 2
Connect Arduino pin 13 to Red resistor (rRed) 2.
Connect Red resistor (rRed) 1 to Red LED (ledRed) anode (+)
Connect Red resistor (rRed) 1 to Red LED (ledRed) anode (+).
Connect Red LED (ledRed) cathode (-) to Arduino GND
Connect Red LED (ledRed) cathode (-) to Arduino GND.
Connect Arduino pin 12 to Yellow resistor (rYellow) 2
Connect Arduino pin 12 to Yellow resistor (rYellow) 2.
Connect Yellow resistor (rYellow) 1 to Yellow LED (ledYellow) anode (+)
Connect Yellow resistor (rYellow) 1 to Yellow LED (ledYellow) anode (+).
Connect Yellow LED (ledYellow) cathode (-) to Arduino GND
Connect Yellow LED (ledYellow) cathode (-) to Arduino GND.
Connect Arduino pin 11 to Green resistor (rGreen) 2
Connect Arduino pin 11 to Green resistor (rGreen) 2.
Connect Green resistor (rGreen) 1 to Green LED (ledGreen) anode (+)
Connect Green resistor (rGreen) 1 to Green LED (ledGreen) anode (+).
Connect Green LED (ledGreen) cathode (-) to Arduino GND
Connect Green LED (ledGreen) cathode (-) to Arduino GND.
Three output pins
const int PIN_RED = 13; const int PIN_YELLOW = 12; const int PIN_GREEN = 11;
Each color has its own pin number at the top. Names like PIN_RED make the code easier to read.
allOff() helper
void allOff() {
digitalWrite(PIN_RED, LOW);
digitalWrite(PIN_YELLOW, LOW);
digitalWrite(PIN_GREEN, LOW);
}Before each new color, every light is turned LOW so only one shows at a time.
Traffic sequence
void loop() {
allOff();
digitalWrite(PIN_RED, HIGH);
delay(2000);
allOff();
digitalWrite(PIN_YELLOW, HIGH);
delay(800);
allOff();
digitalWrite(PIN_GREEN, HIGH);
delay(2000);
}loop() runs red → yellow → green in order. delay() sets how long each color stays on.
const int PIN_RED = 13;
const int PIN_YELLOW = 12;
const int PIN_GREEN = 11;
void allOff() {
digitalWrite(PIN_RED, LOW);
digitalWrite(PIN_YELLOW, LOW);
digitalWrite(PIN_GREEN, LOW);
}
void setup() {
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_YELLOW, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
allOff();
}
void loop() {
allOff();
digitalWrite(PIN_RED, HIGH);
delay(2000);
allOff();
digitalWrite(PIN_YELLOW, HIGH);
delay(800);
allOff();
digitalWrite(PIN_GREEN, HIGH);
delay(2000);
}
Q1. Where does repeating work belong?
Q2. Why turn the other lights OFF before turning one ON?
Make red stay on longer — change its delay(2000) to delay(3000).
Hint: Find the delay right after digitalWrite(PIN_RED, HIGH).
Make yellow faster — change delay(800) to delay(400).
Hint: The yellow delay is on the line after PIN_YELLOW turns on.
A line-by-line tour of the sketch — the same steps as in Robo Gurukul Studio.
Program overview
Technical
Sketches have globals, then setup() once, then loop() forever.
In this project
Cycle red, yellow, and green LEDs like a mini traffic signal.
Why here
Read from top to bottom. Hover words or lines for help!
const int PIN_RED = 13;
const int PIN_YELLOW = 12;
const int PIN_GREEN = 11;
void allOff() {
digitalWrite(PIN_RED, LOW);
digitalWrite(PIN_YELLOW, LOW);
digitalWrite(PIN_GREEN, LOW);
}setup()
Technical
Runs one time when the board turns on.
In this project
Sets up pins and libraries for Traffic Light.
Why here
One-time setup belongs here—not in loop().
void setup() {
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_YELLOW, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
allOff();
}loop()
Technical
Runs again and again after setup() is done.
In this project
This is the main action you see in Traffic Light.
Why here
Repeating work (blink, read sensors) goes here.
void loop() {
allOff();
digitalWrite(PIN_RED, HIGH);
delay(2000);
allOff();
digitalWrite(PIN_YELLOW, HIGH);
delay(800);
allOff();
digitalWrite(PIN_GREEN, HIGH);
delay(2000);
}
Try this: Change numbers in loop(), then compile and run the simulator.
pinMode
Technical
Tells a pin if it listens or drives something.
In this project
Gets the Traffic Light circuit ready in the simulator.
Why here
Goes in setup() because we only set pins once at the start.
pinMode(PIN_RED, OUTPUT);
digitalWrite
Technical
Turns a pin ON or OFF.
In this project
Controls lights, motors, or buzzers in Traffic Light.
Why here
Goes in loop() so it can keep changing while the program runs.
digitalWrite(PIN_RED, LOW);
delay
Technical
Waits for some time. Nothing else runs during the wait.
In this project
Controls speed so you can see Traffic Light in the simulator.
Why here
Right after an action that should stay the same for a moment.
delay(2000);