Urban intersections still rely heavily on fixed-cycle traffic lights—simple timers that rarely match real traffic demand. They waste fuel, worsen congestion, and sometimes create unsafe conditions when queues grow unexpectedly. This project replaces that old logic with an ESP32-powered adaptive traffic controller capable of real-time vehicle detection, dynamic signal control, and a built-in web dashboard for live monitoring.

This build uses four lanes, each equipped with IR vehicle-detection sensors and a set of Red/Yellow/Green LEDs acting as the signal heads. An ESP32 reads every sensor, decides which lane should receive priority, and exposes all activity on a browser-based dashboard hosted directly on the microcontroller.

Project Overview

The goal was to create a self-contained, IoT-enabled traffic management system that reacts to actual traffic density instead of rigid preset timing. By using inexpensive IR modules and a Wi-Fi-enabled ESP32, the system demonstrates how adaptive traffic logic can be achieved with very basic hardware.

Key Outcomes

✔ Real-time vehicle detection on all four lanes
✔ Dynamic signal timing based on lane congestion
✔ Preemption mode for giving priority to highly congested lanes
✔ Local web dashboard showing vehicle counts + current signal states
✔ Fully automated state cycling with safety delays and debouncing

System Architecture

The ESP32 acts as a centralised controller for all sensing and actuation:

  1. Reads the IR sensor input from each lane.

  2. Counts vehicles only when a lane is red.

  3. Determines priority based on defined thresholds (e.g., ≥2 vehicles).

  4. Controls the LEDs for each lane’s signal state.

  5. Hosts a web interface showing:

    • Current signal colours

    • Vehicle counts per lane

    • Preemption/normal cycle mode

If no lane is congested, the controller cycles through the lights in a conventional round-robin pattern. Once congestion is detected, the controller triggers a safety delay and assigns green to the heavy lane.

Bill of Materials

Electronics:

  • ESP32 Dev Module – 1

  • IR obstacle detection sensors – 4

  • LEDs (Red/Yellow/Green) – 12 total

  • 220Ω resistors – 12

  • Breadboard + jumper wires

  • USB cable for programming

Software:

  • Arduino IDE

  • Any browser for dashboard monitoring

How It Works

The controller runs in three operating modes, switching automatically based on sensor input:

1. Normal Mode (Low Traffic)

Each lane receives:

  • 5 seconds green

  • 5 seconds yellow

  • Followed by red as the next cycle continues

Sensors remain active, but only vehicle counts above the threshold can interrupt this cycle.

2. Counting Mode (Sensor Detection Phase)

When a lane is red:

  • IR sensor counts each passing vehicle

  • Debouncing logic (80 ms) prevents double-counting

  • If the count reaches ≥2, preemption is triggered

Green lanes do not count vehicles (their counters reset immediately).

3. Preemption Mode (Congestion Priority)

If any lane exceeds the threshold:

Step 1 — All-Red Safety Delay
Every light turns red for 2 seconds to prevent conflicts.

Step 2 — Priority Green
The congested lane switches to green.

Step 3 — Counter Reset
The selected lane’s vehicle counter resets.

Step 4 — Return to Normal Cycle
Once the green period ends, the system resumes the standard sequence.

This simple logic efficiently clears bottlenecks and prevents queue buildup.

Web Dashboard (Hosted on the ESP32)

The ESP32 launches a minimal HTTP server upon boot, and its local IP address is shown in Serial Monitor. Opening this IP displays a lightweight dashboard with:

  • Lane signal states (Red / Yellow / Green)

  • Real-time vehicle counts

  • Automatic refresh (1 second)

  • No external cloud dependency

This makes the system entirely LAN-hosted and accessible using any phone or laptop on the same network.

Circuit Overview

Each lane consists of:

  • IR sensor → ESP32 (GPIO input)

  • Red, Yellow, Green LEDs → ESP32 (GPIO outputs)

All components...

Read more »