Traffic Light Signal With Raspberry Pi

Introduction

In this blog, I am going to explain about the Traffic Light Signal With Raspberry Pi. It will see the time delay in the light and it will see it as the traffic light. I have made a little program to run some LEDs via the GPIO triggered by a push button to do a traffic light sequence.

Parts Of Lists

  1. Raspberry Pi
  2. LED's
  3. Push Button
  4. Bread Board
  5. Hook up Wires

Traffic Lights

  1. Traffic lights, also known as traffic signals, traffic lamps, traffic semaphore, signal lights, stop lights, robots (in South Africa) and (in technical parlance) traffic control signals.
  2. The signalling devices are positioned at the road intersections, pedestrian crossings and other locations to control the flow of traffic.
  3. The world's first, manually operated gas-lit traffic signal was short lived. Installed in London in December 1868, it exploded less than a month later, injuring or killing its policeman operator.
  4. Traffic control started to seem necessary in the late 1890's and Earnest Sirrine from Chicago patented the first automated traffic control system in 1910. It used the words "STOP" and "PROCEED", although neither word lit up.

    IoT

Traffic Signal Timing

  1. Traffic signal timing is the technique where the traffic engineers are required to determine who has the right-of-way at an intersection.
  2. Signal timing involves deciding how much green time the traffic lights shall provide at an intersection approach, how long the pedestrian WALK signal should be and many other numerous factors.

Connection for Traffic signal

Take the 3 LEDS for the experiment

  1. Led1:GPIO11
  2. Led2:GPIO12
  3. Led3:GPIO13
  4. Connect all the negative pins to the GND.
  5. Connect the SD Card with the OS and the data cable.

Programming

  1. #  
  2. import time and gpio modules  
  3. import time  
  4. import RPi.GPIO as GPIO  
  5.  
  6. # set pin 11, 12 and 13 as an outputs  
  7.   
  8. GPIO.setup(11, GPIO.OUT)# red light  
  9. GPIO.setup(12, GPIO.OUT)# amber light  
  10. GPIO.setup(13, GPIO.OUT)# green light  
  11.  
  12. # set pin 15 as our input  
  13. GPIO.setup(15, GPIO.IN)# push button  
  14.  
  15. # set counters at zero  
  16. carA = 0  
  17. flashA = 0  
  18.  
  19. # set up a  
  20. while loop so the program will keep repeating itself indefinately  
  21. while True: #call pin 15 button  
  22. button = GPIO.input(15)# if button is pressed set carA as 1  
  23. if button == False:  
  24.     carA = 1  
  25.  
  26. #  
  27. if no car detected turn off green and amber lights and# turn on red light  
  28. if carA == 0:  
  29.     GPIO.output(11, True)  
  30. GPIO.output(12, False)  
  31. GPIO.output(13, False)  
  32.  
  33. #  
  34. if car detected then run through sequence  
  35. if carA == 1: #amber light on  
  36. GPIO.output(12, True)# wait 5 seconds  
  37. time.sleep(5)# turn off red and amber lights  
  38. GPIO.output(11, False)  
  39. GPIO.output(12, False)# turn on green light  
  40. GPIO.output(13, True)# wait 5 second  
  41. time.sleep(5)# turn off green light  
  42. GPIO.output(13, False)# set while loop to flash amber light 5 times  
  43. while flashA < 5: #on, wait 5 seconds  
  44. GPIO.output(12, True)  
  45. time.sleep(.5)# off wait 5 seconds  
  46. GPIO.output(12, False)  
  47. time.sleep(.5)# add one to the flash counter  
  48. flashA = flashA + 1# reset flash counter  
  49. flashA = 0# reset carA  
  50. carA = 0  
Explanation 
  1. In this blog, i have explained about the traffic signal by the correct delay time.
  2. The output will be set as the GPIO pin and connect the push button to turnoff all the LEDs when not in use.
  3. The traffic signal is very useful for the real time.The operation of traffic signals is currently limited by the data available from traditional point sensors. Point detectors can provide only limited vehicle information at a fixed location.

Output

IoT

Ebook Download
View all
Learn
View all