Arduino parking sensor
February 12, 2011 9 Comments
(This project is also posted on instructables http://www.instructables.com/id/Arduino-reverse-obstacle-sensor-for-cars/)
My wife has told me about a reverse/backing parking sensor her friend has on their car. It helps someone parallel park in a tight spot. We normally don’t need one but I can see sometimes having one will really help. So I set out to make her one tonight.
As a physicist, I have to lecture on the principle of the sonic ranger a bit. It is a rather simple device, the small cousin of the police speed gun! The sonic ranger sends a few pulses of supersonic waves and waits for the waves to bounce back from an object in front of it. Once it detects the reflected sound, it knows how much time it took the waves to travel a round trip from the ranger to the obstacle and back. With speed of sound at around 340m/s, you can calculate the distance to an object. You can also find velocity if you measure distance at two consecutive times and do distance change over time. Bats use their sonic ranger to fly in pitch black caves or catch food! Mr. English also tried the same technique with no apparent training and failed miserably. One episode of Stan Lee’s super heroes also featured a blind person using his tongue clicks to tell what’s around! That’s it for sonic ranger intro!
Diagram from Parallax
After some coding, wiring, swearing, I’ve got a working prototype. It has the following functions:
- Displays distance to an obstacle in feet/inch and mm.
- Display analog distance as bar graph
- Audio alert of distance as frequency of beeps, like a radioactive sensor (Geiger Muller counter) so that the beeps become more frequent as the car approaches the obstacle closer.
- Adjustable audio alert beep frequency so she can pick an appropriate parameter just for her.
I’ve listed the parts here:
- One arduino Duemilanove or UNO (many vendors sell this)
- One Phi-1 shield kit for arduino (dipmicro.com) I designed this shield. Here is documentation. They also sell this on ebay.
- One RJ11 jack and breakout board. I made some breakout boards myself and used the RJ11 jack from the Phi-1 kit. But you can buy from sparkfun: Rj11 jack and RJ11 breakout board. You have to observe which pin is which with a multimeter.
- One four-wire phone cable. Just go to a dollar store and make sure you’re not getting two-wire cables.
- One Ping or other ultrasonic sensor from parallax. Alternatively you can also buy this one from sparkfun. You will have to make sure you’re connecting the PWM pins to arduino. I don’t have this.
- One 1uF capacitor. You can get it anywhere you but the other parts.
- Either a car power adapter that outputs center-positive 9V to 12V or a 9V battery with a connector from here http://dipmicro.com/store/BH9V
First, assemble your Phi-1 kit. Make sure you solder on the buzzer on top right corner, and one RJ11 jack on the bottom right corner, like in this picture:
Next, test it with the test code found on the Phi-1 shield home page to make sure it works.
Assembling hardware is easy:
- Solder the RJ11 jack on its breakout board.
- Connect phone cord between the shield and the RJ11 jack with breakout board. Determine which pin on the breakout board goes where on the shield
- You will need a cable or solder three wires to the sonic ranger. I found this connector in my drawer but if you don’t have one, go to a surplus store. Old CD-roms also have these wires. Make sure you get the right pin to the sonic ranger. Test with mulitmeter. I used my own breakout board so all signals are marked. Since the cable is only 3-pin, I had to feed 5V on the X pin on my shield. I jumped the x pin to 5V. If you have a cdrom cable you have 4 pins and can switch out pin orders easily with a small jeweler’s screw driver. The output of the sonic ranger should go to arduino channel 2 Y, which is connected to analog 3.
- Stick a 1uF capacitor between 5V and GND to filter out noise. Trust me, this is not optional! Observe polarity of your cap.
- Run my program and use it!
I have made two versions of the program, a fully interactive one with menu and adjustable parameters. Another version is a nutshell, if you’re interested in learning how things work quick.
Phi-menu version (see my phi-menu page)
First I tested it indoors with my wife. Everything works fine (first two videos).
Since it’s warm today (by our local standard) so I got out and installed the sensor with my wife. It worked! (next four videos).
12FT 4-wire phone cord, about 10 pieces of wide tape and some masking tape later, the sensor is on my rear bumper sticker. I had it on my trunk first but it is angled and too high. It couldn’t detect a car but a garage door was fine. So I moved it to the middle of the rear bumper cover.
Here are some pictures I took in a parking lot after backing towards some other dude’s car seriously close (more than I am comfortable without the sensor).
Since there is only one sensor, backing straight is most accurate but backing while turning is not. I need at least two sensors one on each side to cover both sides. Since I’ve got this thing working, I’ve become more observant and saw many newer cars have small attachments on their rear bumper covers, two or four. I suppose they’re either the sonic rangers or empty spots for installation. Will save money for a second sensor 🙂
If you are copying this project, make sure you get two rangers. Phi-1 shield can pass two signals on one 4-wire phone cord. Also make sure you get sensors built for wider angular response so you’re not just testing obstacles right behind but on the side as well. Mine is built for precise measurement so it only detects object more or less right in its line of sight.
Updated housing and mounting options:
I’ve made a small plastic sheet housing out of some 3X5 card holder with my blade half way and fold into a box, then attach some cardboard behind the sensor to prevent it from sliding, nice! Now attaching some 3M command pads with “velcro” I can attach my sensor on my car and easily remove it when it rains outside.
I will mount the sensor next weekend.
More updates today: I turned on the sensor in my electronics class to show my students how it works but to my surprise it’s not working! I then realized we have acoustic ceiling panels that absorb sounds! So I instead pointed it to the floor. Not working either. Nor did the white board. I just got random numbers around 500mm+-300mm. I tried and tried. Then I thought maybe my new housing is interfering with the sound or my capacitor was not well connected. The I tried it in an electronics lab with the same results, the floor is not accurately sensed beyond 400mm.
Then I went back to my office and thought I had to rip the nice housing open. Before I decided to do it, I gave it a last try in my office. Well, it worked again! I guess very plainer materials like floor tiles and white boards reflect most sound just as they do light, mirror reflection so it’s very hard to make the sound reflect exactly back to the source to be detected. But I have carpet in my office, perfect scatterer, so it scatters in all directions. Although scattering reduces reflected intensity very largely, it makes the reflection a wide-angle source so the reflection (although weak) makes it back to the source to get amplified and detected. The number is stable again and physics work! Hahaha!
Here’s the videos:
Run 1 video:
Run 2 video:
Pulling away from garage door:
Driving towards garage door:
In parking lot very close to another car: