Sandaru
Sandaru
Uog04
Group-02
1|Page
INTRODUCTION
The incident happening on the above scenario is a time-scheduled traffic light
system. When an individual is detected at the points a and b, after 20 seconds the
light should change into Yellow. After 10 seconds, the light will turn into Red. When
the light is Red, if a person is detected crossing the light, an alarm should go off via
a buzzer. The light should turn Green once the sensor has detected the person has
finished crossing the road.
trigPin = 6; int
echoPin = 4;
echoPin2 = 3;
echoPin3 = 5;
int green_led = 10; int yellow_led = 9; int red_led = 13; long duration,
void setup()
{
2|Page
Serial.begin(9600); pinMode(6,
INPUT); pinMode(4,
OUTPUT); pinMode(2,
INPUT); pinMode(3,
OUTPUT); pinMode(7,
INPUT); pinMode(5,
OUTPUT); pinMode(12,
OUTPUT); pinMode(2,
OUTPUT); pinMode(3,
OUTPUT); pinMode(7,
OUTPUT);
void cross_checking() //this function create for checking pedestrian crossing if free or no
digitalWrite(6,LOW);
delayMicroseconds(2);
digitalWrite(6,HIGH);
delayMicroseconds(10);
digitalWrite(6,LOW);
duration=pulseIn(4,HIGH); distance=
duration*0.034/2; safetyDistance =
distance;
if (safetyDistance <= 30) // road distance is 30 m this part check somebody walk on the
// crossing and any one on the crossing turn on buzzer. {
digitalWrite(buzzer, HIGH);
}
3|Page
else
digitalWrite(buzzer, LOW);
Serial.print("Distance: ");
Serial.println(distance);
digitalWrite(6,LOW);
delayMicroseconds(2);
digitalWrite(6,HIGH);
delayMicroseconds(10);
digitalWrite(6,LOW);
duration=pulseIn(4,HIGH); distance=
duration*0.034/2;
checkingDistance=distance;
if (safetyDistance <= 20) // this part check somebody on the right side of the crossing
// crossing tower height is 23 and somebody come there this
// tower height descries less than 23 after run if condition.
delay(10000);
digitalWrite(yellow_led, HIGH);
delay(20000); digitalWrite(yellow_led,
else
4|Pa ge
digitalWrite(green_led, HIGH);
digitalWrite(6,LOW);
delayMicroseconds(2);
digitalWrite(6,HIGH);
delayMicroseconds(10);
digitalWrite(6,LOW);
duration=pulseIn(4,HIGH); distance=
duration*0.034/2;
checkingDistance=distance;
if (safetyDistance <= 20) // this part check somebody on the right side of the crossing
// crossing tower height is 23 and somebody come there this
// tower height descries less than 23 after run if condition.
delay(10000);
digitalWrite(yellow_led, HIGH);
delay(20000); digitalWrite(yellow_led,
else
digitalWrite(green_led, HIGH);
}
5|Page
void loop()
cross_checking();
check_left(); check_right();
Algorithm Part
• For cross_checking();
start
If
pedestrian
crossing
free
6|Page
Turn on buzzer
End
start
If
pedestrian
left side fill
End
Link:- https://www.tinkercad.com/things/eTVA5CWRjUR-grand-
amberis/editel?sharecode=sV1rot4ZTWTA51wKmfMIoHt9DYJa0LFGbw
OaMFPAJ_8
This program ;-
o Any one comes a ans b side After 20S should light up the yellow traffic
light When all pedestrians are crossed the road, traffic light should
change to to ready for stopping vehicles.
o After 10S should light up the red traffic light to stopping vehicles.
o back.