Red, yellow, green — in the right order, with the right timing. The friendliest possible introduction to digital outputs and timing.
What you’ll build
Three LEDs cycle through the classic Indian junction sequence: green → yellow → red and back, with a blinking-yellow night mode when you hold the button. Once this makes sense, you understand half of embedded programming.
Components you’ll need
| Component | Qty | Price |
|---|---|---|
| Arduino Nano ATmega328P Compatible Board | 1 | ₹149 |
| 5mm Red LED | 1 | ₹149 |
| 5mm Yellow LED | 1 | ₹199 |
| 5mm Green LED | 1 | ₹19 |
| 220 Ohm 1/4W | 3 | ₹147 |
| 400 Point Breadboard | 1 | ₹299 |
| Total | ₹962 |
Step-by-step guide
- Wire the red LED to D2, yellow to D3, green to D4 — each long leg through a 220Ω resistor, short legs to GND.
- Upload the sketch: green runs 5 seconds, yellow 2, red 5, forever.
- Study the loop and change the timings — make rush-hour and midnight versions.
- Stretch goal: add a second set of LEDs for the cross street and keep both directions safe (both red during changeover).
The code
The whole controller is one loop and three variables — tweak away.
const int red=2, yellow=3, green=4;
const int GREEN_MS=5000, YELLOW_MS=2000, RED_MS=5000;
void setup(){
pinMode(red,OUTPUT); pinMode(yellow,OUTPUT); pinMode(green,OUTPUT);
}
void all(int r,int y,int g){ digitalWrite(red,r); digitalWrite(yellow,y); digitalWrite(green,g); }
void loop(){
all(0,0,1); delay(GREEN_MS); // go
all(0,1,0); delay(YELLOW_MS); // slow down
all(1,0,0); delay(RED_MS); // stop
}The complete, ready-to-upload sketch and wiring diagram are on GitHub:
View full project on GitHubGitHub link is a placeholder — replace it with your project repository URL.
Build this project
Add all 6 required components to your cart in one click — total ₹962.
Add all components to cart