Traffic light controller as a state machine
Build a traffic light with a pedestrian button on an Arduino, written as a proper finite state machine with non-blocking timing, the way real controllers are written.
What this proves to recruiters
- You can design a finite state machine before coding it.
- You can write non-blocking code with millis() instead of delay().
- You can handle inputs like a button without missing them.
Skills you will use
- Finite state machines
- Embedded C
- Non-blocking timing
- Debouncing
Parts list
You can buy the listed parts online here:
| Part | Qty | Approx. price | Shop |
|---|---|---|---|
| Arduino Uno compatible board with USB cable | 1 | ₹550 | Find on Amazon |
| Breadboard, 830 points | 1 | ₹90 | Find on Amazon |
| Jumper wire set (male-male and male-female) | 1 | ₹120 | Find on Amazon |
| LED pack, assorted colours | 1 | ₹60 | Find on Amazon |
| Resistor kit, ¼ W, assorted values | 1 | ₹150 | Find on Amazon |
| Push buttons, pack of 10 | 1 | ₹40 | Find on Amazon |
| Total, about | ₹1,000 | ||
Prices are rough online prices in India and change with the seller. You may already have some parts, or find them in your college lab.
As an Amazon Associate I earn from qualifying purchases. Buying through these links costs you nothing extra and helps keep this site free.
Free software
- Arduino IDE
- Wokwi simulator (no hardware needed to start)
Steps
- Draw the state diagram: GREEN, YELLOW, RED and WALK, with the time or event that moves between them.
- Write an enum for the states and one switch statement that decides what each state does.
- Use millis() to measure time in each state, so the button is read even while lights are on.
- Debounce the pedestrian button in software (ignore changes shorter than 30 ms).
- Test it in Wokwi first, then build it with real LEDs and 220 Ω resistors.
- Write the state diagram into your README; interviewers like seeing the design before the code.
Make it stand out
- Add a night mode where yellow blinks.
- Run two crossing roads from one controller.
Put it on your resume
Implemented a traffic-light controller as a finite state machine in embedded C with non-blocking timing and a debounced pedestrian input.
Replace each [x] with a number you measured. Real numbers make a line believable.
Keep going
This project fits stage 3, “Digital logic and signals”, of the Foundation roadmap.