Smart Traffic Light system

Introduction to smart traffic light system

Traffic congestion is a common problem in many urban areas, causing delays, frustration, and pollution. One of the factors that contribute to traffic congestion is the inefficient operation of traffic signals, which are often fixed and do not adapt to the changing traffic conditions.

To address this issue, a smart traffic light system can be designed and implemented, which can adjust the timing and sequence of the traffic signals according to the traffic density on different lanes. This can improve the traffic flow and reduce the waiting time for the vehicles.

One way to implement a smart traffic light system is to use ultrasonic sensors and Arduino microcontrollers. Ultrasonic sensors are devices that can measure the distance between the sensor and the nearest object, such as a vehicle, by emitting and receiving sound waves. Arduino microcontrollers are small and inexpensive computers that can process the data from the sensors and control the LEDs that represent the traffic lights.

By using these components, we can create a prototype of a smart traffic light system that can detect the density of traffic on different lanes and give priority to the lane with more vehicles.

In this project, we will learn how to build a smart traffic light system using ultrasonic sensors and Arduino. We will test and evaluate the performance of our system and compare it with the conventional traffic light system.

Hardware components used in this project

S/NOComponentValueQTY
1Arduino1
2Ultrasonic Sensors4
3Transistor (NPN)6
4Resistors (R1-R6)1k12
5Red Led4
6Yellow Led4
7Green Led4
8Transformer12V1
9Batteries3.7V2
10Capacitor1000uF1
11 Diode5
12LM781212V1

CIRCUIT DIAGRAM OF SMART TRAFFIC LIGHT SYSTEM

smart traffic light system circuit diagram
smart traffic light implementation
int red1 = 13;
int yellow1 = 12;
int green1 = 11;
int red2 = 10;
int yellow2 = 9;
int green2 = 8;


int trig1 = A0;
int echo1 = A3;
int trig2 = 7;
int echo2 = 6;
int trig3 = A2;
int echo3 = A1;
int trig4 = A4;
int echo4 = A5;

long duration1;
float distance1;
long duration2;
float distance2;
long duration3;
float distance3;
long duration4;
float distance4;

float edistance1;
float edistance2;
float edistance3;
float edistance4;

void setup(){
   pinMode(red1,OUTPUT);
   pinMode(yellow1,OUTPUT);
   pinMode(green1,OUTPUT);
   pinMode(red2,OUTPUT);
   pinMode(yellow2,OUTPUT);
   pinMode(green2,OUTPUT);
  
   pinMode(trig1, OUTPUT);
   pinMode(echo1, INPUT);
   pinMode(trig2, OUTPUT);
   pinMode(echo2, INPUT);
   pinMode(trig3, OUTPUT);
   pinMode(echo3, INPUT);
   pinMode(trig4, OUTPUT);
   pinMode(echo4, INPUT);
 
  digitalWrite(red1,HIGH);
  delay(1000);
  digitalWrite(red1,LOW);
  digitalWrite(yellow1,HIGH);
  delay(1000);
  digitalWrite(yellow1,LOW);
  digitalWrite(green1,HIGH);
  delay(1000);
  digitalWrite(green1,LOW);
  
 digitalWrite(red2,HIGH);
  delay(1000);
  digitalWrite(red2,LOW);
  digitalWrite(yellow2,HIGH);
  delay(1000);
  digitalWrite(yellow2,LOW);
  digitalWrite(green2,HIGH);
  delay(1000);
  digitalWrite(green2,LOW);
}


void loop(){
  int new1=edistance1<10 && edistance4>10;
  int new2=edistance1>10 && edistance4<10;
  int new3 =edistance3<10 && edistance2>10;
  int new4 =edistance3>10 && edistance2<10;

  
   check1();
  check4();
  check3();
  check2();
  
  
  if(new1){ 
    sapa2();
  }
  else if (new2){
    sapa3();
  }
  else if(new3){ 
    sapa2();
  }
  else if (new4){
    sapa3();
  }
  else{
    sapa1();
  }

}


void joint1(){
  digitalWrite(red1,HIGH);
  delay(5000);
  digitalWrite(red1,LOW);
  digitalWrite(yellow1,HIGH);
  delay(2000);
   digitalWrite(yellow1,LOW);
}
void joint2(){
  digitalWrite(red2,HIGH);
  delay(5000);
   digitalWrite(red2,LOW);
  digitalWrite(yellow2,HIGH);
  delay(2000);
   digitalWrite(yellow2,LOW);
}

void joint3(){
  digitalWrite(red1,HIGH);
  delay(8000);
    digitalWrite(red1,LOW);
  digitalWrite(yellow1,HIGH);
  delay(2000);
    digitalWrite(yellow1,LOW);
}

void joint4(){
  digitalWrite(red2,HIGH);
  delay(8000);
    digitalWrite(red2,LOW);
  digitalWrite(yellow2,HIGH);
  delay(2000);
    digitalWrite(yellow2,LOW);
}

void joint5(){
  digitalWrite(red2,HIGH);
  delay(500);
    digitalWrite(red2,LOW);
  digitalWrite(yellow2,HIGH);
  delay(500);
    digitalWrite(yellow2,LOW);
}


