girl writing on book

Traffic Light Sensor

The project focuses on the safety of pedestrians near the traffic light junctions. When it is red man, the traffic light sensor will trigger the LED lights to blink, the warning message to display and the buzzer to sound when someone steps into the prohibited zone.

 

Once they move out of the zone, the LED lights will still be on and the warning message will still be displayed, but the buzzer will stop sounding. When the green man appears, the LED light and warning alert will be turned off. 

 

Contributed by Ms Chiam Lee Lee (Teacher), Aretha Lee and Pay Xinyi (Students) from Raffles Girls Primary School 

You Will Need:

1 x BBC micro:bit
1 x micro USB cable
2 x AAA batteries
1 x Wooden cardboard
2 x Spray paint
1 x set Lego figurines and cars
1 x Breadboard and Prototype Shield
1 x Ultrasonic sensor
1 x set LEDs for LED strip and red/green man
1 x set Jumper wires
1 x Buzzer
2 x Synthetic glass patches
1 x Wooden stick
 

Instructions:

1
Identify on an area of interest

Identified on an area of interest and brief study of data to confirm project.

2
Brainstorm

Brainstorm for possible causes of the problem, using fishbone diagram.

3
Use mindmap

Use mindmap to guide and develop solutions to solve the problem.

4
Code the micro:bit

Initially, light sensor was considered, but after testing, it is concluded that the light sensor is not a good solution as the sensitivity of the light sensor depends on the lighting conditions on the road. For example, the light input to the input sensor will be different on cloudy day and night conditions.

Ultrasonic sensor is used to replace light senor. Ultrasonic sensor returns the distance of an object from the ultrasonic sensor and avoids sensing moving vehicle.

Components used
• LEDs
• Buzzer
• Ultrasonic Sensor
• Micro:Bit Display

5
Install LED strip

LED strip installed before restricted area to warn pedestrians not to cross beyond LED strip when it is Red Man.

6
Place sensors and buzzers within restricted area

Designated Restricted Area near the road. The sensors and buzzer will be placed within the restricted area.

7
Test on red sensor

When it is Red Man, the sensor will be turned on and the LED light will be automatic lighted.
When someone steps into the designated restricted area, the sensor will trigger the LED light to blink, the buzzer to sound and the warning message “Stay Clear” to show up. 

 

8
Test on green sensor

When it is Green Man, the sensors will be turned off.

9
Technical Instructions of the Project

Inputs
Button A = Green Man
Button B = Red Man
P2 = Echo (Signal input pin)

Outputs
P0 = Buzzer
P1 = LED strip
P4 = Trig (Signal output pin)
P5 = Button A
P8 = Red LED (indicate Red Man)
P11 = Button B
P12 = Green LED (indicate Green Man)


Variables
Push Button 1 → To store (indicate) if it is Green Man or Red Man now. If the value is 0, then it is Green Man. If the value is 1, then it is Red Man.

Light Sensor → To store the distance of an object from the ultrasonic sensor.  

Notes

Ultrasonic sensor uses sound waves to measure the distance of an object. The sensor outputs (P4) a sound wave and it will be reflected back to the sensor’s inputs (P2). After the sound wave is sent out, the sensor will time how long it takes for the reflected sound to get back to the ultrasonic sensor.

10
Initialization

● Set P1 = 0 is to turn off all LED strip
● Set buzzer to rest at 1/8 beat
● Set Push Button 1 to 0 is to set everything to Green Man.

11
Run forever loop continuously

If Button A (Green Man) is pressed, do the following:
● Set variable Push Button 1 to “0”
● Set Buzzer to rest at 1/8 beat
● Turn on Green LED by setting P12 to “1”
● Turn off Red LED by setting P8 to “0”

If Button B (Red Man) is pressed, do the following:
● Set variable Push Button 1 to “1”
● Turn on LED strip by setting P1 to “1”
● Turn off Green LED by setting P12 to “0”
● Turn on Red LED by setting P8 to “1”

If it is Red Man, do the following:
● Turn on the ultrasonic sensor and returns the distance in cm.
● Store the distance in the lightSensor variable.
● If the lightSensor variable is between 0 and 9, then repeat the following 3 times. 
o Turn on LED strip by setting P1 to “1”
o Sound the buzzer and pause for 20 ms
o Turn off LED strip by setting P1 to “0” (this is to create the blinking effect)
● If the lightSensor variable is not between 0 and 9 (else statement), do the following:
o Continue to turn on LED strip by setting P1 to “1”

If it is not Red Man, do the following:
● Clear everything.

12
Project complete!

If it is Red Man, do the following:
● Turn on the ultrasonic sensor and it returns the distance in cm.
● Store the distance in the lightSensor variable.
● If the lightSensor variable is between 0 and 9, then repeat the following 3 times. 
o Show “STAY CLEAR” in microbit screen.

More Projects
View All Projects