Skip to main content

Smart Traffic light control system

 

Smart Traffic light control system 

Introduction

Traffic congestion and the efficient management of traffic flow are critical issues in modern urban areas. The implementation of smart traffic light control systems can significantly alleviate these problems by optimizing traffic signal timings based on real-time conditions. This project aims to develop a smart traffic light control system that can operate both automatically and manually, using a NodeMCU microcontroller. The system uses multiple switches to toggle between automatic and manual modes, allowing for flexibility in traffic management.

Objectives

  1. Develop a Functional Traffic Light System: To create a traffic light system that can control traffic lights at three intersections.

  2. Implement Dual Mode Operation: To enable the system to switch between automatic and manual modes using external switches.

  3. Optimize Traffic Flow: To reduce traffic congestion by optimizing signal timings in automatic mode.

  4. Provide Manual Override: To allow for manual control of traffic lights during special situations or emergencies.

Problem Statement

Conventional traffic light systems operate on fixed timings, regardless of real-time traffic conditions. This often leads to inefficient traffic flow, increased congestion, and longer wait times for vehicles. There is a need for a smart traffic light control system that can adapt to real-time traffic conditions and provide the flexibility of manual control when necessary.

Project Methodology

1. Component Selection and Procurement

  • NodeMCU (ESP8266): The core microcontroller for controlling the system.

  • LEDs: Representing red, yellow, and green traffic lights for three intersections.

  • Switches: For toggling between automatic and manual modes.

  • Resistors: For current limiting to protect the LEDs.

2. System Design

  • Circuit Design: Connecting the NodeMCU with LEDs and switches. Ensuring correct pin configurations for input and output operations.

  • Mode Selection Logic: Implementing logic to toggle between automatic and manual modes based on switch inputs.

Circuit Diagram 


3. Software Development

  • Programming: Writing code to control the traffic light sequences in automatic mode and allowing manual override via switches.

  • Testing and Debugging: Ensuring the code works correctly and the transitions between light states are smooth.

The app can be available in playstore which is Blynk IOT 

Code

#include <Servo.h> // Include Servo library

int switchauto = 22; // Define pin for automatic mode switch

int switch1 = 24; // Define pin for manual path1 switch

int switch2 = 26; // Define pin for manual path2 switch

int switch3 = 28; // Define pin for manual path3 switch


int switchautod; // Variable to store automatic mode switch state

int switch1d; // Variable to store manual path1 switch state

int switch2d; // Variable to store manual path2 switch state

int switch3d; // Variable to store manual path3 switch state


int r1 = 8; // Red light for path1

int y1 = 9; // Yellow light for path1

int g1 = 10; // Green light for path1


int r2 = 11; // Red light for path2

int y2 = 12; // Yellow light for path2

int g2 = 13; // Green light for path2


int r3 = 23; // Red light for path3

int y3 = 25; // Yellow light for path3

int g3 = 27; // Green light for path3


void setup() 

{

  Serial.begin(9600); // Initialize serial communication at 9600 baud rate


  // Set pin modes for switches

  pinMode(switchauto, INPUT);

  pinMode(switch1, INPUT);

  pinMode(switch2, INPUT);

  pinMode(switch3, INPUT);


  // Set pin modes for traffic lights

  pinMode(r1, OUTPUT);

  pinMode(y1, OUTPUT);

  pinMode(g1, OUTPUT);

  pinMode(r2, OUTPUT);

  pinMode(y2, OUTPUT);

  pinMode(g2, OUTPUT);

  pinMode(r3, OUTPUT);

  pinMode(y3, OUTPUT);

  pinMode(g3, OUTPUT);


  // Initialize all lights to HIGH (off)

  digitalWrite(r1, HIGH);

  digitalWrite(y1, HIGH);

  digitalWrite(g1, HIGH);

  digitalWrite(r2, HIGH);

  digitalWrite(y2, HIGH);

  digitalWrite(g2, HIGH);

  digitalWrite(r3, HIGH);

  digitalWrite(y3, HIGH);

  digitalWrite(g3, HIGH);

}


