Sixth Form Raspberry Pi Project for PAConsulting.com
Traffic-Improvement is software used to reduce waiting times at a traffic light system by comparing many factors that affect traffic flow, and then calculating the most efficient traffic light cycle timings to use. The Raspberry Pi is used to control the traffic lights, and runs a web interface that allows an engineer to change variables for that traffic system.
The inspiration for the project originated from the number of traffic lights at roadworks in our area. We noticed that drivers would be waiting for extended periods of time at lights, and in some cases just to have no cars going past before the lights would change.
This project aims to reduce the waiting time for drivers at traffic lights by using the optimum timings on the traffic light depending on the conditions. As a result, drivers will feel more positive when travelling and it will reduce traffic build-up at roadworks.
Firstly, we gathered information on current traffic statistics in the UK, from government sources. Furthermore, we researched into other factors that affect traffic flow, such as:
- human reaction time
- distraction chance
- weather effects
- probability of traffic
By combining these factors, we could determine the average waiting time of vehicles in the system for different road usages and traffic light timings. The first part of the software simulates the traffic system with these variables to return an average waiting for all the vehicles. We then plot these on a 3D graph which would then reveal the most efficient timings for different traffic levels for the fastest experience.
The web interface is powered by Python Flask. This site is used by the traffic engineers to generate a simulation of the current traffic conditions at their location, which will then determine and display the most efficient timings for the traffic lights.
Currently, the project generates a graph based on many variables, some of which the user can change through the interface. However, there are many improvements we would implement into future versions to make the project viable for use in the real world.
Our first major improvement would be to use number plate recognition technology through image detection using a Raspberry Pi camera. This could let the simulation determine different timings for different vehicle types that are found in the traffic light system.
Secondly, GPS modules for the Raspberry Pi could be used in order to calculate accurate distances between the lights. Our code currently uses fixed vector positions for the traffic lights, therefore implementing an automatic system to calculate the vectors based on the geographical position of the traffic lights would be more convenient.
Finally, another improvement would be automatic updates of the traffic light timings. The code would use the GPIO pins on the Raspberry Pi to control an external board which would change the colours on the traffic light. This would mean the engineer would only have to input the traffic conditions and the software would do the rest of the work.
Please watch our video on YouTube where we explain how the project works: https://youtu.be/tiH4ZLpnVOU
Here are some images of the project:
- 3D Graph displaying average waiting time for different road traffic levels and green light times
- Flask Web Interface
Software Used: All software listed is free.
-
Visual Studio Code.
-
Python 3.6
- Flask module for Web Interface.
- Simpy and other modules for simulation.
- MatPlotLib module for graphs.
-
HTML + CSS for Web Interface.
-
-
PuTTY (for SSH connection to Raspberry Pi).
Hardware Used:
- Raspberry Pi Model 3 B
-
Setup the Raspberry Pi in headless mode. Follow this guide here.
-
Connect to the Raspberry Pi using PuTTY or any other SSH software.
-
Install
git
,python3
,python3-pip
, andscreen
:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git python3 python3-pip screen
- Clone this repository:
git clone https://github.com/mitgobla/Traffic-Improvement TrafficImprovement
cd TrafficImprovement
- Install the required Python modules in
requirements.txt
:
cd Traffic-Light-Management
sudo python3 -m pip install -r requirements.txt
- Find out the IP address of the Raspberry Pi. Record it for use later.
hostname -I
- Create a new screen instance so the code can run after you have disconnected.
screen bash
# You should now be on a blank terminal
- Simply run
main.py
using Python.
# Make sure you're in the Traffic-Light-Management directory.
python main.py
- You should see in terminal this output:
# ...
Debugger PIN: XXX-XXX-XXX
Running on http://0.0.0.0:80/ Press (CTRL+C to quit)
-
On a web browser on a device that is connected to the same network as the Raspberry Pi, navigate to the IP address you recorded earlier (the IP address of the Raspberry Pi).
-
The web interface to configure the simulation should appear.
- PA Consulting Insight 2019 Article
- PA Consulting PAPiAwards19 Video
- Tivy-Side Advertiser
- E&T Article
- newelectronics Article
- ElectronicsWeekly Article
- Ysgol Gyfun Emlyn Article
Edward Upton (engiego)
Ben Dodd (mitgobla)