void joint6(){
  digitalWrite(red1,HIGH);
  delay(500);
    digitalWrite(red1,LOW);
  digitalWrite(yellow1,HIGH);
  delay(500);
    digitalWrite(yellow1,LOW);
}
void first(){
  digitalWrite(green1,HIGH);
  joint2();
  
  off1();
  //digitalWrite(green3,HIGH);
  //digitalWrite(yellow4,HIGH);
  //operation1();
}
  
void second(){
   digitalWrite(green2,HIGH);
   joint1();
 off2();
 // digitalWrite(red3,HIGH);
 // digitalWrite(green4,HIGH);
  //operation2();
}

void third(){
  digitalWrite(green1,HIGH);
 joint4();
  off1();
 // digitalWrite(red3,HIGH);
 // digitalWrite(green4,HIGH);
  //operation2();
}

void fourth(){
   digitalWrite(green2,HIGH);
 joint3();
 off2();
 // digitalWrite(red3,HIGH);
 // digitalWrite(green4,HIGH);
  //operation2();
}
  
 void fifth(){
  digitalWrite(green1,HIGH);
 joint5();
  off1();
 // digitalWrite(red3,HIGH);
 // digitalWrite(green4,HIGH);
  //operation2();
} 
  
void sixth(){
   digitalWrite(green2,HIGH);
 joint6();
 off2();
 // digitalWrite(red3,HIGH);
 // digitalWrite(green4,HIGH);
  //operation2();
}
  


void off1(){
  digitalWrite(green1,LOW);
  digitalWrite(yellow2,LOW);
  digitalWrite(red2,LOW);
  //digitalWrite(green3,LOW);
  //digitalWrite(yellow4,LOW);
}
void off2(){
  digitalWrite(red1,LOW);
  digitalWrite(green2,LOW);
  digitalWrite(yellow1,LOW);
  //digitalWrite(red3,LOW);
 // digitalWrite(green4,LOW);
}


void check1(){
  digitalWrite(trig1, LOW);
  delayMicroseconds(2); 
  digitalWrite(trig1, HIGH);
  delayMicroseconds(10); 
  digitalWrite(trig1, LOW);
  duration1= pulseIn(echo1,HIGH);
  distance1 = 0.0343*duration1;
  edistance1 = distance1/2;
}

void check2(){
   digitalWrite(trig2, LOW);
   delayMicroseconds(2); 
   digitalWrite(trig2, HIGH);
   delayMicroseconds(10); 
   digitalWrite(trig2, LOW);
   duration2= pulseIn(echo2,HIGH);
   distance2 = 0.0343*duration2;
   edistance2 = distance2/2;

}

void check3(){
  digitalWrite(trig3, LOW);
   delayMicroseconds(2); 
   digitalWrite(trig3, HIGH);
   delayMicroseconds(10); 
   digitalWrite(trig3, LOW);
   duration3= pulseIn(echo3,HIGH);
   distance3 = 0.0343*duration3;
   edistance3 = distance3/2;
 
}

void check4(){
   digitalWrite(trig4, LOW);
   delayMicroseconds(2); 
   digitalWrite(trig4, HIGH);
   delayMicroseconds(10); 
   digitalWrite(trig4, LOW);
   duration4= pulseIn(echo4,HIGH);
   distance4 = 0.0343*duration4;
   edistance4 = distance4/2;
  
}

void sapa1(){
  first();
  off1();
  second();
  off2(); 
}

void sapa2(){
  third();
  off1();
  sixth();
  off2(); 
}

void sapa3(){
    fourth();
    off1();
    fifth();
    off2();
}

How smart traffic light system works

A smart traffic light system using ultrasonic sensors operates on the principle of traffic density detection to optimize the flow of vehicles through intersections. Here’s a high-level overview of how it works:

Ultrasonic sensors are placed at strategic points around the intersection to detect the presence and proximity of vehicles. The sensors emit ultrasonic waves, which bounce back upon hitting an object (like a car), and the sensor calculates the distance based on the time it takes for the echo to return.

The ultrasonic sensors together with the microcontroller measures the distance and once it senses a vehicle on any lane that is as close as 10cm, it compares it with other lanes to determine the lane to prioritize.

Based on the traffic density data, the microcontroller adjusts the traffic light signals accordingly. If a lane has high traffic density, it may be given a longer green light duration, while lanes with no or minimal traffic are given a shorter green phase.

The system can adapt in real-time. For example, if the sensors detect no cars waiting at a red light, the system might skip that signal to reduce unnecessary waiting times, thus improving overall traffic flow.

Smart  traffic light system
smart traffic light system

Applications of smart traffic light system

Smart traffic light systems have a range of applications that can significantly improve traffic management and urban mobility. Here are some of the key applications:

  1. Traffic Flow Optimization: By adjusting signal timings in real-time based on traffic density, smart traffic lights can reduce congestion and improve the flow of vehicles through intersections.
  2. Accident Reduction: By managing traffic flows and reducing the likelihood of congestion and gridlock, smart traffic lights can help lower the risk of accident.
  3. Environmental Benefits: Optimizing traffic flow leads to less idling and can reduce vehicle emissions, contributing to cleaner air in urban areas.
  4. Energy Savings: Smart traffic lights is programmed to turn off when all the lanes are empty, there by saving energy.

Here is a link to test the simulation on tinkercad.

Leave a Comment