Course Project
DeVry University
College of Engineering and Information Sciences
Course Number: CEIS114
Module 6: Multiple Traffic Light Controller with Cross Walk, Buzzer, and LCD Display
Background
The development of modern cities and urban areas has brought about an ever-increasing need for efficient traffic management systems. Ensuring the smooth flow of vehicles and pedestrian traffic at intersections is crucial not only for reducing congestion but also for enhancing safety and minimizing environmental impacts. In response to these challenges, the design and implementation of intelligent traffic light systems have become a key focus in the field of transportation engineering. This project aims to provide students with hands-on experience in creating a Multi-Intersection Traffic Light System using Wokwi Lab, offering them a valuable opportunity to explore the intersection of electronics, microcontroller programming, and traffic engineering. By delving into this project, students will gain insights into the principles behind traffic signal control, as well as practical skills that can contribute to more efficient and sustainable urban transportation systems.
Scenario
Design and develop a two-way traffic light controller with a pedestrian crossing and an emergency signal. The pedestrian crossing will have an LCD display messages whether the pedestrian can or cannot cross the street. When they can cross, the LCD will count down from ten (15) to zero (0) indicating the amount of time they have to cross. The emergency signal will force red lights to turn on in all directions and the blue light will be flashing. The final step is to secure the system so that it could be controlled remotely via a web browser. The alternative final step is a non-internet connection using a motion sensor to allow traffic to continuously flow on major street and only switches to slow traffic street when motion is detected.
Introduction
In the context of our lab project, we are embarking on the creation of a smart traffic light system with a crosswalk with a display for people to see the instructions and a buzzer to sound to alert when to walk and not to walk at the intersection. Our sophisticated multiple traffic light controller integrated with a pedestrian crosswalk with display and buzzer will help people walk safely at the busy intersection.
Deliverables
• Complete the Course Project PowerPoint Deliverable
• Screenshot of your Circuit Simulation from Wokwi
• Screenshot of Code Simulation from Wokwi
• Screenshot of output in Serial Monitor from your computer
Parts List
• ESP32 Board in Wokwi
• Two sets of Colored LEDs: Red, Yellow and Green in Wokwi
• Breadboard in Wokwi
• Button in Wokwi
• Wires in Wokwi
• LCD Unit
• Buzzer
Wokwi Library: LiquidCrystal_I2C-master – for LCD Display
Procedures
Start with Wokwi
1. Open Wokwi.com – Login In – Select My Projects under Account on the top right corner.
2. Open your Module 5 project and click on the Save Dropdown to Save a Copy to start Module 6 Project – Save it as - Module 6 – YourFirstNameLastName
Install LiquidCrystal Library
1. Here we will install the LiquidCrystal_I2C-master Library to use the LCD.
2. Click the Library Manager in Wokwi Dashboard
a. Click the Add Button
b. Type LiquidCrystal I2C and select it to install the library
c. Return to the code editor by clicking on sketch.ino
Add components
3. Here we will add the LCD and Buzzer to our multi-intersection traffic light.
4. Click the in the Wokwi Dashboard
a. Type LCD and select the LCD 16 x 2 (I2C)
b. Type Buzzer and select the Buzzer
5. Move the LCD to the side of the Half Breadboard
6. Move the Buzzer to the Full Breadboard as seen in the image below.
7. Connect the Buzzer to the digital pins on the ESP32 Pin 32 and – (GND) ground on the breadboard.
8. Connect the LCD to the digital pins on the ESP32 (VCC to 5V | SDA to 21 | SCL to 22) and – (GND) ground on the breadboard.
Code
1. Now, that we have all the components connected time to add the code to test our Multi Intersection Traffic light with the Crosswalk, Buzzer, and LCD display
2. Delete the code currently in the Wokwi Code Editor.
3. Copy the code from the next page into the Wokwi Code Editor.
Note: If you did not use the pins configuration suggested in the instructions you will need to modify the code to use the GPIO pins you've connected the components to.
Run the simulation
1. Click the “Start the Simulation” button in Wokwi to start the simulation.
2. Observe the traffic lights changing based on your code's logic.
3. Observe the output in the LCD Panel and Buzzer
4. To activate the crosswalk, click on hold the button for about 5 secs and notice the countdown start in the Serial Monitor.
Final result
Figure 1 – Code for Multi-Intersection Traffic Light with Crosswalk, buzzer, and LCD display
Figure 2 – Simulation of Multi-Intersection Traffic Light with Crosswalk, buzzer, and LCD display
CODE
// === Replace this text with your Name ====
// Module #6 project #include <Wire.h> //lcd
#include <LiquidCrystal_I2C.h> //lcd
LiquidCrystal_I2C lcd(0x27,16,2); //set the LCD address to 0x3F for a 16 chars and 2-line display
const int bzr=32; // GPIO32 to connect the Buzzer
//==================== LCD ====================
const int red_LED1 = 14; // The red LED1 is wired to ESP32 board pin GPIO14
const int yellow_LED1 =12; // The yellow LED1 is wired to ESP32 board pin GPIO12
const int green_LED1 = 13; // The green LED1 is wired to ESP32 board pin GPIO13
const int red_LED2 = 25; // The red LED2 is wired to Mega board pin GPIO25
const int yellow_LED2 = 26; // The yellow LED2 is wired to Mega board pin GPIO 26
const int green_LED2 = 27; // The green LED2 is wired to Mega board pin GPIO 27
int Xw_value;
const int Xw_button = 19; //Cross Walk button
void setup()
{
Serial.begin(115200);
pinMode(Xw_button, INPUT_PULLUP); // 0=pressed, 1 = unpressed button
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.setCursor(0,0); // column#4 and Row #1
lcd.print(" === CEIS114 ===");
pinMode(bzr,OUTPUT);
pinMode(red_LED1, OUTPUT); // initialize digital pin 14 (Red LED1) as an output.
pinMode(yellow_LED1, OUTPUT); // initialize digital pin12 (yellow LED1) as an output.
pinMode(green_LED1, OUTPUT); // initialize digital pin 13 (green LED1) as an output.
pinMode(red_LED2, OUTPUT); // initialize digital pin 25(Red LED2) as an output.
pinMode(yellow_LED2, OUTPUT); // initialize digital pin 26 (yellow LED2) as an output.
pinMode(green_LED2, OUTPUT); // initialize digital pin 27 (green LED2) as an output.
}
// the loop function runs over and over again forever
void loop()
{
// read the cross walk button value:
Xw_value=digitalRead(Xw_button);
if (Xw_value == LOW ){ // if crosswalk button (X-button) pressed
digitalWrite(yellow_LED1 , LOW); // This should turn off the YELLOW LED1
digitalWrite(green_LED1, LOW); // This should turn off the GREEN LED1
digitalWrite(yellow_LED2 , LOW); // This should turn off the YELLOW LED2
digitalWrite(green_LED2, LOW); // This should turn off the GREEN LED2
for (int i=10; i>= 0; i--)
{
Serial.print(" Count = ");
Serial.print(i);
Serial.println(" == Walk == ");
lcd.setCursor(0,1); // set the cursor to column 1, line 2
// lcd.clear(); // clears the display to print new message
lcd.print(" "); //===================== added
lcd.setCursor(0,1); // set the cursor to column 1, line 2
lcd.print(" == Walk == "); // Walk characters to the LCD.
lcd.print(i); // Print the count to the LCD
lcd.print(" "); // ================= add this line ==============
digitalWrite(red_LED1, HIGH); // This should turn on the RED LED1
digitalWrite(red_LED2, HIGH); // This should turn on the RED LED2 digitalWrite(bzr, HIGH);
tone(bzr, 1000);
delay(500);
digitalWrite(red_LED1, LOW); // This should turn off the RED LED1
digitalWrite(red_LED2, LOW); // This should turn off the RED LED2 digitalWrite(bzr, LOW);
noTone(bzr); // ==== Buzzer OFF =====
delay(500);
} // End of counter
// clears the display to print new message
// ===== lcd.clear();
lcd.setCursor(0,1); // set the cursor to column 1, line 2
lcd.print(" ");
} //
else // No Emergency ===
{
lcd.setCursor(0,1); // set the cursor to column 1, line 2
lcd.print(" = Do Not Walk ="); // Do Not Walk characters to the LCD.
Serial.println(" == Do Not Walk == ");
// The next three lines of code turn on the red LED1
digitalWrite(red_LED1, HIGH); // This should turn on the RED LED1
digitalWrite(yellow_LED1 , LOW); // This should turn off the YELLOW LED1
digitalWrite(green_LED1, LOW); // This should turn off the GREEN LED1
delay(1000); //Extended time for Red light#1 before the Green of the other side turns
// The next three lines of code turn on the red LED2
digitalWrite(red_LED2, LOW); // This should turn off the RED LED2
digitalWrite(yellow_LED2 , LOW); // This should turn off the YELLOW LED2
digitalWrite(green_LED2, HIGH); // This should turn on the GREEN LED2
delay(2000); // wait for 1 second
// The next three lines of code turn on the red LED1
digitalWrite(red_LED1, HIGH); // This should turn on the RED LED1
digitalWrite(yellow_LED1 , LOW); // This should turn off the YELLOW LED1
digitalWrite(green_LED1, LOW); // This should turn off the GREEN LED1
// The next three lines of code turn on the red LED2
digitalWrite(red_LED2, LOW); // This should turn on the RED LED2
digitalWrite(yellow_LED2 , HIGH); // This should turn off the YELLOW LED2
digitalWrite(green_LED2, LOW); // This should turn off the GREEN LED2
delay(2000); // wait for 1 second
// The next three lines of code turn on the red LED2
digitalWrite(red_LED2, HIGH); // This should turn on the RED LED2
digitalWrite(yellow_LED2 , LOW); // This should turn off the YELLOW LED2
digitalWrite(green_LED2, LOW); // This should turn off the GREEN LED2
delay(1000); //Extended time for Red light#2 before the Green of the other side turns
// The next three lines of code turn on the yellow LED1
digitalWrite(red_LED1, LOW); // This should turn off the RED LED1
digitalWrite(yellow_LED1 , LOW); // This should turn off the YELLOW LED1
digitalWrite(green_LED1, HIGH); // This should turn off the GREEN LED1
delay(2000); // wait for 1 second
// The next three lines of code turn on the yellow LED1
digitalWrite(red_LED1, LOW); // This should turn off the RED LED1
digitalWrite(yellow_LED1 , HIGH); // This should turn on the YELLOW LED1
digitalWrite(green_LED1, LOW); // This should turn off the GREEN LED1
// The next three lines of code turn on the red LED2
digitalWrite(red_LED2, HIGH); // This should turn on the RED LED2
digitalWrite(yellow_LED2 , LOW); // This should turn off the YELLOW LED2
digitalWrite(green_LED2, LOW); // This should turn off the GREEN LED2
delay(2000); // wait for 1 second
}// Emergency Button closing ============
}