Introduction
A Smart Traffic Management System is an IoT and sensor-based project designed to manage traffic efficiently using real-time monitoring. It helps reduce traffic congestion, travel time, and accidents by controlling traffic lights based on traffic density.
This system uses sensors, microcontrollers, and IoT connectivity to optimize traffic flow in cities.
Objective of the Project
- To automate traffic signals based on traffic density.
- To reduce waiting time at intersections and avoid traffic congestion.
- To implement real-time traffic monitoring using sensors.
- To integrate with IoT dashboards for city-wide traffic analysis.
Working Principle
The system uses IR sensors or ultrasonic sensors to detect vehicles at intersections. Based on sensor data, traffic light durations are adjusted dynamically.
Step-by-Step Working
- Sensors detect the number of vehicles waiting at each side of the intersection.
- Microcontroller (Arduino/ESP32) processes the sensor data.
- Traffic light LEDs are controlled according to vehicle density:
- Green light for high-density lanes for longer duration
- Red/Yellow light for low-density lanes
- Optional: Data can be sent to IoT dashboards for city traffic monitoring and analysis.
Components Required
- Arduino Uno / ESP32
- Ultrasonic Sensors (HC-SR04) or IR Sensors × 4 (for 4 lanes)
- LEDs: Red, Yellow, Green × 4 sets
- Resistors: 220Ω for LEDs
- Jumper Wires & Breadboard / PCB
- Buzzer (optional for alerts)
- IoT Platform (optional for real-time traffic monitoring)
Circuit Diagram
Simplified Intersection Setup
Lane 1:
Ultrasonic Sensor -> Arduino Pin D2
Red LED -> D3
Yellow LED -> D4
Green LED -> D5
Lane 2:
Ultrasonic Sensor -> D6
Red LED -> D7
Yellow LED -> D8
Green LED -> D9
Lane 3:
Ultrasonic Sensor -> D10
Red LED -> D11
Yellow LED -> D12
Green LED -> D13
Lane 4:
Ultrasonic Sensor -> A0
Red LED -> A1
Yellow LED -> A2
Green LED -> A3
Note: Each sensor detects vehicles in the corresponding lane. Arduino controls the LED traffic lights based on vehicle density.
Arduino Code Example (Basic Traffic Management)
// Pin Definitions
#define TRIG1 2
#define ECHO1 3
#define RED1 4
#define YELLOW1 5
#define GREEN1 6
#define TRIG2 7
#define ECHO2 8
#define RED2 9
#define YELLOW2 10
#define GREEN2 11
long distance1, distance2;
void setup() {
Serial.begin(9600);
pinMode(TRIG1, OUTPUT); pinMode(ECHO1, INPUT);
pinMode(TRIG2, OUTPUT); pinMode(ECHO2, INPUT);
pinMode(RED1, OUTPUT); pinMode(YELLOW1, OUTPUT); pinMode(GREEN1, OUTPUT);
pinMode(RED2, OUTPUT); pinMode(YELLOW2, OUTPUT); pinMode(GREEN2, OUTPUT);
}
// Function to calculate distance from ultrasonic sensor
long getDistance(int trigPin, int echoPin) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
return duration * 0.034 / 2; // distance in cm
}
void loop() {
distance1 = getDistance(TRIG1, ECHO1);
distance2 = getDistance(TRIG2, ECHO2);
Serial.print("Lane1: "); Serial.println(distance1);
Serial.print("Lane2: "); Serial.println(distance2);
// Lane1 has more vehicles
if(distance1 < distance2){
digitalWrite(GREEN1, HIGH); digitalWrite(RED1, LOW);
digitalWrite(RED2, HIGH); digitalWrite(GREEN2, LOW);
delay(5000); // Green duration
}
else{
digitalWrite(GREEN2, HIGH); digitalWrite(RED2, LOW);
digitalWrite(RED1, HIGH); digitalWrite(GREEN1, LOW);
delay(5000);
}
// Yellow light transition
digitalWrite(YELLOW1, HIGH); digitalWrite(YELLOW2, HIGH);
delay(2000);
digitalWrite(YELLOW1, LOW); digitalWrite(YELLOW2, LOW);
}
Code Explanation
- Ultrasonic sensors detect vehicle presence in lanes.
- Arduino compares distances (number of vehicles) and decides which lane gets longer green light.
- Traffic light LEDs simulate real traffic signals.
- The system can be expanded to IoT dashboards for monitoring traffic density in real-time.
Advantages
- Reduces waiting time at traffic signals
- Dynamic traffic management based on vehicle density
- Can be integrated with IoT for city-wide traffic monitoring
- Cost-effective and scalable
Applications
- Smart city traffic systems
- Campus traffic management
- Industrial or factory internal traffic control
- IoT-enabled real-time traffic monitoring
Future Enhancements
- Integrate AI-based vehicle counting using cameras
- Use IoT cloud dashboards to monitor multiple intersections
- Include emergency vehicle priority system
- Integrate automatic pedestrian crossing signals
Conclusion
The Smart Traffic Management System is a practical IoT project that demonstrates sensor-based dynamic traffic control, smart city solutions, and real-time traffic monitoring. It combines ultrasonic sensors, microcontrollers, and optional IoT connectivity to optimize urban traffic flow.
