Introduction: Raspberry Pi Park Sensor

Picture of Raspberry Pi Park Sensor

In this instructable we're gonna be building a park sensor. The idea of this park sensor is to show green when you have plenty of room to pull your car forward in parking lot, and then turn yellow as you approach the fully forward position, and then red when you should stop. We're going to build this system with our Raspberry Pi, and use some distances that we can easily test.

Step 1: Things You Will Need

Picture of Things You Will Need

You will need the following components other than Raspberry Pi setup.

  1. HC-SR04 Ultrasonic Distance Sensor
  2. Led (X3)
  3. 330Ω Resistor (X3)
  4. 10KΩ Resistor (x2)
  5. Male-Male / Male-Female Jumper Wires
  6. Breadboard

Step 2: Do the Wiring

Picture of Do the Wiring
  1. Trigger for the distance sensor is GPIO 4, echo is GPIO 18, the green light is 17, the yellow light is 27 and the red light is 22.
  2. 330 ohm resistors are for the leds and they are connecting to the positive leg of the leds and then GPIO.
  3. 10K ohm resistors are for the echo pin of the distance sensor and connect to the GPIO.

Step 3: Code

import RPi.GPIO as GPIO
import time

GPIO.setwarnings(False)

GPIO.cleanup()

GPIO.setmode(GPIO.BCM)

TRIG = 4

ECHO = 18

GREEN = 17

YELLOW = 27

RED = 22

GPIO.setup(TRIG,GPIO.OUT)

GPIO.setup(ECHO,GPIO.IN)

GPIO.setup(GREEN,GPIO.OUT)

GPIO.setup(YELLOW,GPIO.OUT)

GPIO.setup(RED,GPIO.OUT)

def green_light():

GPIO.output(GREEN, GPIO.HIGH)

GPIO.output(YELLOW, GPIO.LOW)

GPIO.output(RED, GPIO.LOW)

def yellow_light():

GPIO.output(GREEN, GPIO.LOW)

GPIO.output(YELLOW, GPIO.HIGH)

GPIO.output(RED, GPIO.LOW)

def red_light(): GPIO.output(GREEN, GPIO.LOW)

GPIO.output(YELLOW, GPIO.LOW)

GPIO.output(RED, GPIO.HIGH)

def get_distance():

GPIO.output(TRIG, True)

time.sleep(0.00001)

GPIO.output(TRIG, False)

while GPIO.input(ECHO) == False: start = time.time()

while GPIO.input(ECHO) == True: end = time.time()

signal_time = end-start

distance = signal_time / 0.000058

return distance

while True:

distance = get_distance()

time.sleep(0.05)

print(distance)

if distance >= 25:

green_light()

elif 25 > distance > 10:

yellow_light()

elif distance <= 5:

red_light()

If the distance is greater than or equal to 25 cm, we show a green light. If it's between 10 and 25 cm, we'll turn yellow, and then we'll turn red for less than or equal to 10 cm.

Comments

BüşraY1 (author)2017-12-04

I have error in line 32 GPIO.output(GREEN, GPIO.HIGH)

amitkumarji501 (author)2017-11-12

please provide schematic circuit Data

tugceko (author)amitkumarji5012017-11-18

I just upload the diagram. You can find it in the wiring step.

tugceko (author)amitkumarji5012017-11-13

okay, I'll draw the diagram on the illustrator, post it soon and let you know.

cangulseren (author)tugceko2017-11-14

Do you have the schematic yet?

tugceko (author)cangulseren2017-11-18

I just upload the diagram. You can find it in the wiring step.

swoolley (author)2017-11-17

Believe it or not, I setup my own solution using the Pi and the HC-SR04 Ultrasonic Distance Sensor. The problem I had is that the car engine noise when pulling close to the sensor seem (my guess) to cause highly erratic distance measurements.

Swansong (author)2017-11-10

I'd love to have something like this in the garage, our jeep is kind of tall and the bike is not so it is easy to pull to far in and bump it.

tugceko (author)Swansong2017-11-13

This is a simple project. It can be improved with buzzer, multiple leds and maybe a box for the circuit. Then it can be useful for garage use. :)

rickharris (author)2017-11-11

This is fine if it is mounted in a garage but potential project users should be aware that the standard Ultrasonic TX/RX are NOT waterproof. They don't last long mounted on a car bumper.

tugceko (author)rickharris2017-11-13

of course not.

About This Instructable

1,874views

22favorites

License:

Bio: something like this but not this
More by tugceko:Raspberry Pi Park Sensor
Add instructable to: