parking

Ultrasound Parks My Car

Every day I back my Toyota 4Runner into my garage at home. I have a backup camera which makes it very easy to not hit anything. But that’s not good enough. I like to maximize my available space and this requires me getting my truck just barely inside the garage door. My quest for the perfect parking job has cost me one slightly bent garage door handle. I do have some visual aids in the garage which get me fairly close, but these all rely on me aligning them to something in the car which means there’s tons of error due to parallax. I can do better than this…

So I decided to use a sensor to detect my distance and tell me when I had reached the perfect distance for parking. There are many options, but I wanted a fairly fast sample rate (~10hz) and max range wasn’t a huge issue since the maximum distance I cared about was only the length of my garage. I decided to go with a cheap ultrasonic ranging sensor (HCSR04 Datasheet). It’s a very simple sensor to work with. You just pull the trigger line high for 10uS, the device then sends out an 8 cycle burst of sound at 40kHz. I then just wait for the ‘Echo’ line to go high and time how long it stays high. I can then calculate the distance that the sound burst was able to travel in that amount of time.

Getting distance measurements was fairly easy. I then needed to be able to see this distance value as I backed up my truck. For display, I used an Osepp LCD Keypad Shield I had been working with on another project. It has a blue background and nice bright characters. Driving an LCD with an Arduino is dirt simple. I just used the built-in LiquidCrystal library in Arduino and it worked like a charm.

An Arduino Uno, an ultrasonic sensor, and an Osepp display shield ready to be joined together like Voltron.

 

An Arduino Uno, an ultrasonic sensor, and an Osepp display shield ready to be joined together like Voltron.

The image above shows the modules I used for this project. I decided to solder some male->female jumper leads onto the LCD shield to make it easier to connect the ultrasound rangefinder and position it wherever I wanted during testing.

Utmost craftsmanship goes into testing the firmware and getting some real-world values for where I need to park my car.

 

Utmost craftsmanship goes into testing the firmware and getting some real-world values for where I need to park my car.

I crudely taped the unit to the wall at about the same height as my backup camera on my 4Runner. This allowed me to get some quick measurements of an ideal distance as seen by the sensor. Turns out, the perfect parking distance for my truck in my garage is 87cm from where I expertly taped this sensor.

Things I learned:

  • Arduino proves once again to be super easy to work with
  • The display looks great, but it is difficult to view through my backup camera
  • 87cm is the perfect parking distance to allow my hatchback to open and not hit my outdoor gear on the wall.

Next Steps:

  • Explore other display options (big 7-segment, colored LEDs, etc)
  • Explore different types of feedback (audio, mechanical)
  • Make the unit shutdown the display until it is needed.
  • Design a custom housing (either vacuum formed or 3D printed)

Here’s some rough sample code:

#define trigPin 3
#define echoPin 2

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print(“Parking Distance:”);
}

void loop() {
long duration, distance;
lcd.setCursor(7,1);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance >= 300 || distance <= 0){
//TODO: Turn off Display
}else {
lcd.print(distance);
lcd.print(” “);
}
delay(100);
}