This project implements a Smart Traffic Management System using an ESP32 microcontroller and infrared (IR) sensors.
It dynamically adjusts traffic light timings based on real-time vehicle density, helping reduce congestion, fuel wastage, and waiting time.
Additionally, a local web dashboard hosted by the ESP32 displays real-time lane status and vehicle counts via Wi-Fi.
- Real-time traffic monitoring using IR sensors
- Dynamic signal control based on vehicle density
- Web-based dashboard hosted on ESP32 (accessible via IP address)
- Automatic priority handling for congested lanes
- Vehicle count reset after each green phase
- Fully autonomous operation without external server dependency
Each lane follows the standard sequence: Green β Yellow β Red.
Signals change automatically at fixed time intervals if no congestion is detected.
While a lane is Red, its IR sensor is active and counts passing vehicles in real-time.
If any Red laneβs vehicle count exceeds a threshold (e.g., β₯2), that lane is given Green priority after a 2-second all-red safety delay.
Whenever a lane turns Green, its count resets to zero to prevent false accumulation.
A built-in web server displays:
- Real-time signal status (Red, Yellow, Green)
- Live vehicle counts for each lane
The dashboard auto-refreshes every second.
| Component | Quantity |
|---|---|
| ESP32 Microcontroller | 1 |
| IR Sensor | 4 |
| Red, Yellow, Green LEDs | 12 (3 per lane) |
| Resistors (220Ξ©) | 12 |
| Breadboard | 1 |
| Jumper Wires | As needed |
| USB Cable | 1 |
- Arduino IDE β for programming ESP32
- Web Browser β for viewing the real-time dashboard
| Component | ESP32 Pin |
|---|---|
| IR1 | 13 |
| IR2 | 12 |
| IR3 | 14 |
| IR4 | 15 |
| RED1 | 32 |
| YELLOW1 | 21 |
| GREEN1 | 16 |
| RED2 | 33 |
| YELLOW2 | 22 |
| GREEN2 | 17 |
| RED3 | 27 |
| YELLOW3 | 23 |
| GREEN3 | 18 |
| RED4 | 26 |
| YELLOW4 | 25 |
| GREEN4 | 19 |
- ESP32 reads all four IR sensors to detect vehicles.
- Each Red lane counts passing vehicles.
- When a laneβs vehicle count crosses a set limit, the ESP32 triggers Preemption Mode, giving that lane Green priority.
- After clearing congestion, normal cycling resumes.
- Real-time signal states and counts are shown on the web dashboard via Wi-Fi.
- Upload the code to ESP32 and power it on.
- Connect to the same Wi-Fi network as the ESP32.
- Check the Serial Monitor for the ESP32βs IP address.
- Open the IP address in a browser to view live data.
The dashboard auto-refreshes every second and shows:
- Current signal status of each lane
- Vehicle count for each lane
- Libraries Used:
WiFi.h,WebServer.h - Core Functions:
checkIR()β Counts vehicles when lane is redcheckPreemption()β Detects congested laneshandlePreemption()β Activates priority modehandleNormalCycle()β Handles normal signal rotationgetDashboardHTML()β Generates live HTML dashboard
- Integration with Blynk or ThingSpeak for cloud analytics
- Replace IR sensors with ESP32-CAM for visual traffic detection
Project link: https://circuitdigest.com/microcontroller-projects/smart-traffic-management-system-using-iot
Vedhathiri K
This project demonstrates how an IoT-based adaptive traffic control system can improve urban mobility, reduce fuel waste, and offer a scalable foundation for future smart city applications.