void loop() 

{

  // Read switch states

  switchautod = digitalRead(switchauto);

  switch1d = digitalRead(switch1);

  switch2d = digitalRead(switch2);

  switch3d = digitalRead(switch3);

  

  // Automatic mode

  if(switchautod == HIGH && switch1d == LOW && switch2d == LOW && switch3d == LOW) 

  {

    autoo();

  }

  // Manual path1

  else if(switchautod == LOW && switch1d == HIGH && switch2d == LOW && switch3d == LOW) 

  {

    path1();

  }

  // Manual path2

  else if(switchautod == LOW && switch1d == LOW && switch2d == HIGH && switch3d == LOW) 

  {

    path2();

  }

  // Manual path3

  else if(switchautod == LOW && switch1d == LOW && switch2d == LOW && switch3d == HIGH) 

  {

    path3();

  }

}


// Function for automatic traffic light control

void autoo()

{

  // First cycle

  digitalWrite(r1, HIGH);

  digitalWrite(y1, HIGH);

  digitalWrite(g1, LOW);

  digitalWrite(r2, LOW);

  digitalWrite(y2, HIGH);

  digitalWrite(g2, HIGH);

  digitalWrite(r3, LOW);

  digitalWrite(y3, HIGH);

  digitalWrite(g3, HIGH);

  delay(7000);


  digitalWrite(r1, HIGH);

  digitalWrite(y1, LOW);

  digitalWrite(g1, HIGH);

  digitalWrite(r2, HIGH);

  digitalWrite(y2, LOW);

  digitalWrite(g2, HIGH);

  digitalWrite(r3, LOW);

  digitalWrite(y3, HIGH);

  digitalWrite(g3, HIGH);

  delay(3000);


  // Second cycle

  digitalWrite(r1, LOW);

  digitalWrite(y1, HIGH);

  digitalWrite(g1, HIGH);

  digitalWrite(r2, HIGH);

  digitalWrite(y2, HIGH);

  digitalWrite(g2, LOW);

  digitalWrite(r3, LOW);

  digitalWrite(y3, HIGH);

  digitalWrite(g3, HIGH);

  delay(7000);


  digitalWrite(r1, LOW);

  digitalWrite(y1, HIGH);

  digitalWrite(g1, HIGH);

  digitalWrite(r2, HIGH);

  digitalWrite(y2, LOW);

  digitalWrite(g2, HIGH);

  digitalWrite(r3, HIGH);

  digitalWrite(y3, LOW);

  digitalWrite(g3, HIGH);

  delay(3000);


  // Third cycle

  digitalWrite(r1, LOW);

  digitalWrite(y1, HIGH);

  digitalWrite(g1, HIGH);

  digitalWrite(r2, LOW);

  digitalWrite(y2, HIGH);

  digitalWrite(g2, HIGH);

  digitalWrite(r3, HIGH);

  digitalWrite(y3, HIGH);

  digitalWrite(g3, LOW);

  delay(7000);


  digitalWrite(r1, HIGH);

  digitalWrite(y1, LOW);

  digitalWrite(g1, HIGH);

  digitalWrite(r2, LOW);

  digitalWrite(y2, HIGH);

  digitalWrite(g2, HIGH);

  digitalWrite(r3, HIGH);

  digitalWrite(y3, LOW);

  digitalWrite(g3, HIGH);

  delay(3000);

}


// Function for manual path1 control

void path1()

{

  digitalWrite(r1, HIGH);

  digitalWrite(y1, HIGH);

  digitalWrite(g1, LOW);

  digitalWrite(r2, LOW);

  digitalWrite(y2, HIGH);

  digitalWrite(g2, HIGH);

  digitalWrite(r3, LOW);

  digitalWrite(y3, HIGH);

  digitalWrite(g3, HIGH);

}


// Function for manual path2 control

void path2()

