1. University of central Punjab
Vehicle accident prevention control system
Supervised by
Mohsin Manzoor
Project Member’s
Muhammad Adil Mukhtar
J3F18ASPM0008
Majid Nawab
J3F18ASPM0025
Shahzaib Ilyas
J3F17ASPM0050
2. University of central Punjab
IN THE NAME OF ALLAH
THE MOST GRACIOUS
THE MOST MERCIFUL
3. University of central Punjab
Abbreviations
W1-1
Turn
(Right or Left)
W1-1a
Turn / Advisory Speed
(Right or Left)
W1-2
Curve
(Right or Le
W1-4
Reverse Curve
(Right or Left)
W1-5
Winding Road
(Right or Left)
W1-10
Side Road – Curv
(Right or Le
VAPCS: Vehicle accident prevention control system
VAPSO: Vehicle accident manage organization
IDE : Integrated development In Environment
LED: light Emitted device
TBBS: The bared board system
USS: Ultra sonic sensor
RD: Road
LDR: Light depended resistance
PSO: Pakistan state oil
MTNR: Mountain Road
4. University of central Punjab
SUBMISSION
A report submitted to UCP Lahore as a partial fulfillment for the award of
the degree of Bachelors’ in math physics.
5. University of central Punjab
DEDICATION:
This effort is dedicated to our respected Supervisor Mohsin
Manzoor, loving parents, our inspiring teacherspeciallyMohsin Manzoorand
HOD, our encouraging friends, those who help us & our prestigious
Institutions.
6. University of central Punjab
ABSTRACT
The Accident prevention vehicle control system on turnings project is very helpful in bend roads
and U turnings. From this project we can vigilant the driver through LED signals to know that
the vehicle is arriving the go round are a bend spot. It decrease the accidents occurring this
project reserve the life of humans for a safe and happy journing. The system, if advanced to
include the whole system in Jaranwala to Faisalabad, will support some target collections, viz.
all road users, Traffic Police and the Emergency and Fire Service through to coverage
companies, and local government. The ideal organization will give people useful submissions
about how to recover road development and traffic management. In this paper, a study is done on
current calculation models and imagining techniques. The study contains of two main parts: the
first part gives feature about the road traffic accident disorder on the routes employing for road
traffic organization. In assumption, the paper highlights the related of the growing problem of
road traffic injuries in the country and city along these routes and delivers some basis for
accident lessening techniques.
Contents
Abbreviations.................................................................................................................................3
7. University of central Punjab
DEDICATION:..................................................................................................................................5
ABSTRACT......................................................................................................................................6
TABLE OF FIGURES . ........................................................................................................................9
CHAPTER 1...................................................................................................................................10
INTRODUCTION ............................................................................................................................10
1.1 Objective....................................................................................................................................11
1.2 COMPONENTS OF PROJECT......................................................................................................12
1.3 COMPONENT DISCRIPTION ......................................................................................................13
1.3.1 UNO ARDIOUNO...................................................................................................................13
1.3.2 MEGA ARDUINO...................................................................................................................14
1.3.3 General pin function.................................................................................................................15
1.3.4 Sensor..................................................................................................................................16
1.3.4.1 Ultrasonic sensor...............................................................................................................16
Definition.....................................................................................................................................16
Working principle .........................................................................................................................17
1.3.5 Light-emitting diode(LED) .........................................................................................................18
1.3.6 Power Adapter.....................................................................................................................19
1.3.7 Male to male wire................................................................................................................19
1.3.8 Poles....................................................................................................................................20
1.3.9 LDR......................................................................................................................................20
Working.......................................................................................................................................21
1.3.10 White Light.........................................................................................................................22
1.3.11 Resistance..........................................................................................................................22
1.3.12 Sheet................................................................................................................................22
1.3.13 Tap for use making a road...................................................................................................24
Chapter No 2................................................................................................................................25
Project description....................................................................................................................25
2.1 BLOCK DIGRAM...................................................................................................................25
2.2 Major Factors for the Roads Traffic Accidents...........................................................................26
2.2.1Causes of Road Accidents.......................................................................................................26
2.2.1.1Human factors :..................................................................................................................26
2.2.1.2Road defect........................................................................................................................26
8. University of central Punjab
2.3 The Traffic Safety Management and preventive strategies.........................................................27
2.3.1 Traffic Safety Administration Management............................................................................27
2.3.2 Mechanism of the Traffic Safety Management: ......................................................................27
2.3.3 Policy of the Traffic Safety Management:...............................................................................27
2.3.4 Duty of the Traffic Safety Management:.................................................................................27
2.3.5 Information System of the Traffic Safety Technical Administrative Management......................27
2.4 WORKING PRINCIPLE...............................................................................................................29
2.4.1STEP NO 1 CODING................................................................................................................29
2.4.2 STEP NO 2 ............................................................................................................................30
2.4.3 STEP NO 3 ............................................................................................................................30
2.4.4 STEP NO 4 ............................................................................................................................30
2.4.5 STEP NO 5 ............................................................................................................................30
2.4.6 STEP NO 6 ............................................................................................................................30
2.5 APPLICATION ..........................................................................................................................31
2.6 Future work............................................................................................................................32
Chapter No 3 ...............................................................................................................................33
Conclusion....................................................................................................................................33
3.1 Photo Copy.............................................................................................................................33
3.2 Reference...............................................................................................................................34
Programing in UNOArduino..............................................................................................................35
Programming in mega arduino ..........................................................................................................41
9. University of central Punjab
TABLE OF FIGURES .
FIGURE NO PAGE NO
1.3.1 14
1.3.2 15
1.3.4.1 17
1.3.5 19
1.3.6 20
1.3.7 20
1.3.8 21
1.3.9 21
1.3.10 23
1.3.11 23
1.3.12 24
1.3.13 25
2.1 26
3.1 34
10. University of central Punjab
CHAPTER 1
INTRODUCTION
Our society facing a lot of problems the major problem is accident. Accident are quite common
on Pakistan roads. Moreover with the rapid urbanization, Pakistan has seen an un-precedent
growth on motor vehicle .currently motor vehicle accidents rank ninth in order of disease burden
and are projected to be rank third in year 2020.saftey study have found that a majority of
accident occur either due to the driver error are due to negligence of the safety norms. The
statistics show that more number of road accident take place at blind road corners where we are
not able to visualize the incoming vehicle ,vehicle taking a turn assuming no other vehicle is at
the opposite and cause major road accidents and results in maximum deaths
11. University of central Punjab
1.1 Objective
1. The main objective of this project is to reduce the accidents in bends and u turnings
vehicle drivers generally not able to see other side view this cause accidents through this
project we can able reduce these types of problems. In this project two LED’S connected
with two ultrasonic sensors . which will be placed in the above mentioned placed.
2. To identify the road traffic accident patterns that exists in jaranwala zones
3. To assess social and economic costs which were incurred due to road traffic accidents
4. . To examine the spatial and temporal variation of road traffic accidents.
5. To assess accident differences between different means of road transport
6. To evaluate the existing road traffic management systems, in terms of coordination,
manpower distribution and availabilities of resources, data handling methods
7. . To determine the major causes and contributing factors of road accidents with respect to
drivers, pedestrians, vehicles and road environments.
8. To suggest some possible strategies and counter measures that will contribute to reducing
the problems of road accidents.
12. University of central Punjab
1.2 COMPONENTS OF PROJECT.
1. ARDUINO UNO
2. ARDUINO MEGA
3. ULTRASONIC SENSOR
4. BATTERY
5. LED, RED&GREEN
6. MALE TO MALE WIRE
7. SIMPLE WIRE
8. POLES
9. LDR
10. LED WHITE
11. RESISTANCE
12. SHEET
13. TAP FOR ROAD
13. University of central Punjab
1.3 COMPONENT DISCRIPTION
1.3.1 UNO ARDIOUNO
The Arduino UNO is an open-source microcontroller board ground on the Microchip
ATmega328P microcontrollerand grownby Arduino.cc.[2][3] The boardis fittedwith sets of digital and
analoginput/output(I/O)pinsthatmaybe interfaced todifferentexpansion boards (shields) and other
circuits.[1] The board has 14 Digital pins, 6 Analog pins, and programmable with the Arduino IDE
(IntegratedDevelopment Environment) via a type B USB cable. [4] It can be powered by the USB cable
or by an external 9-voltbattery,though it take voltages between 7 and 20 volts. It is also similar to the
ArduinoNanoandLeonardo.[5][6] The hardware reference designis distributed under a Creative usual
AttributionShare-Alike2.5license andis accessible onthe Arduinowebsite.Layoutandproduction files
for some versions of the hardware are also accessible. The word "UNO" means one in Italian and was
pick to mark the initial loose of the Arduino Software. [1] The Uno board is the first in a series of USB-
ground Arduino boards,[3] and it and version 1.0 of the Arduino IDE were the reference versions of
Arduino,now advance toneverreleases.[4] The ATmega328 on the board comes preprogrammed with
a boot loader that allows uploading more code to it without the use of an external hardware
programmer.
Figure 1.3.1
14. University of central Punjab
1.3.2 MEGA ARDUINO
The Arduino Mega is a microcontroller board based on the ATmega2560. It has 54
digital input/output pins (of which 14 can be used as PWM outputs), 16 analog inputs, 4 UARTs
(hardware serial ports),a16 MHz crystal oscillator,aUSB connection,apower jack, an ICSP header, and
a reset button.
Figure 1.3.2
15. University of central Punjab
1.3.3 General pin function
LED: There isa built-inLEDdriven by digital pin 13. When the pin is high value, the LED is on, when the
pin is low, it's off. VIN: The input voltage to the Arduino/Genuino board when it's using an external
power source (as opposed to 5 volts from the USB connection or other regulated power source). You
can supplyvoltage throughthispin,or,if supplyingvoltage viathe powerjack,accessitthroughthis pin.
5V: This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with
power either from the DC power jack (7 - 20V), the USB connector (5V), or the VIN pin of the board (7-
20V). Supplyingvoltage via the 5V or 3.3V pins bypasses the regulator, and can damage the board 3V3:
A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.
GND:Ground pins.
IOREF: This pin on the Arduino/Genuino board provides the voltage reference with which the
microcontroller operates. A properly configured shield can read the IOREF pin voltage and select the
appropriate power source or enable voltage translators on the outputs to work with the 5V or 3.3V.
Reset: Typically used to add a reset button to shields which block the one on the board.[7]
Special pin functions
Each of the 14 digital pins and 6 analog pins on the Uno can be used as an input or output, using pin
Mode (), digital Write (), and digital Read() functions. They operate at 5 volts. Each pin can provide or
receive 20 mA as recommendedoperatingconditionand has an internal pull-up resistor (disconnected
by default) of 20-50k ohm. A maximum of 40mA is the value that must not be exceeded on any I/O pin
to avoidpermanentdamage tothe microcontroller.The Unohas 6 analoginputs,labeledA0throughA5,
each of which provide 10 bits of resolution (i.e. 1024 different values). By default, they measure from
ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and
the analog Reference () function.
16. University of central Punjab
1.3.4 Sensor
A sensorisa sophisticateddevice thatmeasuresaphysical quantitylikespeed or pressure and converts
it into a signal that can be measured electrically. Sensors are based on several working principals and
typesof measurements.Inourcase almostall typesof sensors emit signals and measure the reflection
to make measurements
1.3.4.1 Ultrasonic sensor
Definition
The module used is HC-SR04 ranging from 2cm-4cm. It has the accuracy of 3mm. The sensor consists of
ultrasonictransmitter,receiver and control circuit. It consists of 4 pins they are VCC of 5v, input trigger
pulse,outputechopulse,andground.The electricparameterof ultrasonicsensoris,its working voltage
5v DC, its operatingfrequencyis40kHz.It has triggeredinputsignal of 10us TTL pulse. Ultrasonic sensor
works on the basic principle of piezoelectric effect The ultrasonic sensor works on the principle of
SONAR and RADAR system which is used to determine the distance to an object. An ultrasonic sensor
generatesthe high-frequencysound(ultrasound)waves.Whenthisultrasoundhitsthe object,itreflects
as echo which is sensed by the receive By measuring the time required for the echo to reach to the
receiver, we can calculate the distance. This is the basic working principle of Ultrasonic module to
measure distance
Figure 1.3.4.1
17. University of central Punjab
How to calculate distance?
We now that,
Distance = speed * time
The speed of sound waves is 343 m/s
So,
Total distance = 343 * time of high( echo) pulse/2
Total distance is divided by 2 because signal travels from HC-SR04 to object and returns to the module
HC-SR-04.
HC-SR04 Pin Discription
VCC - +5 V supply
TRIG – Trigger input of sensor. Microcontroller applies 10 us trigger pulse to the HC-SR04 ultrasonic
module.
ECHO–Echo output of sensor. Microcontroller reads/monitors this pin to detect the obstacle or to nd
the distance.
GND – Ground
Working principle
Ultrasonic sensor is a sensor that works on principle like to radar or sonar. It makes high frequency
sound and calculate the time interval among the distribution of signal and the getting of echo.
Therefore, ultrasonic sensor can be used to quantity distance Hc-SP04 ultrasonic sensor consists of a
source, a receiver and a control module.
18. University of central Punjab
1.3.5 Light-emitting diode(LED)
A light-emittingdiode (LED) is a semiconductor device that emits visible light when an electric current
passesthroughit.The lightisnot particularlybright,butinmostLEDs itis monochromatic,occurringata
single wavelength. The output from an LED can range from red (at a wavelength of approximately 700
nanometers) to blue-violet (about 400 nanometers). Some LEDs emit infrared (IR) energy (830
nanometers or longer); such a device is known as an infrared-emitting diode (IRED)
LED standsfor light-emittingdiode,whichmeansthatmuch like their diode cousins, they're polarized.
There are a handful of identifiersforfindingthe positive andnegative pinsonan LED. You can try to find
the longer leg, which should indicate the positive, anode pin. Or, if someone's trimmed the legs, try
finding the flat edge on the LED's outer casing. The pin nearest the flat edge will be the negative,
cathode pin.
Figure No 1.3.5
19. University of central Punjab
1.3.6 Power Adapter
Amperage (or current) is the amount of electricity flowing from the battery to the
connecteddevice,whilevoltageisthe strengthof the electric current. ... So even if you have it plugged
into a 5V/3A adapter, if it's only able to handle 5V/2.4A, that's the rate at which it will charge.
Figure No 1.3.6
1.3.7 Male to male wire
A jump wire (also known as jumper wire, or jumper) is an electrical wire, or
collection of theminacable,witha connectoror pin at individually end (or sometimes without them –
only "tinned"), which is generally used to interconnect the components of a breadboard or other
prototype ortestcircuit internallyorwithotherequipmentorcomponents,withoutsoldering.Theseare
jumperwire male tomale usedinconnectingfemalewire pinof anydevelopmentboardlike(Ardiuno) to
other development board o breadboard .Also you can combined it with our Female jumper wire to
create Male to Female jumper wire.
Figure NO 1.3.7
20. University of central Punjab
1.3.8 Poles
Poles is used for signals indication to show red and green lights. Also be used to show the sign turn on
left and turn on right, stop, and zebra crossing and so on points .
Figure No 1.3.8
1.3.9 LDR
It stands for Light Dependent Resistor or Photo resistor, which is a passive electronic component,
basically a resistor which has a resistance that varies depending of the light intensity. A photo resistor is
made of a high resistance semiconductor that absorbs photons and based on the quantity and frequency of
the absorbed photons the semiconductor material give bound electrons enough energy to jump into the
conduction band. The resulting free electrons conduct electricity resulting in lowering resistance of the
photo resistor. The number of electrons is dependent of the photons frequency
Figure No 1.3.9
21. University of central Punjab
Working
The resistance is very high in darkness, almost high as 1MΩ but when there is light that falls on the LDR,
the resistance is falling down to a few depending on the model. Light dependent resistors come in
different shapes and colors. LDRs are very useful in many electronic circuits, especially in alarms,
switching devices, clocks, street lights and more. There are some audio application uses such as audio
limiters or compressors. It is used to turn ON or OFF a device according to the ambient light.
22. University of central Punjab
1.3.10 White Light
White LED usedin thisprojectforstreetlightthatlight glow in night time and be off on day time.white
lightisnot a colourits combinationof all colourswhite lightcontainsall wavelengths from about 390nm
to 700nm.
Figure No 1.3.10
1.3.11 Resistance
An electron traveling through the wires and loads of the external circuit encounters
resistance.Resistance isthe hindrance tothe flow of charge.Foran electron,the journey from terminal
to terminal is not a direct route. Rather, it is a zigzag path that results from countless collisions with
fixed atoms within the conducting material. The electrons encounter resistance - a hindrance to their
movement.Whilethe electricpotential difference established between the two terminals encourages
the movement of charge, it is resistance that discourages it. The rate at which charge flows from
terminal to terminal is the result of the combined effect of these two quantities.
Figure No 1.3.11
1.3.12 Sheet
Sheet also be used in this project where all the components of project setup on this.
24. University of central Punjab
1.3.13 Tap for use making a road
Here to show the road map using a black tap on white sheet.
Figure No 1.3.13
25. University of central Punjab
E
T
+G
+R
E
T
+G
+R
E
T
+G
+R
+R
+G
T
E
+R
+G
T
E
+R
+G
T
E
+R
+G
T
E
Chapter No 2
Project description
2.1 BLOCK DIGRAM
Figure No 2.1
E
E
T
+
G
+
R
E
T
+
G
+
R
E
T
+
G
T
E
T
+
G
+
R
E
T
+
G
+
R
E
T
+
G
S 1
S 2
S 3
S 6
S 7
S 4
S 5
26. University of central Punjab
2.2 Major Factors for the Roads Traffic Accidents
There are many factors which affect the roads traffic accidents. These factors may
increase the severity of the accidents on the roads due to their negative impact
contribution for the road accidents.
2.2.1Causes of Road Accidents
Road accidents are caused by three main factors. These main factors contribute a great
road accidents and damage of life, properties, etc due to the high magnitude of the
errors committed by the following main factors. The risks occurring due to these
factors on the world are not reducing rather increasing as the data shows that traffic
accidents increasing on the world continents. These main factors are:
1. Human Factors (Road Users) 2. Road Defect
2.2.1.1Human factors :
Driverfitnessasan essentialelementinroadsafetyishighlighted by international studies on the cause
of most accidents.DriverFitnesscanbe summarized as the physical and mental ability of the driver to
enhance safe driving.
2.2.1.2Road defect
Unsafe road conditionthat causes an accident. Example of accidents with causes an accident. Example
of accidents with dangerous road defects include:
1. Dangerous curves
2. Insufficient lighting
3. Poor water drainage
4. Faded lane making
5. Missing guardrails
6. Lack of reflective markers
7. Failure to maintain traffic flow
27. University of central Punjab
2.3 The Traffic Safety Management and preventive strategies
The traffic safety management includes traffic safety administration management, traffic
safety technical management and safety facilities management.
2.3.1 Traffic Safety Administration Management
Traffic safety administration management includes the mechanism of the traffic safety
management, policy, duty and administrative information system of technology, etc.
2.3.2 Mechanism of the Traffic Safety Management:
The traffic safety management refers to the construction and maintenance, management of the
vehicle, establishment and execution of the regulation of the road, training and management of
the driver, traffic participants' understanding of traffic rule, etc. It is a comprehensive and
social system.
2.3.3 Policy of the Traffic Safety Management:
It’s planning and management is belonging to government's functions. The main
contents of the policy of the traffic safety management include legal system,
legislation and executing the law, technical policy, norm and standard, etc. An
important policy is to make the sustainable development strategy for the traffic.
2.3.4 Duty of the Traffic Safety Management:
Traffic participants, roads, vehicles and environment cause the traffic safety problem.
And it seems to do not matter with the duty personnel of the traffic, but if the duty
personnel are strict on duty, the traffic will supervise participants. Meanwhile it finds
and reflects the bad roads, commands and guides the traffic in special climate and
environment. The main content of the duty of the traffic safety duty management
includes the mode of the traffic duty management, post norm, behavioral norm,
equipping the standard, etc.
2.3.5 Information System of the Traffic Safety Technical Administrative
Management
The information system of the traffic safety technical administrative management is to
regard computer as the platform, based on database, and make people receive the
information of traffic safety technical administrative management accurately more
directly. The main contents include mode, method, form, gathering, dealing with,
28. University of central Punjab
counting, storing, searching and feed backing the system, The main cause of bend
road accident we use the sensor on bend. etc.
29. University of central Punjab
2.4 WORKING PRINCIPLE.
2.4.1STEP NO 1 CODING
1. Coding fro Arduino UNO&MEGA which consists of set of commands to process the data
from sensor and to operate the LED.
30. University of central Punjab
2.4.2 STEP NO 2
2. Circuit assembly having sensor and Arduino UNO&MEGA where the sensor senses the
obstacle and the Arduino UNO&MEGA processes and operates LED as per the
commands.
2.4.3 STEP NO 3
3. Analyzing, repairing and running the program. The program is uploaded to Arduino
UNO&MEGA sensor leads the signal and senses the object and gives the signal
information to Arduino UNO&MEGA . Arduino is powered by using laptop
2.4.4 STEP NO 4
4. Fixing the circuit to the perfect fixing arduino UNO&MEGA ultrasonic sensor and LED
light to the model of turn road
2.4.5 STEP NO 5
5. Detection of vehicle by the sensor when vehicle passes through the road. It is the
experimental demo for this thesis. The signal sent by the hits the vehicle and reflected
back to the sensor
2.4.6 STEP NO 6
6. Output is obtained glowing of LED at the instantaneous when the signal is received by
the sensor after hitting the vehicle .
31. University of central Punjab
2.5 APPLICATION
1. Vehicle accident prevention control systems can be implement
easily.
2. Easily implemented fully automated (No person is required to
operate).
3. Avoid accidents in curve road bend road mountains road and hill
roads turn no left and turn no right on bend roads.
4. Installation cost is very less.
5. Save thousands of lives
32. University of central Punjab
2.6 Future work
1. Decrease the size of unit so that is occupies small placed and easily kept in narrow roads.
2. Implementing the system to detect number of vehicles and velocity of vehicle.
3. Arrangements to protect the sensor from being damaged in critical places.
33. University of central Punjab
Chapter No 3
Conclusion
The purpose of this thesis is to decrease the number of accidents in curve roads. This is done
by altering the diver by means of LED light which glows when vehicle come from the other side
to the curve. The vehicle is detected by the help of ultrasonic sensor which is interfaced to the
microcontroller Arduino UNO&MEGA. By this we can save thousands of lives in the curve roads.
3.1 Photo Copy
Figure No 3.1
34. University of central Punjab
3.2 Reference
1. https://www.sparkfun.com/artemis
2. https://www.academia.edu/
3. http://www.ijireeice.com
4. https://www.researchgate.net/publication/315829097_Road_Accidents_and_Prevention
5. https://www.wikipedia.org/
35. University of central Punjab
Programing in UNO Arduino
// One
int ledRed_1 = 2;
int ledGreen_1 = 3;
int trigPin_1 = 4;
int echoPin_1 = 5;
// Two
int ledRed_2 = 6;
int ledGreen_2= 7;
int trigPin_2 = 8;
int echoPin_2 = 9;
// Three
int ledRed_3 =10 ;
int ledGreen_3= 11;
int trigPin_3 = 12;
int echoPin_3 = 13;
// Four
int ledRed_4 = A0;
int ledGreen_4 = A1;
int trigPin_4 = A2;
int echoPin_4 = A3;
void setup() {
Serial.begin (9600);
// One
36. University of central Punjab
pinMode(ledRed_1, OUTPUT);
pinMode(ledGreen_1, OUTPUT);
pinMode(trigPin_1, OUTPUT);
pinMode(echoPin_1, INPUT);
// Two
pinMode(ledRed_2, OUTPUT);
pinMode(ledGreen_2, OUTPUT);
pinMode(trigPin_2, OUTPUT);
pinMode(echoPin_2, INPUT);
// Three
pinMode(ledRed_3, OUTPUT);
pinMode(ledGreen_3, OUTPUT);
pinMode(trigPin_3, OUTPUT);
pinMode(echoPin_3, INPUT);
// Four
pinMode(ledRed_4, OUTPUT);
pinMode(ledGreen_4, OUTPUT);
pinMode(trigPin_4, OUTPUT);
pinMode(echoPin_4, INPUT);
}
void One_sensor(){ // This function is for 1st sensor.
int duration_1, distance_1;
37. University of central Punjab
digitalWrite (trigPin_1, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin_1, LOW);
duration_1 = pulseIn (echoPin_1, HIGH);
distance_1 = (duration_1/2) / 29.1;
Serial.print("1st Sensor: ");
Serial.print(distance_1);
Serial.print("cm ");
//if (distance_1 < 2 && distance_1 > 20)
if (distance_1 > 20)
{ // Change the number for long or short distances.
digitalWrite (ledGreen_1, HIGH);
digitalWrite (ledRed_1, LOW);
delay(2000);
Serial.print("LOW ");
} else {
digitalWrite (ledGreen_1, LOW);
digitalWrite (ledRed_1, HIGH);
} }
void Two_sensor(){ // This function is for 2nd sensor.
int duration_2, distance_2;
digitalWrite (trigPin_2, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin_2, LOW);
38. University of central Punjab
duration_2 = pulseIn (echoPin_2, HIGH);
distance_2 = (duration_2/2) / 29.1;
Serial.print("2nd Sensor: ");
Serial.print(distance_2);
Serial.print("cm ");
//if (distance_2 < 2 && distance_2 > 30)
if (distance_2 > 20)
{ // Change the number for long or short distances.
digitalWrite (ledGreen_2, HIGH);
digitalWrite (ledRed_2, LOW);
delay(2000);
Serial.print("LOW");
}
else {
digitalWrite (ledGreen_2, LOW);
digitalWrite (ledRed_2, HIGH);
}
}
void Three_sensor(){ // This function is for 3rd sensor.
int duration_3, distance_3;
digitalWrite (trigPin_3, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin_3, LOW);
duration_3 = pulseIn (echoPin_3, HIGH);
39. University of central Punjab
distance_3 = (duration_3/2) / 29.1;
Serial.print("3rd Sensor: ");
Serial.print(distance_3);
Serial.print("cm ");
// if (distance_3 > 2 && distance_3 < 30)
if (distance_3 > 20)
{ // Change the number for long or short distances.
digitalWrite (ledGreen_3, HIGH);
digitalWrite (ledRed_3, LOW);
delay(2000);
Serial.print("LOW ");
}
else {
digitalWrite (ledGreen_3, LOW);
digitalWrite (ledRed_3, HIGH);
}
}
void Four_sensor(){ // This function is for 4th sensor.
int duration_4, distance_4;
digitalWrite (trigPin_4, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin_4, LOW);
duration_4 = pulseIn (echoPin_4, HIGH);
distance_4 = (duration_4/2) / 29.1;
40. University of central Punjab
Serial.print("4th Sensor: ");
Serial.print(distance_4);
Serial.print(distance_4);
Serial.print("cm ");
//if (distance_4 < 2 && distance_4 > 30)
if (distance_4 > 20)
{ // Change the number for long or short distances.
digitalWrite (ledGreen_4, HIGH);
digitalWrite (ledRed_4, LOW);
delay(2000);
Serial.print("LOW");
}
else {
digitalWrite (ledGreen_4, LOW);
digitalWrite (ledRed_4, HIGH);
}
}
void loop() {
Serial.println("n");
One_sensor();
Two_sensor();
Three_sensor();
Four_sensor();
delay(1000);
41. University of central Punjab
}
Programming in mega arduino
// Four
int ledRed_4 = 14;
int ledGreen_4 = 15;
int trigPin_4 = 16; // One
int ledRed_1 = 2;
int ledGreen_1 = 3;
int trigPin_1 = 4;
int echoPin_1 = 5;
// Two
int ledRed_2 = 6;
int ledGreen_2= 7;
int trigPin_2 = 8;
int echoPin_2 = 9;
// Three
int ledRed_3 =10 ;
int ledGreen_3= 11;
int trigPin_3 = 12;
int echoPin_3 = 13;
int echoPin_4 = 17;
42. University of central Punjab
// Five
int ledRed_5 = 18;
int ledGreen_5= 19;
int trigPin_5 = 20;
int echoPin_5 = 21;
// Six
int ledRed_6 = 22 ;
int ledGreen_6 = 23;
int trigPin_6 = 24;
int echoPin_6 = 25;
// Seven
int ledRed_7 = 26;
int ledGreen_7 = 27;
int trigPin_7 = 28;
int echoPin_7 = 29;
void setup() {
Serial.begin (9600);
// One
pinMode(ledRed_1, OUTPUT);
pinMode(ledGreen_1, OUTPUT);
pinMode(trigPin_1, OUTPUT);
pinMode(echoPin_1, INPUT);
43. University of central Punjab
// Two
pinMode(ledRed_2, OUTPUT);
pinMode(ledGreen_2, OUTPUT);
pinMode(trigPin_2, OUTPUT);
pinMode(echoPin_2, INPUT);
// Three
pinMode(ledRed_3, OUTPUT);
pinMode(ledGreen_3, OUTPUT);
pinMode(trigPin_3, OUTPUT);
pinMode(echoPin_3, INPUT);
// Four
pinMode(ledRed_4, OUTPUT);
pinMode(ledGreen_4, OUTPUT);
pinMode(trigPin_4, OUTPUT);
pinMode(echoPin_4, INPUT);
// Five
pinMode(ledRed_5, OUTPUT);
pinMode(ledGreen_5, OUTPUT);
pinMode(trigPin_5, OUTPUT);
pinMode(echoPin_5, INPUT);
// Six
44. University of central Punjab
pinMode(ledRed_6, OUTPUT);
pinMode(ledGreen_6, OUTPUT);
pinMode(trigPin_6, OUTPUT);
pinMode(echoPin_6, INPUT);
// Seven
pinMode(ledRed_7, OUTPUT);
pinMode(ledGreen_7, OUTPUT);
pinMode(trigPin_7, OUTPUT);
pinMode(echoPin_7, INPUT);
}
void One_sensor(){ // This function is for 1st sensor.
int duration_1, distance_1;
digitalWrite (trigPin_1, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin_1, LOW);
duration_1 = pulseIn (echoPin_1, HIGH);
distance_1 = (duration_1/2) / 29.1;
Serial.print("1st Sensor: ");
Serial.print(distance_1);
Serial.print("cm ");
//if (distance_1 < 2 && distance_1 > 20)
45. University of central Punjab
if (distance_1 > 20)
{ // Change the number for long or short distances.
digitalWrite (ledGreen_1, HIGH);
digitalWrite (ledRed_1, LOW);
delay(2000);
Serial.print("LOW ");
} else {
digitalWrite (ledGreen_1, LOW);
digitalWrite (ledRed_1, HIGH);
}
}
}
void Two_sensor(){ // This function is for 2nd sensor.
int duration_2, distance_2;
digitalWrite (trigPin_2, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin_2, LOW);
duration_2 = pulseIn (echoPin_2, HIGH);
distance_2 = (duration_2/2) / 29.1;
Serial.print("2nd Sensor: ");
Serial.print(distance_2);
Serial.print("cm ");
//if (distance_2 < 2 && distance_2 > 30)
if (distance_2 > 20)
46. University of central Punjab
{ // Change the number for long or short distances.
digitalWrite (ledGreen_2, HIGH);
digitalWrite (ledRed_2, LOW);
delay(2000);
Serial.print("LOW");
}
else {
digitalWrite (ledGreen_2, LOW);
digitalWrite (ledRed_2, HIGH);
}
}
void Three_sensor(){ // This function is for 3rd sensor.
int duration_3, distance_3;
digitalWrite (trigPin_3, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin_3, LOW);
duration_3 = pulseIn (echoPin_3, HIGH);
distance_3 = (duration_3/2) / 29.1;
Serial.print("3rd Sensor: ");
Serial.print(distance_3);
Serial.print("cm ");
// if (distance_3 > 2 && distance_3 < 30)
if (distance_3 > 20)
{ // Change the number for long or short distances.
47. University of central Punjab
digitalWrite (ledGreen_3, HIGH);
digitalWrite (ledRed_3, LOW);
delay(2000);
Serial.print("LOW ");
}
else {
digitalWrite (ledGreen_3, LOW);
digitalWrite (ledRed_3, HIGH);
}
}
void Four_sensor(){ // This function is for 4th sensor.
int duration_4, distance_4;
digitalWrite (trigPin_4, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin_4, LOW);
duration_4 = pulseIn (echoPin_4, HIGH);
distance_4 = (duration_4/2) / 29.1;
Serial.print("4th Sensor: ");
Serial.print(distance_4);
Serial.print("cm ");
//if (distance_4 < 2 && distance_4 > 30)
if (distance_4 > 20)
{ // Change the number for long or short distances.
digitalWrite (ledGreen_4, HIGH);
48. University of central Punjab
digitalWrite (ledRed_4, LOW);
delay(2000);
Serial.print("LOW");
}
else {
digitalWrite (ledGreen_4, LOW);
digitalWrite (ledRed_4, HIGH);
}
}
void Five_sensor(){ // This function is for 5th sensor.
int duration_5, distance_5;
digitalWrite (trigPin_5, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin_5, LOW);
duration_5 = pulseIn (echoPin_5, HIGH);
distance_5 = (duration_5/2) / 29.1;
Serial.print("5th Sensor: ");
Serial.print(distance_5);
Serial.print("cm ");
// if (distance_5 > 2 && distance_5 < 30)
if (distance_5 > 20)
{ // Change the number for long or short distances.
digitalWrite (ledGreen_5, HIGH);
digitalWrite (ledRed_5, LOW);
delay(2000);
49. University of central Punjab
Serial.print("LOW ");
}
else {
digitalWrite (ledGreen_5, LOW);
digitalWrite (ledRed_5, HIGH);
}
}
void Six_sensor(){ // This function is for 6th sensor.
int duration_6, distance_6;
digitalWrite (trigPin_6, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin_6, LOW);
duration_6 = pulseIn (echoPin_6, HIGH);
distance_6 = (duration_6/2) / 29.1;
Serial.print("6th Sensor: ");
Serial.print(distance_6);
Serial.print("cm ");
//if (distance_6 > 2 && distance_6 < 30)
if (distance_6 > 20)
{ // Change the number for long or short distances.
digitalWrite (ledGreen_6, HIGH);
50. University of central Punjab
digitalWrite (ledRed_6, LOW);
delay(2000);
Serial.print("LOW ");
}
else {
digitalWrite (ledGreen_6, LOW);
digitalWrite (ledRed_6, HIGH);
}
}
void Seven_sensor(){ // This function is for 7th sensor.
int duration_7, distance_7;
digitalWrite (trigPin_7, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin_7, LOW);
duration_7 = pulseIn (echoPin_7, HIGH);
distance_7 = (duration_7/2) / 29.1;
Serial.print("7th Sensor: ");
Serial.print(distance_7);
Serial.print("cm ");
//if (distance_7 < 2 && distance_7 > 30)
if (distance_7 > 20)
{ // Change the number for long or short distances.
digitalWrite (ledGreen_7, HIGH);
digitalWrite (ledRed_7, LOW);