smart traffic light system
TRANSCRIPT
Smart Traffic Light System 2015
Page | 0
Smart Traffic Light System 2015
Page | 1
Al Balqa’ Applied University
Faculty of Engineering Technology
Graduation Project
Smart Traffic light System Presented to the Department of Mechatronics Engineering
In Partial Fulfillment Of the Requirements
For the Degree of
Bachelor of Science in Engineering Technology
Mohammad El-Badawi Mohammad Awawdeh Abdullah Ashour Abdullah Abd Alkareem Ahmad Al-Badawi Supervisor: Dr. Lina Momani
January, 2015
Smart Traffic Light System 2015
Page | 2
Dedication
This project is sincerely dedicated to:
Our prophet
MOHAMMED [PBUH]
Mercy of all humankind
Our parents:
Who have supported and encouraged us through the past years.
Our instructors:
Who have accompanied us through the undergraduate period.
Our beloved homeland.
Smart Traffic Light System 2015
Page | 3
Acknowledgment
After Thanks Our God We would like to express our deep appreciation to
Dr.Lina Momani for all her suspension encouragement with support and guidance
in supervising throughout the course of this project.
Finally, we must thank all our closest friends and family members who support us
throughout the way and gave us all the chances to get where we are right now.
Thank you all...
Smart Traffic Light System 2015
Page | 4
ABSTRACT
raffic jams which caused by unutilized time of traffic light to pass as much as
possible number of vehicles on traffic light intersections, and the timing delay
method that applied on the current traffic light system is not feasible to organize the traffic
process for vehicles, also emergency vehicles obstruction, missing guidelines, and
electrical power cut-off that happens to the traffic light intersections are growing problems
that needs to be solved. The aim of this project is developing a traffic light that can solve
these problems, that can be done by making a smart system that counts the cars on each
side of traffic light and estimates time for every traffic light, and measures a real time
frequencies from microphone and compare them to siren frequencies to let emergency
vehicles passes, also the system has a display boards for displaying temperature degree and
guidelines, and a solar tracking energy system that can solve the electrical power cut-of
problems.
T
Smart Traffic Light System 2015
Page | 5
TABLE OF CONTENTS
ACKNOWLEDGEMENTS ........................................................................... 3
ABSTRACT ............................................................................................... 4
TABLE OF CONTENTS .............................................................................. 5
1 INTRODUCTION ............................................................................. 7
1.1 LITERATURE SURVAYES ............................................................ 9
1.1.1 CAR DENSITY USING IMAGE PROCESSING ...................................... 9
1.1.2 EMERGENCY SIGNAL DETECTING .................................................... 10
1.1.3 ALTERNATIVE ENERGY ................................................................... 11
2 THEORY ............................................................................................ 12
2.1 CAR DETECTING AND TIME CALCULATION .......................... 12
2.2 EMERGENCY DETECTING AND SIREN FREQUANCIES ........ 14
2.3 SOLAR TRACKING SYSTEM ....................................................... 18
3 PROPOSED SYSTEM ...................................................................... 21
3.1 DESCRIPTION ................................................................................ 21
3.2 OBJECTIVES ................................................................................... 22
3.3 DESIGN ............................................................................................ 22
3.3.1 CAR DETECTION BASED ON IMAGE PROCESSING ............................. 23
3.3.2 EMERGENCY DETECTING AND SIREN FREQUENCIES ......................... 25
3.3.3 SOLAR TRACKING SYSTEM .............................................................. 27
3.3.4 DISPLAY BOARDS ............................................................................ 29
4 SELECTION OF COMPONENTS .................................................. 31
4.1 CAR DETECTING BASED ON IMAGE PROCESSING ............................... 31
4.2 EMERGENCY DETECTING AND SIREN FREQUENCIES .......................... 34
4.3 SOLAR TRACKING SYSTEM ................................................................ 34
4.4 DISPLAY BOARDS .............................................................................. 38
5 SIMULATION ................................................................................... 39
5.1 TRAFFIC LIGHTS SIMULATION ........................................................... 39
5.2 DISPLAY BOARDS SIMULATION ......................................................... 40
5.3 EMERGENCY DETECTING SIMULATION .............................................. 41
Smart Traffic Light System 2015
Page | 6
5.4 SOLAR TRACKING SYSTEM SIMULATION ........................................... 42
5.5 SIMULATION OF PROPOSED SYSTEM .................................................. 43
6 IMPLEMENTATION ....................................................................... 44
6.1 HARDWARE ....................................................................................... 44
6.1.1 PROTOTYPE COMPONENTS .............................................................. 46
6.2 SOFTWARE ......................................................................................... 47
6.2.1 CAR DETECTION BASED ON IMAGE PROCESSING ............................ 47
6.2.2 EMERGENCY DETECTING ................................................................ 50
6.3 SOLAR TRACKING SYSTEM ................................................................ 52
6.4 DISPLAY BOARDS .............................................................................. 52
7 TESTING AND PERFORMANCE MEASURE ............................. 53
8 CONCLUSIONS ................................................................................ 56
APPENDICES....................................................................................... 57
APPENDIX 1.......................................................................................... 58
APPENDIX 2.......................................................................................... 60
APPENDIX 3.......................................................................................... 63
APPENDIX 4.......................................................................................... 67
APPENDIX 5.......................................................................................... 68
APPENDIX 6.......................................................................................... 70
REFERENCES ....................................................................................... 72
Smart Traffic Light System 2015
Page | 7
CHAPTER 1
INTRODUCTION
owadays traffic system faces different problems; many of these problems
obstruct traffic process, which are usually related to the traffic light, where
the control system of traffic light became necessary need and not just a secondary system,
however the increase of population growth followed by increased number of cars, caused
traffic jam and obstruction of the emergency vehicles. Other problems such as electrical
power cut-off, technical faults and missing way guidelines are existed.
Through observation the traffic in Jordan, it's become clear that most of the
problems that has been mentioned previously exist in traffic lights, where the traffic light
can be considered as gathering point for vehicles, this point need a system to monitor and
control the traffic, in terms of the traffic light sequence, speed control, investigation of car
accidents and link them to the traffic department. It also needs to contain many features
like path guidelines, weather, speed limits, and clock ... etc.
After searching and studying of all possible solutions for these problems in the
traffic system, the result of this search was that there are some countries that have solved
some of them, but not all of these problems in one system. They have developed some
partial systems to solve specific issues. However, the purpose of this project is to develop
a smart universal system, which includes all features and solutions for the problems faced
in current traffic systems. The integration of all these different techniques that accomplish
higher efficiency and more intelligence. This system will perform some missions of
controlling the traffic process automatically.
N
Smart Traffic Light System 2015
Page | 8
However, the problems that occur in traffic light and their causes should be
discussed with more details, these problems are:
1- Traffic jam :
Current traffic light don’t care about cars distribution in quad intersection, so it
can do a traffic jam in different sides, and this problem related to non-direct
feedback system.
2- Obstruction of emergency vehicles :
Sometimes emergency vehicles are stuck on one side of the intersection with
red light, that make the drivers take an action and pass the red light to let the
emergency vehicles pass on, that’s why a confusion happens at the intersection,
which leads to delay the emergency vehicle.
3- Electrical power cut-off :
The traffic light system in Jordan suffers from frequent power outages where
there is no alternative power source to compensate the main source of street energy,
and that leads to state of confusion in traffic, which calls for The presence of a
policeman to regulate the functioning of the movement, but this solution consumes
time, effort and cost.
4- Guidelines:
The driver in Jordan faces in most intersections a problem in determining the
direction to his/her destination that he/she wants to go, that’s because of the lack of
signboards, which may sometimes cause accidents.
Smart Traffic Light System 2015
Page | 9
1.1 LITERATURE SURVAYES
There are many Literature surveys that addressed Smart traffic light systems, a
summary of these surveys discussed below:
1.1.1 Car Density Using Image Processing:
Chandrasekhar, et al, addressed: “a system that implement image processing
algorithm in real time traffic light control which will control the traffic light efficiently.
A web camera is placed in each stage of traffic light that will capture the still images
of the road where we want to control the traffic. Then those captured images are
successively matched using image matching with a reference image which is an empty
road image. The traffic is governed according to percentage of matching” [1].
Nagaraj, et al, addressed: “Existing commercial image processing systems work
well in free-flowing traffic, but the systems have difficulties with traffic congestion,
shadows and various lighting conditions. The suggested feature-based tracking system
will detect vehicles under these challenging conditions. Using image processing
operations to calculate traffic density is cost effective as cameras are cheaper and
affordable devices compared to any other devices such as sensors” [2].
Dangi, et al, addressed: “The image sequences from a camera are analyzed using
various edge detection and object counting methods to obtain the most efficient
technique”. Subsequently, the number of vehicles at the intersection is evaluated and
traffic is efficiently managed. The paper also proposes to implement a real-time
emergency vehicle detection system. In case an emergency vehicle is detected, the lane is
given priority over all the others” [3].
Smart Traffic Light System 2015
Page | 10
1.1.2 Emergency signal detecting:
Fazend addressed: “A system has been investigated for the detection of incoming
direction of an emergency vehicle. Acoustic detection methods based on a cross
microphone array have been implemented. It is shown that source detection based on time
delay estimation outperforms sound intensity techniques, although both techniques
perform well for the application. The relaying of information to the driver as a warning
signal has been investigated through the use of ambisonic technology and a 4 speaker array
which is ubiquitous in most modern vehicles. Simulations show that accurate warning
information may be relayed to the driver and afford correct action” [4].
Hashem addressed: “This system was designed to be operated when it received
signal from emergency vehicles based on radio frequency (RF) transmission and used the
Programmable Integrated Circuit (PIC) 16F877A microcontroller to change the sequence
back to the normal sequence before the emergency mode was triggered. This system will
reduce accidents which often happen at the traffic light intersections because of other
vehicle had to huddle for given a special route to emergency vehicle. As the result, this
project successful analyzing and implementing the wireless communication; the radio
frequency (RF) transmission in the traffic light control system for emergency vehicles. The
prototype of this project is using the frequency of 434 MHz and function with the sequence
mode of traffic light when emergency vehicles passing by an intersection and changing the
sequence back to the normal sequence before the emergency mode was triggered. In future,
this prototype system can be improved by controlling the real traffic situation, in fact
improving present traffic light system technology” [5].
Smart Traffic Light System 2015
Page | 11
1.1.3 Alternative energy:
Hassan and others addressed: “A photovoltaic system is needed in order to use this
energy continuously. The results of the investigation of components, design, and market
availability are shown in the paper. Solar cells, which are used for absorbing sunlight and
generating electric current, are the main source for the system’s operation. A charge
controller is used to control the flow of charge through the battery and to protect the battery
from overcharging and deep discharging. A dc-dc converter is used to regulate the output
voltage which depends on the type of dc to dc converter. Lead acid batteries are used as
the electric energy storage for the PV system to use electrical energy in the absence of
sunlight. The principle operation of the system and the feasibility of using it for rural area
with no power grid have been studied. For this project, a mount tracker was constructed
that enabled the solar panel to be placed at 0, 15, 30, 45, 60, 75 and 90 degree angles in
order to determine which angle and what time provides the optimum voltage. Experimental
results for different angles of radiation at different times of the day and different days of
the year are shown in the paper” [6].
Smart Traffic Light System 2015
Page | 12
CHAPTER 2
THEORY
s the problem of urban traffic congestion spreads, there is a pressing need
for the introduction of advanced technology and equipment to improve the
state of traffic control. Traffic problems nowadays are increasing because of the growing
number of vehicles and the limited resources provided by current infrastructures. The
simplest way for controlling a traffic light uses timer for each phase. Another way is to use
electronic sensors in order to detect vehicles, and produce signal that cycles. Project
propose a system for controlling the traffic light by image processing. The system will
detect vehicles through images instead of using electronic sensors embedded in the
pavement.
2.1 CAR DETECTING AND TIME CALCULATION
The system will estimate the number of cars at each side of traffic light based on
image processing, then the system will estimate the turn on time for each traffic light
according to equation (2.1.1).
tY = K × XY……………..(2.1.1)
Where,
ty: turn on time.
XY: number of cars.
K: is the time average constant that every car can take to pass the traffic light. It
can be changed due to type of intersection.
The system also checks if the turn on time smaller than the maximum time and
greater than zero, then system turn on the traffic light for one side with time delay equal
the turn on time (ty). After finish, the system turn off the traffic light and continue the
sequence.
A
Smart Traffic Light System 2015
Page | 13
If ty is greater than tmax the system will determine that ty=tmax, where tmax is a specific
value of time that prevent the time delay estimated exceed over an acceptable value.
To give more clearance assume there are four sides and the number of cars in each
side are 4,1,3,0, respectively. The tmax=18 sec. The time constant K=6 sec. Then the turn
on time for each side:
ty1= 6 × 4 = 24 sec. but ty1 is greater than tmax, so ty1 = tmax = 18 sec.
ty2= 6 × 1 = 6 sec.
ty3= 6 × 3 = 18 sec.
ty4= 6 × 0 = 0 sec.
Table (2.1) shows the time diagram of the turn on time for each side.
Table (2.2) shows the time according to cars number.
Table (2.3) shows the traffic light sequence.
Table (2.1): Time diagram.
Table (2.2): Time according to cars number. Table (2.3): Traffic light sequence.
TIME 6 12 18 24 30 36 42
A
B
C
D
Traffic
Light Count Time (sec) Time / Count
A 4 18 6/1
B 1 6 6/1
C 3 18 6/1
D 0 0 6/1
Traffic
Light Turn
A 1
B 2
C 3
D 4
Smart Traffic Light System 2015
Page | 14
2.2 EMERGENCY DETECTING AND SIREN FREQUANCIES
The system detect emergency vehicles by measuring frequencies of the sounds that
enter the mic, and compare it to the siren frequencies, if the frequencies are in the range of
the siren sound, the system will interrupted, then all the traffic lights on the intersection
will turns to red, and the traffic light on the side of the emergency vehicle will be turned to
green.
Sirens are devices that produce warning sounds. Siren sounds are intended to help
alert the public that an emergency vehicle (e.g., police car, ambulance, fire truck) is nearby
and responding to an emergency. These sounds should be recognized as the call for the
right-of-way of the vehicle.
Two widely used and recognized sounds are available with electronic siren system.
A wail is designed to mimic the intrinsic sound of a mechanical siren. This sound is
produced by slow increases and decreases in frequency. A yelp cycles through a range of
frequencies in a manner similar to a wail, but at a faster cycle rate. Other sounds, less
commonly used, are available with many siren systems. Most siren systems also have a so-
called manual control on the amplifier, which is a momentary contact switch that permits
intermittent, rather than continuous, operation [7].
Smart Traffic Light System 2015
Page | 15
In the United States, the most widely recognized and cited documents that specify
test methods, performance requirements, and installation practices for emergency vehicle
sirens are those listed in Table (2.4) [7].
Table (2.4): Documents that specify test methods, performance requirements.
As the siren sound consists of wail, yelp, and Hi-Low frequencies, the Wail and
yelp sounds are produced by increases and decreases in the frequency of a square wave.
Any particular wail or yelp sound is characterized by its cycle rate and fundamental
frequency range. For a square wave, harmonics are present at frequencies higher than the
frequency of the square wave itself, which is the fundamental frequency of the square wave.
Examples of how the square wave frequency varies with time for wail and yelp are shown
in Figure (2.1) [7].
Description Abbreviated description used in this
guide
Section 3.14.6 of the Federal specification
KKK–A–1822 for ambulances, produced
by the U.S. General Services
Administration (GSA).
GSA K-Specification
Title 13, Article 8 of the California Code
of Regulations (CCR), produced by the
California Highway Patrol.
CCR Title 13
Emergency Vehicle Sirens -SAE J1849
August 1995 Recommended Practice,
produced by the Society of Automotive
Engineers (SAE).
SAE J1849
Smart Traffic Light System 2015
Page | 16
Figure (2.1): Examples of wail and yelp with cycle rates of 20 cycles per minute (cpm) and 240
cpm, respectively.
Tables (2.5) and (2.6) summarize the frequency and cycle rate requirements of the
GSA K-Specification, CCR Title 13, and SAE J1849 for the wail and yelp sounds, [7].
See the Appendix (1).
Smart Traffic Light System 2015
Page | 17
There are some considerations that must be taken for sound frequencies
measurements, as follows:
Echoes
Echoes are just time-shifted, attenuated versions of the original signal the frequency
content of the echo does not change, thus any echoes will actually help in the detection of
a siren.
Doppler Effect
Where
Vr is the velocity of the receiver relative to the medium; positive if the receiver is
moving towards the source (and negative in the other direction), in the project the receiver
is constant, so = 0.
VS is the velocity of the source relative to the medium; positive if the source is
moving away from the receiver (and negative in the other direction).
V is the velocity of waves in the medium (sound travels at 345 m/s in air) The car
ambulance moving at 90 Km/Hour = 25 m/s, relative to speed of sound in air, there will
not be a huge shift in frequency.
Smart Traffic Light System 2015
Page | 18
2.3 SOLAR TRACKING SYSTEM
Solar Tracking System is a device for orienting a solar panel or concentrating a
solar reflector or lens towards the sun. Concentrators, especially in solar cell applications,
require a high degree of accuracy to ensure that the concentrated sunlight is directed
precisely to the powered device. There are two types of tracking system can be driven by
linear actuators.
Types of solar tracking system:
Single Axis Tracking System.
Dual Axis Tracking System.
A single axis system, Figure (2.2), is most commonly used for most standard PV cell
arrays. The cells are mounted on a moving axis which is oriented to rotate along the earth’s
axis. These types of trackers usually have simple levers which can be used to tilt the cells
depending on the season to still maximum the exposure to the sunlight.
This is the type of tracking system most commonly used for residential solar arrays, as
well as many smaller commercial arrays. While single axis trackers don’t allow for as much
exposure to the sun’s rays as dual axis systems, their main advantage lies in the price.
Single axis systems cost only a small fraction of what their dual axis counterparts do, which
makes them ideal for all but the biggest solar arrays.
Figure (2.2): Single Axis Tracking System.
Smart Traffic Light System 2015
Page | 19
Dual axis systems, Figure (2.3), are typically used in concentrated solar power
systems, where it becomes necessary to completely orient the mirrors or reflectors so that
the sun’s rays are redirected onto their intended focal point. This type of solar tracker is
usually referred to as a heliostat, and consists of mirrors which rotate and tilt to focus their
energy on a fixed collector.
Figure (2.3): Tracking Dual axis systems.
Dual axis systems - as their name suggests - are capable of moving in two
directions, on both the horizontal and the vertical axis so they can make complete use of
the sun’s rays for the entire day. Another type of dual axis system is the moving collector,
which is the exact same concept as the single axis tracker, except these systems are still
capable of moving on the horizontal and vertical axes, thus increasing the amount of time
they are directly exposed to the sunlight.
The major advantage of dual tracking systems is that they allow the solar cells to
be placed much closer together, thus reducing the total amount of space necessary for a
large solar array.
Smart Traffic Light System 2015
Page | 20
This means that much more power can be produced in a small area, and because of
the dual axis system, this power can also be produced in a much more efficient manner as
well. Almost all large scale commercial solar applications utilize dual axis systems for their
reliability and efficiency, and they allow for much less need for conventional types of
power which often burn fossil fuels and release pollution into the atmosphere
How the solar sensor works
The system contains 4 LDRs sensors with sheets between them, Figure (2.4), the
withe stips are the LDRs.
When the stick on top is righted to the sun or the brightest point the four LDRs get
the same amount of light on them. When right-top, right-down, and left-down LDRs are
in the shadow, and the left-top get the most light, then the controller send commands to
motors to make the same amount of light in each (LDRs). And the same thing on other
sensor.
Figure (2.4): sensor of 4 LDRs with sheets between them
Smart Traffic Light System 2015
Page | 21
CHAPTER 3
PROPOSED SYSTEM
3.1 DESCRIPTION
urrent traffic lights do not have feedback, they only change signal based on
time principle, and such a system causes many problems that was previously
mentioned. In this project the feedback signal is entered to traffic light system by adding
camera on the intersection, and use this camera to count the number of vehicles for each
path by using image processing technique.
This technique analyze the images from camera at the same time, and import to the
controller the number of vehicles for each direction, then the controller estimates a period
of time needed by each path to open each traffic light based on the number of vehicles in a
fixed sequence, it is also used to monitor the traffic.
The system consists additional features such as opening one traffic light and closing
the others when it detects emergency vehicle siren, and the second feature is adding
alternative power source that depends on the solar energy, and it is used when the electrical
power source is cut-off.
Also, accessories are added to the system such as clock and temperature sensor that
allows the drivers to know the time and air temperature, and direction guidelines to guide
the drivers to the destination that they want.
C
Smart Traffic Light System 2015
Page | 22
3.2 OBJECTIVES
After studying the principle of work of the traffic light and identify the problems
that related to it, it had to determine the desired objectives of this project to find appropriate
solutions to solve these problems, the most important objectives to be achieved are:
1. Reduce the traffic jam.
2. To give more flexibility to the traffic light system.
3. Use solar energy as a source of power under power cut-off cases.
4. Identify directions of local places using digital guidelines.
5. Develop control system can handle with emergency cases.
3.3 DESIGN
The system relies on the principle of priority of traffic, the priority always for
emergency vehicles, the system checks the signal coming from the Emergency vehicle, if
there is a logic signal (1) the system turn off all the traffic lights and determine the direction
of the emergency vehicle and then turn on the traffic light that the emergency vehicle is
coming from, and wait until the emergency vehicle passed the traffic light, and then return
to check the signal coming from the emergency vehicle. If there is a logic signal (0) the
system will determine the next traffic light turn depending on the traffic lights sequence.
Smart Traffic Light System 2015
Page | 23
3.3.1 Car detection based on Image Processing
Image processing is a form of signal processing for which the input is an image,
such as a photograph or video frame; the output of image processing may be either an
image or a set of characteristics or parameters related to the image. Most image-processing
techniques involve treating the image as a two-dimensional signal and applying standard
signal-processing techniques to it.
Car detection process is performed by Image processing on the images which
picked from video frame that came from camera. Computer is used to perform image
processing by Matlab™ software.
3.3.1.1 System Requirements
System Require these hardware to be implemented, a Personal Computer (Main
Controller), Webcam Camera, Arduino (Mega), Electric wires, and power supply.
3.3.1.2 Bock Diagram
Figure (3.1) show the hardware of the process.
Figure (3.1): Car Detection Block Diagram.
Camera Computer Arduino Traffic
Lights
Smart Traffic Light System 2015
Page | 24
Check turn [Y]
Check number
of cars at X[Y]
Estimate turn
on time tY
If
0<tY<tmax
If tY=0
If ti>tY
No Yes
tY = tmax
Turn on traffic
side (Y) for tY
Yes No
Yes No
3.3.1.3 Flow chart
Figure (3.2) show the sequence of operations of the process.
Y: Side turn.
XY: Number of cars at Y side.
ty: Turn on time.
ti: instantaneous time.
tmax: Maximum time.
Figure (3.2): Car detecting flow chart.
Smart Traffic Light System 2015
Page | 25
3.3.2 Emergency detecting and siren frequencies
The system consists of a microphone with built in amplifier and filter, Figure (3.3),
and an Arduino. The system will detect the emergency vehicles by its siren frequencies,
where the siren audio will be the input and the mice is the sensor that will receive the siren
sound, and the Arduino is the main controller that will open the way for the emergency
vehicles by measuring the input frequencies and compare them to the standard siren
frequency, where the output is a signal that will interrupt the traffic light sequence and open
the traffic light on the side of the emergency vehicle.
Figure (3.3): Microphone with built in amplifier and filter.
3.3.2.1 System Requirements
System Require these hardware to be implemented, Arduino UNO, Microphone with
built in amplifier and filter, Electric wires, and Power supply.
3.3.2.2 Bock Diagram
Figure (3.4) show the hardware the process.
Figure (3.4): Emergency Detecting Block Diagram.
Microphone
Arduino
Traffic
light
Controller
Traffic
Lights
Smart Traffic Light System 2015
Page | 26
3.3.2.3 Flow chart
Figure (3.5) show the emergency signal detecting process.
Measure
frequencies of
audio signals
Calculate
average of
measured
frequencies
If
fmin<frq<fmax
No Yes
Interrupt traffic
light sequence
Turn all traffic
lights to Red
Turn the traffic
light on the
side of the
emergency
vehicle to
green for tmax
Return to main
sequence
Receive audio
signals
Figure (3.5): Emergency signal detecting flow chart.
Smart Traffic Light System 2015
Page | 27
3.3.3 Solar tracking system
This model of the system, contains a panel which is sensing the sun light,
until the controller receives analog data from the solar sensor, and convert it to
digital data by internal ADC on it. Then this convert data processing by program
install in control unit, then sending it to interfacing output unit which sending
signals to two servo motor to change the position of the PV panel.
3.3.3.1 System Requirements
System Require these hardware to be implemented, Arduino UNO, Servo motors,
solar sensor, Electric wires, Power supply, Battery, and Solar cell.
3.3.3.2 Bock Diagram
Figure (3.6) show the hardware the process.
Figure (3.6): Solar tracking Block Diagram.
Solar Sensor
Arduino
Servo
Motors
Smart Traffic Light System 2015
Page | 28
Calculate
voltage average
for every side
(VL, VR, VU, VD)
Read solar
sensor voltage
for each side
Yes
No
Estimate difference
between LEFT side
and RIGHT side
MOVE TO
REQUIRED
POSITION
Estimate difference
between UP side
and DOWN side
If VU>VD || VD>VU If VR>VL || VL>VR
Yes
No
3.3.3.3 Flow chart
Figure (3.7) show the Solar tracking process.
Figure (3.7): Solar tracking Flow chart.
VL: Left side average voltage.
VR: Right side average voltage.
VU: Upside average voltage.
VD: Down side average voltage.
Required position: the position where the four solar sensors give same voltage.
Smart Traffic Light System 2015
Page | 29
3.3.4 Display boards
Liquid Crystal Display (LCD), Figure (3.8), are added to display the guidelines of
the surrounding area of traffic light, and also display the temperature and the speed limit.
For temperature measuring a temperature transducer (LM35), Figure (3.9), is used to sense
the temperature and convert it to a voltage that represent the actual temperature, based on
Equation (3.3.1). Then the controller (Arduino) display the temperature on the LCD in
Celsius.
Temp = (5 × Vin × 100) / 1024………. (3.3.1)
Where,
Temp: actual temperature.
Vin: analog voltage from LM35 transducer.
Figure (3.8): Blue 16×2 LCD.
Figure (3.9): LM35 Transducer.
3.3.4.1 System Requirements
System Require these hardware to be implemented, Arduino UNO, LM35
Transducer, Four LCD's, Electric wires, and Power supply.
Smart Traffic Light System 2015
Page | 30
3.3.4.2 Bock Diagram
Figure (3.10) show the hardware the process.
Figure (3.10): Display Boards Block Diagram.
3.3.4.3 Flow chart
Figure (3.11) show temperature measuring process.
Convert
temperature to
voltage
Estimate actual
temperature
Display
Temperature,
guidelines, and
speed limit.
Sense
temperature
Figure (3.11): Display Boards flow chart.
LM35
Transducer
Arduino
LCD’s
Smart Traffic Light System 2015
Page | 31
CHAPTER 4
SELECTION OF COMPONENTS
4.1 Car Detecting based on Image Processing
This sub system need to be implemented a Personal Computer, Arduino (Mega),
WebCam (Microsoft HD 3000).
4.1.1 Comparison between PC and Raspberry Pi.
Car detection process is performed by Image processing on the images which
picked from video frame that came from camera. At first Open Computer Vision (OpenCV)
Library is used to implement image processing. Raspberry Pi® microprocessor was chosen
to accomplish the process.
The Raspberry Pi is a credit card-sized single-board computer developed in
the UK by the Raspberry Pi Foundation with the intention of promoting the teaching of
basic computer science in schools. Shown in Figure (4.1).
Figure (4.1): Raspberry Pi computer Model B+.
Smart Traffic Light System 2015
Page | 32
Raspberry Pi is a good option for several applications of image processing because
it has many features such as Compatible with many camera devices, it Control any
hardware devices using (GIOP), it can Connect to the internet by Wi-Fi or LAN cable, It
can controlled remotely by a PC also it work with Linux operating system.
In other hand it has some disadvantages like the Processor speed is slow comparing
with PC microprocessor, it’s only 800MHz. This slowing in speed is not suitable for this
project because there is a lack in processing and sending the desired data to the
microcontroller.
So that Computer is used to perform image processing by Matlab™ software
because computer speed is high enough to implement image processing.
4.1.2 Comparison between Arduino (Mega) and PIC Microcontroller.
Arduino Mega, Figure (4.2), is an open-source physical computing platform based on
a simple I/O board and a development environment that implements the Processing/Wiring
language.
Figure (4.2): Arduino Mega.
Smart Traffic Light System 2015
Page | 33
Microchip's 16F877A 8-Bit Processor PIC Microcontroller has 8K of program space
and 33 I/O lines, 8 of which are 10bit Analog to Digital converter capable. Runs up to
20MHz with external crystal.
Arduino mega is chosen because it’s easier in use, more simple in programing, don’t
need a power circuit, it also more reliable.
4.1.3 Comparison between Microsoft HD 3000 Camera and Normal camera
Microsoft HD 3000 camera, Figure (4.3), has many features such as HD-quality
image, 16:9 format offers cinematic video recording, and TrueColor technology
automatically delivers bright and colorful video, in virtually all lighting conditions.
Microsoft HD 3000 camera is chosen because it give a high quality image which is
necessary for image processing, also it has a built in processor which is good for processing
speed, where computer will not waste time for image processing.
Figure (4.3): Microsoft HD 3000 camera.
Smart Traffic Light System 2015
Page | 34
4.2 Emergency Detecting and Siren Frequencies
This sub system need to be implemented an Electret Microphone Breakout and
Arduino.
4.2.1 Comparison between Electret Microphone Breakout with normal microphone
Microphone Breakout has these features, it couples a small electret microphone with
a 100x op-amp to amplify the sounds of voice, door knocks, etc. Loud enough to be
picked up by a microcontroller’s Analog to Digital converter, it also unit comes fully
assembled. Works from 2.7V up to 5.5V.
Electric microphone breakout is chosen because that normal microphone needs an
amplifier circuit and a filter circuit, where electric microphone breakout comes with
built in amplifier and built in filter.
4.3 Solar Tracking System
This sub system need to be implemented 2 servo's motors (995, metal gear), 4 light
depending resistors (LDR) (sensing element), 4 resistors (10K), Arduino (controller),
and 2 potentiometers (value doesn't matter).
4.3.1 Comparison between Servo Motor and Stepper Motor
A servomotor, Figure (4.4), is a rotary actuator that allows for precise control of angular
position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for
position feedback. It also requires a relatively sophisticated controller, often a dedicated
module designed specifically for use with servomotors.
Smart Traffic Light System 2015
Page | 35
Figure (4.4): Servo motor.
Servo Motors are fast, high torque, accurate rotation within a limited angle – Generally
a high performance alternative to stepper motors, but more complicated setup with PWM
tuning. Suited for robotic arms/legs or rudder control etc.
Stepper Motors are Slow, precise rotation, easy set up & control – Advantage over
servo motors in positional control. Where servos require a feedback mechanism and
support circuitry to drive positioning, a stepper motor has positional control via its nature
of rotation by fractional increments. Suited for 3D printers and similar devices where
position is fundamental.
Servo motors has been chosen because it operate at a range of speeds without
overheating, operate at zero speed while retaining enough torque to hold a load in position,
and operate a very low speeds for long periods without overheating.
4.3.2 Light depending resistors (LDR)
A photoresistor or light-dependent resistor (LDR), Figure (4.3.2), or photocell is
a light-controlled variable resistor. The resistance of a photoresistor decreases with
increasing incident light intensity; in other words, it exhibits photoconductivity. A
photoresistor can be applied in light-sensitive detector circuits, and light- and dark-
activated switching circuits.
Smart Traffic Light System 2015
Page | 36
Figure (4.5): Light depending resistors (LDR).
A photoresistor is made of a high resistance semiconductor. In the dark, a
photoresistor can have a resistance high, as shown in Figure (4.6), while in the light, a
photoresistor can have low resistance as shown in Figure (4.7). If incident light on a
photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give
bound electrons enough energy to jump into the conduction band. The resulting free
electrons (and their hole partners) conduct electricity, thereby lowering resistance. The
resistance range and sensitivity of a photoresistor can substantially differ among dissimilar
devices. Moreover, unique photoresistors may react substantially differently to photons
within certain wavelength bands.
Figure (4.6): High resistance. Figure (4.7): Low resistance.
Smart Traffic Light System 2015
Page | 37
4.3.3 Potentiometer
This potentiometer, Figure (4.8), is a two-in-one, good in a breadboard or with a
panel,. It’s a fairly standard linear taper 10K ohm potentiometer, with a grippy shaft. It’s
smooth and easy to turn, but not so loose that it will shift on its own. We like this one
because the legs are 0.2" apart with pin-points, so you can plug it into a breadboard or
perfboard. Once you're done prototyping, you can drill a hole into your project box and
mount the potentiometer that way. .
Figure (4.8): Potentiometer.
Smart Traffic Light System 2015
Page | 38
4.4 Display Boards
This sub system need to be implemented Four LCD’s, LM35 Temperature
Transducer, and Arduino.
4.4.1 LCD’s
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide
range of applications. A 16x2 LCD display is very basic module and is very commonly
used in various devices and circuits. A 16x2 LCD means it can display 16 characters per
line and there are two lines in this LCD. This LCD has two registers, namely, Command
and Data.
4.4.2 Comparison between LM35 Transducer with Thermistor
Thermistor need an electric circuit to work, however LM35 don’t need, it easy to
use, and it can sense a wide range of temperature bigger than thermistors.
Smart Traffic Light System 2015
Page | 39
CHAPTER 5
SIMULATION
efore buying the project hardware pieces, all systems has been
simulated in PROTEUS™ program. Simulation is good for
testing the project in both side hardware connection and software. It gives an
indication if the system can be applied or not.
5.1 Traffic Lights Simulation
The Figure (5.1) illustrates the schematic diagram of traffic lights
connections with Arduino mega, where it can be simulated by PROTEUS as
it’s a real.
Figure (5.1): Traffic lights simulation.
B
Smart Traffic Light System 2015
Page | 40
5.2 Display Boards Simulation
The Figure (5.2) illustrates the schematic diagram of Display Boards
and LM35 transducer connections with Arduino UNO. Where it can be
simulated by PROTEUS as it’s a real.
Figure (5.2): LCD's simulation.
Smart Traffic Light System 2015
Page | 41
5.3 Emergency Detecting Simulation
The Figure (5.3) illustrates the schematic diagram of Microphone and
filter circuit connections with Arduino UNO. Where it can be simulated by
PROTEUS as it’s a real.
Figure (5.3): Emergency Detecting Simulation.
C1(1)
DIGITAL (~PWM)
ANALOG IN
ATMEGA328P-PU1121
~~
~
~~
~
TX
RX
PD
0/R
XD
0P
D1
/TX
D1
PD
2/I
NT0
2P
D3
/IN
T1
3P
D4
/T0
/XC
K4
PD
5/T
15
PD
6/A
IN0
6P
D7
/AIN
17
PB
0/I
CP
1/C
LK
O8
PB
1/O
C1A
9P
B2
/SS
/OC
1B
10
PB
3/M
OS
I/O
C2A
11
PB
4/M
ISO
12
PB
5/S
CK
13
AR
EF
PC
5/A
DC
5/S
CL
A5
PC
4/A
DC
4/S
DA
A4
PC
3/A
DC
3A
3P
C2
/AD
C2
A2
PC
1/A
DC
1A
1P
C0
/AD
C0
A0
RE
SE
T
ARD1ARDUINO UNO R3
PWM COMUNICATIOND
IGIT
AL
ANALOG IN
ATMEGA256016AU 1126
TX
0
TX
3
TX
2
TX
1
SD
A
SC
L
RX
0
RX
3
RX
2
RX
1
PD
0/S
CL
/IN
T0
21
PD
1/S
DA
/IN
T1
20
PD
2/R
XD
1/I
NT2
19
PD
3/T
XD
1/I
NT3
18
PH
0/R
XD
217
PH
1/T
XD
216
PJ0
/RX
D3
/PC
INT9
15
PJ1
/TX
D3
/PC
INT10
14
PE
0/R
XD
0/P
CIN
T8
0P
E1
/TX
D0
/PD
O1
PE
4/O
C3
B/I
NT4
2P
E5
/OC
3C
/IN
T5
3P
G5
/OC
0B
4P
E3
/OC
3A
/AIN
15
PH
3/O
C4A
6P
H4
/OC
4B
7
PH
5/O
C4C
8P
H6
/OC
2B
9P
B4
/OC
2A
/PC
INT4
10
PB
5/O
C1
A/P
CIN
T5
11
PB
6/O
C1
B/P
CIN
T6
12
PB
7/O
C0
A/O
C1
C/P
CIN
T7
13
AR
EF
PA0/AD022
PA1/AD123
PA2/AD224
PA3/AD325
PA4/AD426
PA5/AD527
PA6/AD628
PA7/AD729
PC6/A1431
PC5/A1332
PC4/A1233
PC3/A1134
PC2/A1035
PC1/A936
PC0/A837
PD7/T038
PG2/ALE39
PG1/RD40
PG0/WR41
PL742
PL643
PL5/OC5C44
PL4/OC5B45
PL3/OC5A46
PL2/T547
PL1/ICP548
PL0/ICP449
PB3/MISO/PCINT350
PB2/MOSI/PCINT251
PB1/SCK/PCINT152
PB0/SS/PCINT053
PK
7/A
DC
15
/PC
INT23
A15
PK
6/A
DC
14
/PC
INT22
A14
PK
5/A
DC
13
/PC
INT21
A13
PK
4/A
DC
12
/PC
INT20
A12
PK
3/A
DC
11
/PC
INT19
A11
PK
2/A
DC
10
/PC
INT18
A10
PK
1/A
DC
9/P
CIN
T17
A9
PK
0/A
DC
8/P
CIN
T16
A8
PF
7/A
DC
7/T
DI
A7
PF
6/A
DC
6/T
DO
A6
PF
5/A
DC
5/T
MS
A5
PF
4/A
DC
4/T
CK
A4
PF
3/A
DC
3A
3P
F2
/AD
C2
A2
PF
1/A
DC
1A
1P
F0
/AD
C0
A0
RE
SE
T
PC7/A1530
ARD2
ARDUINO MEGA2560 R3
C1
0.47uF
R1560
R2
160
C20.47uF
A
B
C
D
FILTER CIRCUITMIC
OSCILLOSCOPE
ARDUINO UNO (FREQUENCY MEASSURING CONTROLLER)
ARDUINO MEGA ( MAIN SEQUENCE3 CONTROLLER)
Smart Traffic Light System 2015
Page | 42
5.4 Solar Tracking System Simulation
The Figure (5.4) illustrates the schematic diagram of LDR’s and servo
motors connections with Arduino UNO. Where it can be simulated by
PROTEUS as it’s a real.
Figure (5.4): Solar Tracing System simulation.
Smart Traffic Light System 2015
Page | 43
5.5 Simulation of Proposed System
The Figure (5.4) illustrates the schematic diagram of all systems connected
with each other. Where it can be simulated by PROTEUS as it’s a real.
Figure (5.5): Proposed System Simulation.
Smart Traffic Light System 2015
Page | 44
CHAPTER 6
IMPLEMENTATION
6.1 Hardware
he model has been designed based on the dimension which camera were able
to detect. The current location of the camera is just for simulation however,
in real design there is a camera for each side. After known the maximum range which
camera can detect clearly the dimension of the model has been determined. It was designed
from wood with Box shape to allow save all of control devices and wires inside it, on the
surface there is the intersection. However, the traffic light's columns was made from iron
which vacuumed inside. You can see the model as in Figure (6.1).
Figure (6.1): The model with camera.
T
Smart Traffic Light System 2015
Page | 45
According to the range that camera can detected, the design has been made using
AutoCAD™, so the final design was defined as shown in Figure (6.2). However, in this
design the car’s size and street medians were considered.
Figure (6.2): AutoCAD design for traffic light intersection.
Smart Traffic Light System 2015
Page | 46
6.1.1 Prototype Components
1. Cars
Due to the width of the street the dimensions of cars have been determined as
follow:
Width = 2cm, Length = 6cm as shown in Figure (6.3).
2. Traffic columns
The material that used is Iron, however it’s the only material that found in
suitable size and easy to form. The dimension of tube is (1×1) cm, the height is =
15 cm and the horizontal tube length = 10 cm. as shown in Figure (6.3).
Figure (6.3): Traffic column and cars.
3. Camera Holder
For simulation the camera is installed in the middle of intersection, however in
practical it’s better to have a camera for each traffic light.
4. Accessories
To add more beauty on the prototype, some accessories have been added to the
model such as: grass turf surfaces, chairs, trees and lamps columns.
Smart Traffic Light System 2015
Page | 47
6.2 Software
6.2.1 Car Detection based on Image Processing
6.2.1.1 Process Methodology
The process begin with recording a real-time video by camera and send it to the
computer, then computer start the image processing using Matlab™ in several steps to
estimate the time delay desired for each traffic light and send them to the Arduino™ to
control the traffic light.
6.2.1.2 Function of Matlab:
Determine the suitable resolution for video frames which is 640x480 Pixels.
Determine the type of image as RGB (Red, Green, and Blue).
Snapshot image from video. Figure (6.4).
Figure (6.4): Snapshot image
Convert the image to the grayscale mode. Figure (6.5).
Figure (6.5): Grayscale image.
Smart Traffic Light System 2015
Page | 48
Convert the image to binary mode, only two colors Wight (1) and Black (0).
Figure (6.6).
Figure (6.6): Binary mode image.
Filtering the image by discard any noise less than 400 pixel. Figure (6.7).
Figure (6.7): Binary mode image with filtration.
Dividing the image to four sections, each section represent a side of the intersection
(Right, Left, Up, Down), depending on specific pixels that determine boundaries of
each section. Figure (6.8).
Figure (6.8): Divided four sections.
Smart Traffic Light System 2015
Page | 49
Counting objects that has (1) state in each section separately and store it in matrices.
Estimating time delay needed for each section and store them in variables
(w, x, y, z).
Send the variables values serially to the Arduino by USB port.
The previous steps are done by instruction written on Matlab. The code shown in the
Appendix (2).
6.2.1.3 Function of Arduino:
Receive the time delay values which has been estimated by Matlab and use them
to control the traffic light system.
Control the sequence of the traffic light system.
The previous steps are done by instruction written on Arduino. The code shown in the
Appendix (3).
Smart Traffic Light System 2015
Page | 50
6.2.2 Emergency Detecting
6.2.2.1 Process Methodology
The process was running Arduino program live time frequency measuring for the
emergency signal detecting. At first a frequency measuring program has been built, the
program measures the frequencies that come to the mic and output the measured
frequencies using the serial port. In Figure (6.9) you can see how the first frequency
measuring program was running.
Figure (6.9): Frequency measuring program.
Smart Traffic Light System 2015
Page | 51
After that a four siren samples were selected for testing. The samples consists of 3
wail samples and one yelp sample, all samples have been tested on the frequency measuring
program. And values of (sum, average, maximum, minimum) has been calculated as shown
in Table (6.1).
Table (6.1): Measured frequencies (sum, average, maximum, minimum)
After measuring the final average value for the samples, an If statement instruction
was added to the program to make it ready for detecting, you can see the program code in
Appendix (4).
sample 1 sample 2 sample 3 sample 4 Total
Sum 25732 409875.4 1377418 416231.6 2229257
average 1531.679 1433.131 1698.419 1313.423 1494.163
Max 2873.05 2193.28 2887.04 2984.35 2984.35
Min 853.61 826.87 877.96 716.81 716.81
final average value 1731.774
Smart Traffic Light System 2015
Page | 52
6.3 Solar Tracking System
6.3.1 Process Methodology
The process begin with sensing the sun light, then check if all LDR’s have the same
voltage, then the solar cell still in the same position. If not, estimate the average difference
voltage for (up, down/left, right) side, and decide the precise required position by the
microcontroller and send commands to servo motors to move to the required position. You
can see the program code in Appendix (5).
6.4 Display Boards
6.4.1 Process Methodology
The process begin with sensing a temperature from LM35 transducer as a voltage
value, and send it to the Arduino, then the Arduino covert the voltage value to temperature
value in Celsius, then the Arduino will send the temperature, guidelines and speed limit to
display them on LCD's. You can see the program code in Appendix (6).
Smart Traffic Light System 2015
Page | 53
CHAPTER 7
TESTING AND PERFORMANCE MEASURE
urrent traffic light systems depends on fixed time, as explained previously.
On the other hand, the system of this project estimate the desired time of the
green light based on the number of cars. These two systems can be compared through the
following example from actual life, as shown in Figure (7.1):
Figure (7.1): Traffic light example
The following example shows traffic light intersection, there are four traffic lights
on the intersection (A, B, C, D), according to the tables below that shown comparison
between the current system and project system:
Comparison between the two systems:
In the current system fixed time will be given for every traffic light, usually
traffic light (A) and (C) are given the biggest time, (B) and (D) are given the lowest time,
the time will be constant and for a traffic with 3 car capacity, usually (A) and (C) will be
given as like (18) sec. and (B) and (D) will be given as like (12) sec. as shown in Table
(7.1).
C
Smart Traffic Light System 2015
Page | 54
Table (7.1): Current system, Timing sequence of traffic light.
In the proposed system of the traffic light (A) will be allocated (18) s, (C) will be
given (18) s, (B) will be given (12) s, (D) will be given (0) s, and in each side the times
will be dynamic time where the time based on the number of cars. Also the proposed system
is able to detect the emergency vehicle and interrupt the sequence, as shown in Table (7.2).
Table (7.2): The proposed system time diagram
TIME 6 12 18 24 30 36 42 48
A
B
C
D
Table (7.3) shows the comparison between the two systems.
Factors Current system Proposed system
Cycle time (sec) 60 48
Number of passing cars 8 8
Emergency detecting No Yes
Solar tracking No Yes
Guidelines No Yes
And it can be concluded from Table (7.3) that the current system does not contain
the emergency detecting system, neither solar tracking system nor the road guidelines, but
the proposed system provides all these features on the traffic lights, making the traffic
process more orderly and reduce the time delay.
TIME 6 12 18 24 30 36 42 48 54 60
A
B
C
D
Smart Traffic Light System 2015
Page | 55
Figure (7.2): Comparison between current and proposed system based on cycle time and number of passing cars.
Can also be mentioned that in the second cycle time the current system is not taking
into consideration the cars that lined up on the previous traffic light, and traffic light time
is constant even with the number of cars that lined up, but in the proposed system the
camera will count the number of cars in each side and calculate the new time for each
traffic light, which means increased time in the current system, and shortening it in the
proposed system.
60
48
8 8
CURRENT SYSTEM PROPOSED SYSTEM
Comparison between the two systems
Cycle time (sec) Number of passing cars
Smart Traffic Light System 2015
Page | 56
CHAPTER 8
CONCLUSIONS
After testing and validation of the proposed system, the advantages were found that the
cycle time of the traffic lights intersection has been reduced, number of passing cars
through traffic lights has been increased, emergency detecting has solved the obstruction
of emergency vehicles, solar tracking energy system has solved the electrical cut-off
problems, and also display boards system has solved the missing guidelines.
Practical results of the proposed system were that the system has minimized the traffic
jams, provides an alternative energy source in case of electrical power cut-off, revving the
process of passing emergency vehicles, reduce disorientation of drivers that happened
because of missing guidelines.
Proposals and improvements to develop the system in the future are using the camera
as a tool to monitor the movement of vehicles in terms of the type and speed of the car,
develop a technical faults system that is linked with traffic administration to be able to
determine the type and location of the fault signal, and develop a mobile application that
can help traffic department to control traffic light through this application and dispensing
the traditional traffic control, so the control of the process will be remotely.
Smart Traffic Light System 2015
Page | 57
APPENDICES
Smart Traffic Light System 2015
Page | 58
APPENDIX 1
Tables
Table (2.5 :( Frequency and cycle rate requirements for wail.
Parameter CCR Title 13 SAE J1849 GSA K-Specification
Cycle rate lower limit in
cycles per minute (cpm).
10 10 10
Cycle rate upper limit
(cpm).
30 30 18
Minimum range of
Fundamental frequency
none 850 Hz one octave*
Minimum fundamental
frequency (Hz)
100 650 500
Maximum fundamental
frequency (Hz)
2500 2000 2000
Octave band in which
maximum sound pressure
level is measured (Hz)
1000 or 2000 none 1000 or 2000
Maximum fundamental frequency is equal to twice the minimum fundamental frequency.
Smart Traffic Light System 2015
Page | 59
Table (2.6): Frequency and cycle rate requirements for yelp.
Maximum fundamental frequency is equal to twice the minimum fundamental frequency.
Parameter CCR Title 13 SAE J1849 GSA K-Specification
Cycle rate lower limit in
cycles per minute
(cpm).
150 150 150
Cycle rate upper limit
(cpm).
250 250 250
Minimum range of
Fundamental frequency
none 850 Hz one octave*
Minimum fundamental
frequency (Hz)
100 650 500
Maximum fundamental
frequency (Hz)
2500 2000 2000
Octave band in which
maximum sound
pressure
level is measured (Hz)
1000 or 2000 none 1000 or 2000
Smart Traffic Light System 2015
Page | 60
APPENDIX 2
Code of Car Detecting System Using Matlab
s1=serial('COM3','Baudrate',9600) % Setup serial communication with speed 9600 bit/sec
with Arduino COM
fopen(s1) % Start Serial Communication
pause(2) % Delay 2 sec
vid = videoinput('winvideo',2,'YUY2_640x480'); % Input video from camera and store it in vraible to
use it again
set(vid, 'ReturnedColorSpace', 'RGB'); % Set type of return image RGB mode
preview(vid); % Preview Video
pause(2)
while(1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Right_Traffic_Light %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
img = getsnapshot(vid); % Snapshoot image from Video
imwrite(img,'test6.png'); % Store image in image file 'test6.png'
I=imread('test6.png'); % Store image in variable to use it again
figure(2)
imshow(I) % Preview Image
I=rgb2gray(I); % Convert image to gray mode
figure(3)
imshow(I) % Preview Image
I=im2bw(I,graythresh(I)); % Convert image to binary mode
figure(4)
imshow(I) % Preview Image
I2=bwareaopen(I,400); % Filter Image ignore object less than 400 Pixel
figure(5)
imshow(I2) % Preview Image
right= I2(176:234, 440:585); % Crop Image for Right Side
right2=bwareaopen(right,800); % Filter Image ignore object less than 800 Pixel
rn=bwboundaries(right2); % Determine Objects (Cars)
length(rn) % Count Number of Cars
x=length(rn)*6+6; % Estimate Turn On Time for Green Light
figure(6)
subplot(2,2,1)
imshow(right2) % Preview Image
if length(rn)==0
fprintf(s1,'%s','10')
pause(2)
end
if length(rn)==1
fprintf(s1,'%s','11')
pause(x)
end
if length(rn)==2
fprintf(s1,'%s','12')
pause(x)
end
if length(rn)==3
fprintf(s1,'%s','13')
pause(x)
end
if length(rn)>3
fprintf(s1,'%s','13')
pause(24)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Left_Traffic_Light %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
img = getsnapshot(vid); % Snapshoot image from Video
imwrite(img,'test6.png'); % Store image in image file 'test6.png'
Smart Traffic Light System 2015
Page | 61
I=imread('test6.png'); % Store image in variable to use it again
figure(2)
imshow(I) % Preview Image
I=rgb2gray(I); % Convert image to gray mode
figure(3)
imshow(I) % Preview Image
I=im2bw(I,graythresh(I)); % Convert image to binary mode
figure(4)
imshow(I) % Preview Image
I2=bwareaopen(I,400); % Filter Image ignore object less than 400 Pixel
figure(5)
imshow(I2) % Preview Image
left= I2(244:305, 92:224); % Crop Image for Left Side
left2=bwareaopen(left,800);
ln=bwboundaries(left2);
length(ln)
y=length(ln)*6+6;
figure(6)
subplot(2,2,2)
imshow(left2)
if length(ln)==0
fprintf(s1,'%s','20')
pause(2)
end
if length(ln)==1
fprintf(s1,'%s','21')
pause(y)
end
if length(ln)==2
fprintf(s1,'%s','22')
pause(y)
end
if length(ln)==3
fprintf(s1,'%s','23')
pause(y)
end
if length(ln)>3
fprintf(s1,'%s','13')
pause(24)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% UP_Traffic_Light %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
img = getsnapshot(vid); % Snapshoot image from Video
imwrite(img,'test6.png'); % Store image in image file 'test6.png'
I=imread('test6.png'); % Store image in variable to use it again
figure(2)
imshow(I) % Preview Image
I=rgb2gray(I); % Convert image to gray mode
figure(3)
imshow(I) % Preview Image
I=im2bw(I,graythresh(I)); % Convert image to binary mode
figure(4)
imshow(I) % Preview Image
I2=bwareaopen(I,400); % Filter Image ignore object less than 400 Pixel
figure(5)
imshow(I2) % Preview Image
up=I2(4:129, 268:330); % Crop Image for UP Side
up2=bwareaopen(up,800);
upn=bwboundaries(up2);
length(upn)
z=length(upn)*6+6;
figure(6)
subplot(2,2,3)
imshow(up2)
if length(upn)==0
fprintf(s1,'%s','30')
pause(2)
Smart Traffic Light System 2015
Page | 62
end
if length(upn)==1
fprintf(s1,'%s','31')
pause(z)
end
if length(upn)==2
fprintf(s1,'%s','32')
pause(z)
end
if length(upn)==3
fprintf(s1,'%s','33')
pause(z)
end
if length(upn)>3
fprintf(s1,'%s','13')
pause(24)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Down_Traffic_Light %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
img = getsnapshot(vid); % Snapshoot image from Video
imwrite(img,'test6.png'); % Store image in image file 'test6.png'
I=imread('test6.png'); % Store image in variable to use it again
figure(2)
imshow(I) % Preview Image
I=rgb2gray(I); % Convert image to gray mode
figure(3)
imshow(I) % Preview Image
I=im2bw(I,graythresh(I)); % Convert image to binary mode
figure(4)
imshow(I) % Preview Image
I2=bwareaopen(I,400); % Filter Image ignore object less than 400 Pixel
figure(5)
imshow(I2) % Preview Image
down=I2(354:473 , 337:402); % Crop Image for Down Side
down2=bwareaopen(down,800);
dn=bwboundaries(down2);
length(dn)
b=length(dn)*6+6;
figure(6)
subplot(2,2,4)
imshow(down2);
if length(dn)==0
fprintf(s1,'%s','40')
pause(2)
end
if length(dn)==1
fprintf(s1,'%s','41')
pause(b)
end
if length(dn)==2
fprintf(s1,'%s','42')
pause(b)
end
if length(dn)==3
fprintf(s1,'%s','43')
pause(b)
end
if length(dn)>3
fprintf(s1,'%s','13')
pause(24)
end
end
Smart Traffic Light System 2015
Page | 63
APPENDIX 3
Code of Traffic Light Sequence System Using Arduino
int incomingByte = 0; // for incoming serial data
char x[70];
int red_I =3;
int yellow_I = 4;
int green_I = 5;
int red_II = 6;
int yellow_II = 7;
int green_II = 8;
int red_III = 9;
int yellow_III = 10;
int green_III = 11;
int red_IV = 12;
int yellow_IV = 13;
int green_IV = 14;
int Emergency_I = 2;
int d;
void setup (){
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(red_I, OUTPUT);
pinMode (yellow_I, OUTPUT);
pinMode (green_I, OUTPUT);
pinMode(red_II, OUTPUT);
pinMode (yellow_II, OUTPUT);
pinMode (green_II, OUTPUT);
pinMode(red_III, OUTPUT);
pinMode (yellow_III, OUTPUT);
pinMode (green_III, OUTPUT);
pinMode(red_IV, OUTPUT);
pinMode (yellow_IV, OUTPUT);
pinMode (green_IV, OUTPUT);
pinMode (Emergency_I, INPUT);
attachInterrupt(0,Emergency,RISING);
}
void loop (){
Serial.readBytesUntil(7, x, 70);
Serial.print("I received: ");
Serial.println(x);
////////////////////////////////////////////////////////////////////Traffic_I_Conditions//////////////
////////////////////////
if (x[0] == '1'){
if ( x[1] == '0')
{
digitalWrite(red_I,1);
digitalWrite(red_II,1);
digitalWrite(red_III,1);
digitalWrite(red_IV,1);
}
if (x[1] == '1')
{d=6000;
Traffic_I(d);
}
if (x[1] == '2')
{d=12000;
Traffic_I(d);
}
if (x[1] == '3')
{d=18000;
Smart Traffic Light System 2015
Page | 64
Traffic_I(d);
}
}
////////////////////////////////////////////////////////////////////Traffic_II_Conditions/////////////
/////////////////////////
if (x[0] == '2'){
if ( x[1] == '0')
{
digitalWrite(red_I,1);
digitalWrite(red_II,1);
digitalWrite(red_III,1);
digitalWrite(red_IV,1);
}
if (x[1] == '1')
{d=6000;
Traffic_II(d);
}
if (x[1] == '2')
{d=12000;
Traffic_II(d);
}
if (x[1] == '3')
{d=18000;
Traffic_II(d);
}
}
////////////////////////////////////////////////////////////////////Traffic_III_Conditions////////////
//////////////////////////
if (x[0] == '3'){
if (x[1] == '0')
{
digitalWrite(red_I,1);
digitalWrite(red_II,1);
digitalWrite(red_III,1);
digitalWrite(red_IV,1);
}
if (x[1] == '1')
{d=6000;
Traffic_III(d);
}
if (x[1] == '2')
{d=12000;
Traffic_III(d);
}
if (x[1] == '3')
{d=18000;
Traffic_III(d);
}
}
////////////////////////////////////////////////////////////////////Traffic_IV_Conditions/////////////
/////////////////////////
if (x[0] == '4'){
if (x[1] == '0')
{
digitalWrite(red_I,1);
digitalWrite(red_II,1);
digitalWrite(red_III,1);
digitalWrite(red_IV,1);
}
if (x[1] == '1')
{d=6000;
Traffic_IV(d);
}
if (x[1] == '2')
{d=12000;
Traffic_IV(d);
Smart Traffic Light System 2015
Page | 65
}
if (x[1] == '3')
{d=18000;
Traffic_IV(d);
}
}
///////////////////////////////////////////////////////////////End_Conditions/////////////////////////
////////////////////////////
}
///////////////////////////////////////////////////////////////Traffic_I_loop/////////////////////////
////////////////////////////
void Traffic_I(int d){
digitalWrite(red_I,1);
digitalWrite(red_II,1);
digitalWrite(red_III,1);
digitalWrite(red_IV,1);
delay(2000);
digitalWrite(red_I,0);
digitalWrite(yellow_I,1);
delay(2000);
digitalWrite(yellow_I,0);
digitalWrite(green_I,1);
delay(d);
digitalWrite(green_I,0);
digitalWrite(yellow_I,1);
delay(2000);
digitalWrite(yellow_I,0);
digitalWrite(red_I,1);
delay(1000);
return ;
}
///////////////////////////////////////////////////////////////Traffic_II_loop////////////////////////
/////////////////////////////
void Traffic_II(int d){
digitalWrite(red_I,1);
digitalWrite(red_II,1);
digitalWrite(red_III,1);
digitalWrite(red_IV,1);
delay(2000);
digitalWrite(red_II,0);
digitalWrite(yellow_II,1);
delay(2000);
digitalWrite(yellow_II,0);
digitalWrite(green_II,1);
delay(d);
digitalWrite(green_II,0);
digitalWrite(yellow_II,1);
delay(2000);
digitalWrite(yellow_II,0);
digitalWrite(red_II,1);
delay(1000);
return ;
}
///////////////////////////////////////////////////////////////Traffic_III_loop///////////////////////
//////////////////////////////
void Traffic_III(int d){
digitalWrite(red_I,1);
digitalWrite(red_II,1);
digitalWrite(red_III,1);
digitalWrite(red_IV,1);
delay(2000);
digitalWrite(red_III,0);
digitalWrite(yellow_III,1);
delay(2000);
digitalWrite(yellow_III,0);
digitalWrite(green_III,1);
delay(d);
Smart Traffic Light System 2015
Page | 66
digitalWrite(green_III,0);
digitalWrite(yellow_III,1);
delay(2000);
digitalWrite(yellow_III,0);
digitalWrite(red_III,1);
delay(1000);
return ;
}
///////////////////////////////////////////////////////////////Traffic_IV_loop////////////////////////
/////////////////////////////
void Traffic_IV(int d){
digitalWrite(red_I,1);
digitalWrite(red_II,1);
digitalWrite(red_III,1);
digitalWrite(red_IV,1);
delay(2000);
digitalWrite(red_IV,0);
digitalWrite(yellow_IV,1);
delay(2000);
digitalWrite(yellow_IV,0);
digitalWrite(green_IV,1);
delay(d);
digitalWrite(green_IV,0);
digitalWrite(yellow_IV,1);
delay(2000);
digitalWrite(yellow_IV,0);
digitalWrite(red_IV,1);
delay(1000);
return ;
}
//////////////////////////////////////////////////////////////////Emergrncy_Interrupt_Function////////
///////////////////////////////
void Emergency()
{
digitalWrite(green_IV,LOW);
digitalWrite(yellow_IV,LOW);
digitalWrite(red_IV,HIGH);
digitalWrite(green_III,LOW);
digitalWrite(yellow_III,LOW);
digitalWrite(red_III,HIGH);
digitalWrite(green_II,LOW);
digitalWrite(yellow_II,LOW);
digitalWrite(red_II,HIGH);
digitalWrite(yellow_I,HIGH);
for (i=0; i<=1000; i++)
{ {delayMicroseconds(2000);}
}
digitalWrite(yellow_I,LOW);
digitalWrite(green_I,HIGH);
for (i=0; i<=1000; i++)
{ {delayMicroseconds(18000);}
}
Smart Traffic Light System 2015
Page | 67
APPENDIX 4
Code of Emergency Detection System Using Arduino
#include <FreqMeasure.h> //frequency measure library in ardiuno
double sum=0; //variable for the sum of the live time frequency reading
int count=0; //variable for counting specific number of live time frequencies depending on the live
time of the instantaneous measuring you want
unsigned long finalsum=0; //variable for summing the measured frequencies
unsigned int finalnum=0; // variable for counting of measured frequencies
void setup()
{
pinMode(13,OUTPUT); //make led pin no.13 in output mode
Serial.begin(57600); //make serial communication avilable
FreqMeasure.begin(); //start the frequency measuring
}
void loop() {
if (FreqMeasure.available()) {
//if requency measuring is runing, average several reading together
sum = sum + FreqMeasure.read();
count = count + 1;
if (count > 30) {
float frequency = FreqMeasure.countToFrequency(sum / count);
sum = 0;
count = 0;
finalsum = finalsum + frequency; //start summing the meassured values
++finalnum;
if (finalnum >= 50){
//average serval measures together
float average = (finalsum / finalnum);
finalsum =0;
finalnum=0;
if ((average > 1700 && average <2100) || (average > 1100 && average <1300))
{
//check if the frequency is between the range of wail or yelp
digitalWrite(13,HIGH); // make led pin 13 on
Serial.println(average);// print the frequency to make sure of that it's in the range
}
else
digitalWrite(13,LOW); // if not make led pin 13 off
}
}
}
}
Smart Traffic Light System 2015
Page | 68
APPENDIX 5
Code of Solar Tracking System Using Arduino
#include <Servo.h> // include Servo library
Servo horizontal; // horizontal servo
int servoh = 90; // stand horizontal servo
Servo vertical; // vertical servo
int servov = 90; // stand vertical servo
// LDR pin connections
// name = analogpin;
int ldrlt = 0; //LDR top left
int ldrrt = 1; //LDR top rigt
int ldrld = 2; //LDR down left
int ldrrd = 3; //ldr down rigt
void setup()
{
// servo connections
// name.attacht(pin);
horizontal.attach(9); //pwm pin
vertical.attach(10);
horizontal.write(servoh);
vertical.write(servov);
}
void loop()
{
int lt = analogRead(ldrlt); // top left 10bit 1024 values
int rt = analogRead(ldrrt); // top right
int ld = analogRead(ldrld); // down left
int rd = analogRead(ldrrd); // down rigt
int dtime = analogRead(4)/20; // read potentiometers
int tol = analogRead(5)/2; //256 value
int avt = (lt + rt) / 2; // average value top
int avd = (ld + rd) / 2; // average value down
int avl = (lt + ld) / 2; // average value left
int avr = (rt + rd) / 2; // average value right
int dvert = avt - avd; // check the diffirence of up and down
int dhoriz = avl - avr;// check the diffirence og left and rigt
if (-1*tol > dvert || dvert > tol) // check if the diffirence is in the tolerance else change vertical
angle
{
if (avt > avd)
{
--servov;
if (servov < 0)
{
servov = 0;
}
}
else if (avt < avd)
{
++servov;
if (servov > 170)
{
servov = 170;
}
}
vertical.write(servov);
}
if (-1*tol > dhoriz || dhoriz > tol) // check if the diffirence is in the tolerance else change
horizontal angle
{
if (avl > avr)
{
--servoh;
if (servoh < 0)
{
servoh = 0;
}
}
else if (avl < avr)
{
Smart Traffic Light System 2015
Page | 69
++servoh;
if (servoh > 170)
{
servoh = 170;
}
}
horizontal.write(servoh);
}
delay(20);
delay(dtime);
}
Smart Traffic Light System 2015
Page | 70
APPENDIX 6
Code of Display Boards System Using Arduino
#include <LiquidCrystal.h> // include the library code
LiquidCrystal lcd1(12,11,5,4,3,2);
//initialize the library with the LCD1 at enable pin 11
LiquidCrystal lcd2(12,10,5,4,3,2);
//initialize the library with the LCD2 at enable pin 10
LiquidCrystal lcd3(12,9,5,4,3,2);
//initialize the library with the LCD3 at enable pin 9
LiquidCrystal lcd4(12,8,5,4,3,2);
//initialize the library with the LCD4 at enable pin 8
int tempPin=0;
//data pin from temp sensor
int tempc;
// wether temp variable
void setup (){
// set up the LCD's number of columns and rows:
lcd1.begin(16,2);
lcd2.begin(16,2);
lcd3.begin(16,2);
lcd4.begin(16,2);
// clear all LCD's from data
lcd1.clear();
lcd2.clear();
lcd3.clear();
lcd4.clear();
}
void loop (){
tempc=(5.0* analogRead(tempPin) *100)/1024;
// ADC temp. conversion equation
lcd1.print ("Tabarbour >>");
// Print a message to the LCD.
lcd1.setCursor (0,1);
// set the cursor column0, row1
lcd1.print("Temperature=");
lcd1.setCursor(12,1);
lcd1.print(tempc);
lcd1.setCursor(14,1);
lcd1.print("oC");
lcd2.print ("AL-Hashmi >>");
lcd2.setCursor (0,1);
lcd2.print("Temperature=");
lcd2.setCursor(12,1);
lcd2.print(tempc);
lcd2.setCursor(14,1);
lcd2.print("oC");
lcd3.print ("AL-Zarqa >>");
lcd3.setCursor (0,1);
lcd3.print("Temperature=");
lcd3.setCursor(12,1);
lcd3.print(tempc);
lcd3.setCursor(14,1);
lcd3.print("oC");
lcd4.print ("Sport City >>");
lcd4.setCursor (0,1);
lcd4.print("Temperature=");
lcd4.setCursor(12,1);
lcd4.print(tempc);
lcd4.setCursor(14,1);
lcd4.print("oC");
delay (2000);
lcd1.clear();
lcd2.clear();
lcd3.clear();
Smart Traffic Light System 2015
Page | 71
lcd4.clear();
delay (200);
lcd1.setCursor (0,0);
lcd2.setCursor (0,0);
lcd3.setCursor (0,0);
lcd4.setCursor (0,0);
lcd1.print ("AL-Hashmi <<");
lcd1.setCursor (0,1);
lcd1.print("Speed Limit = 60");
lcd2.print ("Tabarbour <<");
lcd2.setCursor (0,1);
lcd2.print("Speed Limit = 60");
lcd3.print ("Sport City <<");
lcd3.setCursor (0,1);
lcd3.print("Speed Limit = 60");
lcd4.print ("AL-Zarqa <<");
lcd4.setCursor (0,1);
lcd4.print("Speed Limit = 60");
delay (2000);
lcd1.clear();
lcd2.clear();
lcd3.clear();
lcd4.clear();
delay (200);
lcd1.setCursor (0,0);
lcd2.setCursor (0,0);
lcd3.setCursor (0,0);
lcd4.setCursor (0,0);
}
Smart Traffic Light System 2015
Page | 72
REFERENCES
1- Chandrasekhar. M, et al, International Journal of Engineering Research and Applications (IJERA).
2- Nagaraj, et al, International Journal of Engineering Research and Applications (IJERA), Vol. 3,
Issue 2, March -April 2013, pp.1087-1091.
3- Dangi, et al, Sardar Patel Institute of Technology, Mumbai, India.
4- Fazenda, et al, ICCAS-SICE, International Joint Conference, 18-21 Aug. 2009.
5- Hashim, et al, Faculty of Electronics & Computer Engineering, Universiti Teknikal Malaysia
Melaka, Malaysia.
6- Moghbelli et al, Texas A&M University at Qatar, Doha, Qatar.
7- National Institute of Justice, Guide to Test Methods, Performance Requirements, and Installation
Practices for Electronic Sirens, Used on Law Enforcement Vehicles, NIJ Guide 500–00.
Smart Traffic Light System 2015
Page | 73