Buster

../_images/Buster.jpg

Description

This Project gives tickets for road raging in an attempt to organize traffic and ensure safety. It is made to check the speed of the vehicle moving and according to the results control the traffic lights to provide safety. It is made of two ultrasonic sensors attached to the side of the road. When any vehicle passes by, it will come across both sensors. The program records the time interval of which the vehicle passes across the first and second ultrasonic sensor. If the speed is greater than 50, the camera will shoot a short video of 5 seconds to take the plate number and drivers identity.

Learning Objectives

Buster is a project that helps students learn and apply the following:

  • Velocity and Speed
  • Road safety
  • Internet of things
  • The implementation of the engineering design process
  • Application of theoretical concepts to real life situations
  • Coding, electronics, and physical science through a hands-on application that can be directly related to real life situations

Materials Needed

  • Raspberry pi with micro SD card and Raspbian
  • Jumper wires
  • Breadboard
  • Glue gun and glue sticks
  • Cutter blades or scissors
  • Thick cardboard
  • 12x Resistors
  • 2x Ultrasonic Sensors
  • 2x Red led light
  • 2x Yellow led leds
  • 2x Green leds
  • PiCamera

Setup and Functionality

Buster is designed to detect the speed of a car as it passes in front two ultrasonic sensors and find the time taken to pass from sensor 1 to sensor 2. The two sensors are set across the side of the road at a known distance between them. When the first sensor detects a vehicle (having the distance seen by the sensor decreased) it triggers a time recording until the vehicle passes the second sensor.

../_images/Buster2.jpg

Circuitry and Electronics:

../_images/Buster.png

Programming

import RPi.GPIO as GPIO
import time
import picamera

tR=36
eR=35
tL=38
eL=37
timer_Start = 0
timer_Stop = 0
distance = 10 #cm
GPIO.setmode(GPIO.BOARD)
GPIO.setup(tR,GPIO.OUT)
GPIO.setup(eR,GPIO.IN)
GPIO.setup(tL,GPIO.OUT)
GPIO.setup(eL,GPIO.IN)
GPIO.setup(3,GPIO.OUT)
GPIO.setup(5,GPIO.OUT)
GPIO.setup(7,GPIO.OUT)
GPIO.setup(8,GPIO.OUT)
GPIO.setup(10,GPIO.OUT)
GPIO.setup(12,GPIO.OUT)
GPIO.output(3,False) #Red 2
GPIO.output(5,False) #Yellow 2
GPIO.output(7,False) #Green 2
GPIO.output(8,False) #Red 1
GPIO.output(10,False) #Yellow 1
GPIO.output(12,False) #Green 1

camera = picamera.PiCamera()
while True:
    GPIO.output(tR,False)
    time.sleep(0.5)
    GPIO.output(tR,True)
    time.sleep(0.00001)
    GPIO.output(tR,False)
   
    while GPIO.input(eR)==0:
        pulseStartR = time.time()

    while GPIO.input(eR)==1:
        pulseEndR = time.time()
    pulseDurationR = pulseEndR-pulseStartR
    distanceR= pulseDurationR*17150
    print'Distance R',distanceR
    if distanceR < 10:
        print 'Right Off'
        timer_Start = time.time()
    GPIO.output(tL,False)
    time.sleep(0.5)
    GPIO.output(tL,True)
    time.sleep(0.00001)
    GPIO.output(tL,False)
    while GPIO.input(eL)==0:
        pulseStartL=time.time()
    while GPIO.input(eL)==1:
        pulseEndL=time.time()
    pulseDurationL=pulseEndL-pulseStartL
    distanceL=pulseDurationL*17150
    print'Distance L',distanceL
    if distanceL < 10 and distanceR > 10:
        print 'Left Off'
        timer_Stop = time.time()
        camera.capture('image1.jpg')
        time.sleep(5)


    GPIO.output(3,False) #Red 2
    GPIO.output(5,False) #Yellow 2
    GPIO.output(7,True) #Green 2
    GPIO.output(8,True) #Red 1
    GPIO.output(10,False) #Yellow 1
    GPIO.output(12,False) #Green 1
    time.sleep(1)
    GPIO.output(3,True) #Red 2
    GPIO.output(5,False) #Yellow 2
    GPIO.output(7,False) #Green 2
    GPIO.output(8,False) #Red 1
    GPIO.output(10,True) #Yellow 1
    GPIO.output(12,False) #Green 1
    time.sleep(1)
    GPIO.output(3,False) #Red 2
    GPIO.output(5,True) #Yellow 2
    GPIO.output(7,False) #Green 2
    GPIO.output(8,False) #Red 1
    GPIO.output(10,False) #Yellow 1
    GPIO.output(12,True) #Green 1
    time.sleep(1)

Science Concepts and Skills

Road safety is a big issue all around the world. This project aims at using simple and cheap methods in order to enhance safety and reduce injuries. Using two ultrasonic sensors on the side of the road, a moving car will pass in front of the first sensor and then in front of the second sensor. When any car passes in front of the first senor, time measurement is triggered and the time needed to reach the second sensor in recorded. Since the two sensors are located at a known distance apart from each other, the velocity can be calculated based on the following formula:

Speed = distance/time

Speed is measured in centimeters/second Distance in centimeters Time in second

If the calculated speed is greater than a set figure (50 cm/s in this case) the camera is triggered to take a picture to document the plate number for the driver to get a ticket. However, since the main concern in this project is safety, then in case of a speeding car on a certain lane will delay the red lights on the other lanes until the car passes the cross road. The time needed to pass the crossroad is based on the calculated speed of the car.

Video Tutorial.

Flex your brain! How can this this project be improved to help ambulance and fire engine get faster to their destinations without risking the lives of others?