Table of Contents
Introduction
When you pull your car into the garage, it's always a bit of a guessing game to determine how far to pull in. You want to drive in far enough to close the garage door but not so far that you hit your bicycle or some other obstruction. This project uses ultrasound to help you park your car at a repeatable, predefined distance everytime you pull in. Note: this is just a concept project that utilizes a number of the components in the TINKERkit. We cannot be responsible for software, wiring, hardware, or user errors. So, be aware of this in the event you decide to make this a permanent installation in your garage.
Required Parts
The following parts are required for this project:
- A TINKERplate attached to a preprogrammed Raspberry Pi
- From a TINKERkit
- the HC-SR04 Ultrasonic Sensor
- the mini breadboard
- the 74HCT125 IC chip
- the 8 channel RGB LED module
- the Beeper module
- male to male jumper wires as required
- optional: four male to female jumper wires if you choose to relocate the position of the ultrasonic sensor or LED strip.
Assembly
OK, there's a lot going on with this assembly so study the diagram below very closely and place the jumpers accordingly:
Note that to aid the wiring, we are showing the rear view of the LED strip and the ultrasonic sensor. These two items should face the front of the car low enough to detect the front of the hood but high enough so that the driver can see the LEDs. Depending on the model of the car, you might want to use some of the male to female jumper wires to position either the ultrasonic sensor or the LED strip to a more advantageous position.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import piplates.TINKERplate as TINK import time import traceback #from decimal import Decimal #set distance thresholds in inches dMax=120.0 dClose=40.0 dGood=30.0 dDanger=20.0 stringR = [0xFF,0x0,0x0] #Create a list of red LEDs patterns for i in range(3): stringR=stringR+stringR stringY = [0xFF,0xFF,0x00] #Create a list of yellow LEDs patterns for i in range(3): stringY=stringY+stringY stringG = [0x0,0xFF,0x00] #Create a list of green LEDs patterns for i in range(3): stringG=stringG+stringG stringO = [0x0,0x00,0x00] #Create a list of off LEDs patterns for i in range(3): stringO=stringO+stringO TINK.setDEFAULTS(0) #set all Digital I/O ports to their default states TINK.setMODE(0,1,'rgbled') #set the mode of Digital I/O port 1 to RGB LED TINK.setMODE(0,5,'dout') #set the mode of Digital I/O port 5 to digital output TINK.setMODE(0,78,'range') #set the mode of Digital I/O channel pair 78 to range dist=0.0 #initialize global variables bToggle=False blink=False alarm=False zone=0 while(True): #start repeating loop dist=TINK.getRANGEfast(0,78) #print(dist,zone) #uncomment for debugging try: blink=False #assume no blinking alarm=False #assume no alarm if(dist > dMax): #if measured distance is greater than dMax stringP=stringO #set LEDs to OFF zone=0 elif(dist>dClose): stringP=stringG #set LEDs to green zone=1 elif(dist>dGood): stringP=stringY #set LEDs to yellow zone=2 elif(dist>dDanger): stringP=stringR #set LEDs to red zone=3 else: stringP=stringR #inside danger zone - set LEDs to red blink=True #enable blinking alarm=True #enable alarm zone=4 if((blink and bToggle) or (blink==False)): TINK.setRGBSTRING(0,1,stringP) #send eight LED values to port 1 else: TINK.setRGBSTRING(0,1,stringO) #send right off LEDs to port 1 if(alarm): TINK.setDOUT(0,5) #turn on alarm if enabled else: TINK.clrDOUT(0,5) #turn off alarm otherwise if (bToggle): #toggle bToggle bToggle=False else: bToggle=True except: print("Stabilizing") time.sleep(0.2) #sleep 100msec before repeating |
- git clone https://github.com/pi-plates/TINKERplate-Projects.git
- cd TINKERplate-Projects
- python3 UltraParkingAid.py
The code breaks the distance measurement into different zone and performs a unique action for each:
Zone | Low Distance | High Distance | LED color | Blink | Alarm |
0 | 120" | ∞ | off | FALSE | FALSE |
1 | 40" | 120" | green | FALSE | FALSE |
2 | 30" | 40" | yellow | FALSE | FALSE |
3 | 20" | 30" | red | FALSE | FALSE |
4 | 0" | 20" | red | TRUE | TRUE |
Operation
As you pull in, the LEDs go from off to a steady green. When you are between 30" and 40" the LEDs will switch to yellow indicating you are getting close. When you are between 20" and 30", the LEDs turn a steady red indicating you should stop. If you get closer than 10" the LEDs will start flashing and the alarm will sound. Again, these values can be modified to accommodate your garage and car.