0% found this document useful (0 votes)
35 views

Sandaru

The document describes an Arduino program for controlling a traffic light system using ultrasonic sensors. The program uses sensors to detect pedestrians and vehicles, then controls the lights accordingly, changing to yellow after 20 seconds and red after 10 more seconds if a pedestrian is detected. It also includes an alarm to sound if a pedestrian crosses when the light is red.

Uploaded by

Jayan Sama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Sandaru

The document describes an Arduino program for controlling a traffic light system using ultrasonic sensors. The program uses sensors to detect pedestrians and vehicles, then controls the lights accordingly, changing to yellow after 20 seconds and red after 10 more seconds if a pedestrian is detected. It also includes an alarm to sound if a pedestrian crosses when the light is red.

Uploaded by

Jayan Sama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Sandaru Samuditha Alwis

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.

Project Arduino cord


// C++ code int

trigPin = 6; int

echoPin = 4;

int trigPin2 = 2; int

echoPin2 = 3;

int trigPin3 = 7; int

echoPin3 = 5;

int buzzer = 12;

int green_led = 10; int yellow_led = 9; int red_led = 13; long duration,

inches , distance , safetyDistance , checkingDistance , cm;

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);

void check_left() //this function checking left side of the road

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,

LOW); digitalWrite(red_led, HIGH);

else
4|Pa ge

digitalWrite(green_led, HIGH);

void check_right()//this function checking right side of the road

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,

LOW); digitalWrite(red_led, HIGH);

else

digitalWrite(green_led, HIGH);

}
5|Page

void loop()

cross_checking();

check_left(); check_right();

Algorithm Part

• For cross_checking();

start

Get input from ultrasonic

If
pedestrian
crossing

free
6|Page
Turn on buzzer

Turn off buzzer

End

Algorithm for check_left() and check_right()

start

Get input from ultrasonic

If
pedestrian
left side fill

After 10S turn on yellow led then

20s turn on red led road side and

Turn on green led on crossing


7|Page Turn on green led road side

Turn on red led on crossing side

End

• Thinkercad circuit diagram

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.

You might also like