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

Task - 3 Traffic Lights Controller

The document describes a traffic light controller circuit and code that keeps the red light on if an infrared (IR) sensor detects a pedestrian crossing the road. The circuit uses an IR sensor connected to analog pin A0 on an Arduino board. The code defines the LED pins as outputs and checks the sensor value each loop - if above 512, it keeps the red light on to indicate a pedestrian; otherwise it allows the normal traffic light sequence of red, orange, green to proceed every 60 seconds.

Uploaded by

Divyank Shekhar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Task - 3 Traffic Lights Controller

The document describes a traffic light controller circuit and code that keeps the red light on if an infrared (IR) sensor detects a pedestrian crossing the road. The circuit uses an IR sensor connected to analog pin A0 on an Arduino board. The code defines the LED pins as outputs and checks the sensor value each loop - if above 512, it keeps the red light on to indicate a pedestrian; otherwise it allows the normal traffic light sequence of red, orange, green to proceed every 60 seconds.

Uploaded by

Divyank Shekhar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Task -3

TRAFFIC LIGHTS CONTROLLER

The following gives the circuit diagram followed by the code and explanation to
build a traffic signal with three LEDs such that the signal remains red if a
pedestrian is crossing the road.
CIRCUIT DIAGRAM FOR THE TASK
The IR sensor senses whether a pedestrian is crossing or not and gives the corresponding
output to the input pin A0. This pin now gives a high signal for keeping the red light glowing
if the pedestrian is crossing the road and vice-versa.

detailed diagram of an IR sensor

CODE:int sensorPin = A0;


/* This defines the input pin */
unsigned int sensorValue = 0;
/* variable to store the value coming from the IR Sensor*/
int redled=4;
int orangeled=3;
int greenled=2;
void setup()
{
pinMode(A0, INPUT); /* Defines an input pin*/
pinMode(redled, OUTPUT); /* Defines an output pin */
pinMode(orangeled, OUTPUT);
pinMode(greenled, OUTPUT);
Serial.begin(9600)

}
Void loop()
{
digitalWrite(greenled, HIGH); /* turns the green LED on*/
delay(60000);

/* wait for 60 seconds*/

digitalWrite(greenled, LOW); /*turns the green LED off*/


digitalWrite(orangeled, HIGH); /* turns the orange LED on*/
delay(60000);

/* wait for 60 seconds*/

digitalWrite(orangeled, LOW); /*turns the orange LED off*/


digitalWrite(redled, HIGH); /* turns the red LED on*/
delay(60000);

/* wait for 60 seconds*/

if(sensorValue>512) digitalWrite(redled, HIGH); // keeps the red LED on


else digitalWrite(redled, LOW); // red led stops glowing
}
EXPLANATION:We have taken three LEDs and connected one terminal of each one of them to
the negative of the battery, which is also connected to the ground of the
Arduino.
We have taken an IR sensor here as it is cheaper than other complex sensors.
Above ground detectors(ADGs) are also available at a higher price and have
inbuilt features to detect objects clearly.
A power source drives the IR sensor, which after sensing whether there is an
object(pedestrian) or not, gives a signal to the input pin A0 of our circuit which
has one end connected to the sensor output. For example, let us say that if a
pedestrian is crossing the road and the sensor senses this and gives a value that
lies between 512 to 1024 in the output. The input pin receives a number greater

than 512 and gives a HIGH signal to the red LED so that it remains glowing till
the value becomes lower than 512( implying that the pedestrian has crossed the
road). Other LEDs keep glowing at an interval of 60 seconds(using the delay
command) one after the other.

You might also like