connect@howdiyworld.com
|

Traffic Light Control

What is Needed?

RGB LED X 2
IR Sensor X 2
Jumpers
HowDIY

BLOCK DIAGRAM

Procedure

  1. IR sensors and RGB LED
  2. Connections
  3. Program
  4. Output

IR Sensor

An infrared sensor is an electronic device, that emits in order to sense some aspects of the surroundings. An IR sensor can measure the heat of an object as well as detects the motion.

RGB LED

A RGB LED or Light Emitting Diode is a Semiconductor  with Four terminal(Pin) component, the Four terminals are R,G,B(+)Positive and (-)Negative. To get Red Light Connect R and Negative pins where R is positive, To get Green and Blue do the same to G and B Pins.

Connections

  • ·       Connect IR1’s VCC to 2nd pin.

    ·       Connect IR1’s GND to 6th pin.

    ·       Connect IR1’s Digital out(D0) to 8th pin.

    ·       Connect IR2’s VCC to 4th pin.

    ·       Connect IR2’s GND to 9th pin.

    ·       Connect IR2’s Digital out(D0) to 10th pin.

    ·       Connect RGB1 LED’s  Red(R) to 12th pin.

    ·       Connect RGB1 LED’s Green(G) to 16th pin.

    ·       Connect RGB1 LED’s Ground(GND) to 14th pin.

    ·       Connect RGB2 LED’s  Red(R) to 18th  pin.

    ·       Connect RGB2 LED’s Green(G) to 22nd pin.

    ·       Connect RGB2 LED’s Ground(GND) to 20th pin.

Python Programing

import RPi.GPIO as GPIO

import time

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BOARD)

GPIO.setup(8,GPIO.IN)

GPIO.setup(10,GPIO.IN)

GPIO.setup(12,GPIO.OUT)  #Red 1

GPIO.setup(16,GPIO.OUT)  # Red 2

GPIO.setup(18,GPIO.OUT)  # Green 1

GPIO.setup(22,GPIO.OUT)   # Green 2

#GPIO.cleanup()

c1=0

c2=0

c3=0

while True:

a=GPIO.input(8)

b=GPIO.input(10)

if a==GPIO.HIGH:

c1=c1+1

print(“T1")

time.sleep(0.3)

if b==GPIO.HIGH:

c2=c2+1

print(“T2")

time.sleep(0.3)

if c1>5:

print(“Sensor 1")

GPIO.output(12,False)

GPIO.output(22,False)

GPIO.output(18,True)

GPIO.output(16,True)

time.sleep(5)

c1=0

if c2>5:

print(“Sensor  2")

GPIO.output(18,False)

GPIO.output(16,False)

GPIO.output(22,True)

GPIO.output(12,True)

time.sleep(5)

c2=0

c3=c3+1

time.sleep(0.2)

if c3>25:

print(“Green 2")

GPIO.output(18,False)

GPIO.output(16,False)

GPIO.output(22,True)

GPIO.output(12,True)

if c3<25: print("Green 1") GPIO.output(12,False) GPIO.output(22,False) GPIO.output(18,True) GPIO.output(16,True) if c3>50:

c3=0

Output

Here Traffic Light automation work, if more than 5 vehicle cross the IR1 Sensor it’s assume over crowd so signal automatically changed (RGB1)Red to Green for reduce the traffic. Then after 5sec its will automatically changed. 

Social media & sharing icons powered by UltimatelySocial
Facebook
Twitter
YouTube
LinkedIn
Instagram