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 signaling 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 1890s 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. # import time and gpio modules  
  2. import time  
  3. import RPi.GPIO as GPIO  
  4.   
  5. # set pin 11, 12 and 13 as an outputs  
  6.   
  7. GPIO.setup(11, GPIO.OUT)# red light  
  8. GPIO.setup(12, GPIO.OUT)# amber light  
  9. GPIO.setup(13, GPIO.OUT)# green light  
  10.   
  11. # set pin 15 as our input  
  12. GPIO.setup(15, GPIO.IN)# push button  
  13.   
  14. # set counters at zero  
  15. carA = 0  
  16. flashA = 0  
  17.   
  18. # set up a while loop so the program will keep repeating itself indefinitely 
  19. while True#call pin 15 button  
  20.     button = GPIO.input(15)# if button is pressed set carA as 1  
  21.     if button == False:  
  22.       carA = 1  
  23.   
  24. #if no car detected turn off green and amber lights and  
  25. # turn on red light  
  26. if carA == 0:  
  27.     GPIO.output(11True)  
  28.     GPIO.output(12False)  
  29.     GPIO.output(13False)  
  30.   
  31. #if car detected then run through sequence  
  32. if carA == 1#amber light on  
  33.     GPIO.output(12True)# wait 5 seconds  
  34.     time.sleep(5)# turn off red and amber lights  
  35.     GPIO.output(11False)  
  36.     GPIO.output(12False)# turn on green light  
  37.     GPIO.output(13True)# wait 5 second  
  38.     time.sleep(5)# turn off green light  
  39.     GPIO.output(13False)# set while loop to flash amber light 5 times  
  40.       
  41. while flashA < 5#on, wait 5 seconds  
  42.     GPIO.output(12True)  
  43.     time.sleep(.5)# off wait 5 seconds  
  44.     GPIO.output(12False)  
  45.     time.sleep(.5)# add one to the flash counter  
  46.     flashA = flashA + 1# reset flash counter  
  47.     flashA = 0# reset carA  
  48.     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