{

  digitalWrite(r1, LOW);

  digitalWrite(y1, HIGH);

  digitalWrite(g1, HIGH);

  digitalWrite(r2, HIGH);

  digitalWrite(y2, HIGH);

  digitalWrite(g2, LOW);

  digitalWrite(r3, LOW);

  digitalWrite(y3, HIGH);

  digitalWrite(g3, HIGH);

}


// Function for manual path3 control

void path3()

{

  digitalWrite(r1, LOW);

  digitalWrite(y1, HIGH);

  digitalWrite(g1, HIGH);

  digitalWrite(r2, LOW);

  digitalWrite(y2, HIGH);

  digitalWrite(g2, HIGH);

  digitalWrite(r3, HIGH);

  digitalWrite(y3, HIGH);

  digitalWrite(g3, LOW);

}



4. Prototyping and Testing

  • Breadboard Assembly: Assembling the components on a breadboard for initial testing.

  • Simulation: Simulating traffic conditions and testing the system in both automatic and manual modes.

  • Adjustments: Making necessary adjustments based on test results to ensure reliable performance.

5. Deployment

  • Installation: Setting up the system in a real-world environment.

  • Monitoring and Adjustment: Monitoring the system's performance and making further adjustments if needed.

Application

The smart traffic light control system has various applications, including:

  1. Urban Traffic Management: Improving traffic flow and reducing congestion in cities.

  2. Emergency Situations: Allowing manual override for emergency vehicles or during special events.

  3. Construction Zones: Managing traffic in areas with temporary road work.

  4. Educational Purposes: Demonstrating the principles of IoT and smart traffic systems in educational institutions.

Conclusion

This project successfully demonstrates the potential of IoT-based solutions in improving traffic management. By integrating automatic and manual control modes, the smart traffic light system enhances the flexibility and efficiency of traffic control. The successful implementation of this system highlights the benefits of smart technology in urban planning and traffic management, offering a scalable solution to reduce congestion and improve road safety.


Comments

Popular posts from this blog

2017//2(b)//Engineering Eco//KU

A loan of $10,000 is to be repaid over a period of eight years. During the first four years, exactly half of the loan principal is to be repaid (along with accumulated compound interest) by a uniform series of payments of A1 dollar per year. The other half of the loan principal is to be repaid over four years, with accumulated interest, by a uniform series of payments of A2 dollar per year, If i=9% per year, what are A1 and A2?

Testing servo motor with arduino

  Testing servo motor with arduino  Components Needed: Arduino board (e.g., Arduino Uno) Servo motor Jumper wires Steps for Connection: Servo Motor Pins: Ground (GND): Usually the brown or black wire of the servo motor. Power (VCC): Usually the red wire of the servo motor. Control Signal (PWM): Usually the yellow, orange, or white wire of the servo motor. Connecting to Arduino: Ground (GND): Connect the ground wire of the servo motor to one of the GND pins on the Arduino. Power (VCC): Connect the power wire of the servo motor to the 5V pin on the Arduino. Control Signal (PWM): Connect the control signal wire of the servo motor to digital pin 9 on the Arduino, as specified in the code by myservo.attach(9); Connection Arduino  Servo motor  VCC/ 5V Red wire  GND Black Wire  9  Yellow wire Explanation: Ground (GND): This connection ensures that the servo motor and the Arduino share a common ground, which is necessary for proper operation. Power (VCC): The servo motor needs a power supply t

CanSat

  CanSat is a type of small satellite that is designed to fit inside a soda can. These miniature satellites are used for a variety of purposes, including educational projects, scientific research, and commercial applications. The CanSat concept was first developed in 1998 by Bob Twiggs, a professor at Stanford University, and Jordi Puig-Suari, a professor at California Polytechnic State University. They wanted to create a low-cost, hands-on way for students to learn about satellite technology and space science. Since then, CanSats have become a popular platform for educational projects around the world. They are often used in STEM (Science, Technology, Engineering, and Mathematics) education programs, where students are tasked with designing, building, and launching their own CanSats. A typical CanSat consists of a soda can-sized container that houses a variety of sensors, such as temperature, humidity, pressure, and acceleration sensors. It also includes a small computer, a radio tran