Six-LED Sequence and Traffic Lights
Build a six-LED chase, then arrange the same six outputs as two traffic lights. The traffic-light practical ends after the working sequence, with no end test.
Lesson 3 · Build a six-LED running sequence
Use six LEDs in a row. Each output pin has its own current-limiting resistor. Connect each LED cathode to GND. Check breadboard row connections before powering the circuit.
1LED 1: D2 → resistor → anode; cathode → GND
2LED 2: D3; LED 3: D4; LED 4: D5
3LED 5: D6; LED 6: D7 — same resistor and GND pattern
D2→ resistor →●→ GND
D3→ resistor →●→ GND
D4→ resistor →●→ GND
D5→ resistor →●→ GND
D6→ resistor →●→ GND
D7→ resistor →●→ GND
PHOTO TO ADDWide view of six LEDs in a straight row, all resistors visible.
void setup() {
pinMode(2, OUTPUT); pinMode(3, OUTPUT);
pinMode(4, OUTPUT); pinMode(5, OUTPUT);
pinMode(6, OUTPUT); pinMode(7, OUTPUT);
}
void loop() {
digitalWrite(2, HIGH); delay(200); digitalWrite(2, LOW);
digitalWrite(3, HIGH); delay(200); digitalWrite(3, LOW);
digitalWrite(4, HIGH); delay(200); digitalWrite(4, LOW);
digitalWrite(5, HIGH); delay(200); digitalWrite(5, LOW);
digitalWrite(6, HIGH); delay(200); digitalWrite(6, LOW);
digitalWrite(7, HIGH); delay(200); digitalWrite(7, LOW);
}The repeated lines are intentional: each LED is switched on, held briefly, then switched off before the next one lights.
Lesson 4 · Rearrange them as two traffic lights
1Direction A: red D2, amber D3, green D4
2Direction B: red D5, amber D6, green D7
3Each pin → its own resistor → LED anode; all cathodes → GND
Direction A
🔴 Red D2
🟡 Amber D3
🟢 Green D4
Direction B
🔴 Red D5
🟡 Amber D6
🟢 Green D7
PHOTO TO ADDTwo clearly labelled red–amber–green stacks on the breadboard.
The diagram shows electrical connections. Arrange the physical LEDs as two separate vertical stacks so the two directions are easy to read.
const int ar=2, aa=3, ag=4;
const int br=5, ba=6, bg=7;
void setup() {
pinMode(ar,OUTPUT); pinMode(aa,OUTPUT); pinMode(ag,OUTPUT);
pinMode(br,OUTPUT); pinMode(ba,OUTPUT); pinMode(bg,OUTPUT);
digitalWrite(ar,HIGH); digitalWrite(br,HIGH);
}
void loop() {
// A: red+amber, then green. B stays red.
digitalWrite(aa,HIGH); delay(1000);
digitalWrite(ar,LOW); digitalWrite(aa,LOW);
digitalWrite(ag,HIGH); delay(3000);
digitalWrite(ag,LOW); digitalWrite(aa,HIGH); delay(1000);
digitalWrite(aa,LOW); digitalWrite(ar,HIGH); delay(1000);
// B: red+amber, then green. A stays red.
digitalWrite(ba,HIGH); delay(1000);
digitalWrite(br,LOW); digitalWrite(ba,LOW);
digitalWrite(bg,HIGH); delay(3000);
digitalWrite(bg,LOW); digitalWrite(ba,HIGH); delay(1000);
digitalWrite(ba,LOW); digitalWrite(br,HIGH); delay(1000);
}VIDEO TO ADDRecord the six-LED chase, rearrangement into two light stacks, and one complete cycle.