Traffic Light Sequence

Overview

This simple project controls a single UK road traffic light, and stops the traffic whenever a pedestrian wants to cross the road.

The Hardware

The electronics consist of three LEDs (red, yellow and green) which are connected to the digital pins D1, D2 and D3 via current limiting resistors. The pedestrian crossing input is a single button connected between 3v and D4.

The Breadboard

The pictures below shows the device in action.

And a nice little GIF of it in actionů

The Code

The program shows the green light and waits in a loop until the pedestrian crossing button is pushed. It then shows the amber light for 3 seconds, then the red light for three seconds. After that the amber comes on also for a further three seconds, and then switches back to a green light.

10 REM TRAFFIC LIGHTS
20 REM SETUP PINS
30 SYS 10,1,1:SYS 10,2,1:SYS 10,3,1:SYS 10,4,0
100 REM START ON GREEN
110 GOSUB 1200
115 REM WAIT FOR THE CROSS ROAD BUTTON
120 REPEAT
121 UNTIL SYS(12,4)=1
130 GOSUB 1300
140 WAIT(3000)
150 GOSUB 1000
160 WAIT(3000)
170 GOSUB 1100
180 WAIT(3000)
190 GOTO 110
1000 REM RED LIGHT
1010 SYS 11,1,1:SYS 11,2,0:SYS 11,3,0
1020 RETURN
1100 REM RED-AMBER
1110 SYS 11,1,1:SYS 11,2,1:SYS 11,3,0
1120 RETURN
1200 REM GREEN
1210 SYS 11,1,0:SYS 11,2,0:SYS 11,3,1
1220 RETURN
1300 REM AMBER LIGHT
1310 SYS 11,1,0:SYS 11,2,1:SYS 11,3,0
1320 RETURN


(c) 2017 PicoCreate

Terms and conditions apply, click here for further details