Smart Traffic System
Adaptive signal control using real-time vehicle counting from intersection cameras.

Smart Traffic System
This project retrofit an ordinary intersection with adaptive signal control. The premise: if you can see the queues, you can schedule the lights.
It is archived as a research prototype — but the simulation findings are the useful artifact.
The Problem
Fixed-cycle signals optimize for nothing in particular. In low-traffic hours they hold lanes empty; in peak hours they starve the busiest approach. The classic fix (induction loops) is expensive to install; the modern fix (cameras + CV) is much cheaper and retrofittable.
Architecture
The pipeline has three stages: detect, count, and decide.
Edge Camera → Vehicle Counter → Controller → Signal Head
- Detect — A Raspberry Pi runs YOLO on the camera feed, detecting vehicles per lane.
- Count — Queue lengths publish over MQTT to a central controller.
- Decide — The controller computes green-times proportionally and updates the signal head.
Engineering decisions
- Count at the edge, decide centrally. Sending raw frames to a central server is bandwidth-heavy and slow. Detection runs on a Raspberry Pi; only counts travel over MQTT.
- Queue length, not flow rate. Counting stopped vehicles in a region of interest is more robust than tracking speeds, and it maps directly to the control objective.
- A simulation mode as a first-class citizen. The same controller logic runs against a micro-simulator, so tuning never requires a real intersection.
def green_time(queue_length: int, phase_min: int, phase_max: int) -> int:
"""Greedy proportional allocation with min/max clamping."""
demand = max(queue_length, 1)
return min(phase_max, max(phase_min, int(demand * K)))Evaluation
Using a simple micro-simulation of a four-approach intersection:
| Metric | Fixed 30s | Adaptive |
|---|---|---|
| Mean vehicle delay | 41 s | 34 s (−18%) |
| 95th-percentile delay | 92 s | 71 s (−23%) |
| Max queue length | 24 veh | 16 veh |
The gains concentrate in off-peak hours, exactly where adaptive control should shine.
Challenges
Tracking ambiguity — a stopped bus occludes the queue behind it, so naive counts are systematically low. Occlusion-aware counting (counting the visible line, then estimating) was the most valuable correction.
Dirty real-world video — the prototype assumed a clean overhead view. Real cameras are tilted, jittery, and dirty. Robustness tricks mattered far more than detector choice.
Lessons
- The control logic was the easy 20%; the pipeline reliability was the hard 80%.
- Simulation is not evidence, but it's the fastest way to be wrong cheaply. It caught two logic bugs before any hardware was involved.
- Cost ceilings are design constraints. At $120 per intersection, the system has to run on edge hardware — a useful forced constraint.
Roadmap
- (Archived) If resumed: occlusion-aware counting and a public dashboard of the findings.
Status
Archived as a prototype. The simulation harness and write-up remain public in the repo.