Introduction: ChipKIT Parking Obstacle Sensor
I've always thought it would be nice to have a car with a parking sensor. I don't want to spend that kind of money until I pay off my student loans. However I do have the materials to make one myself thanks to a class I took on microcontrollers. Part of my motivation is that my car doesn't make parking particularly easy. The back end is tall and it doesn't extend out very far so I'm usually too far or too close.
This project will show you how to build your own parking obstacle sensor for your car.
This obstacle sensor shows the distance in inches, cm, or mm depending on the "units" variable you can change in the code. It also displays between 0 to 16 bars in the bottom indicating 0 to 255 inches. The sonar module can only detect between 6 and 255 inches. Any less than 6 will show as 6 and any more than 255 will display as 255.
Step 1: Tools and Materials
What do you need?
- Soldering Iron
- Pliers and Wire Strippers
- Helping Hands (optional but highly recommended)
- 3/32 inch dia black heat shrink tubing - $3.49
- 1/4 - 1/8 inch dia black heat shrink tubing - $2.99
- Velcro for Auto BLACK : 1-1/2IN X 2 FT - $9.49 (You only need 1-1/2 in X 4 in. I just bought extra for other projects)
- 25 ft cat5e patch cable - $7.99
- chipKIT Pro MX4 : Embedded Systems Trainer Board - $79
- PmodCLS: Character LCD with Serial Interface - $39.99
- PmodMAXSONAR: Maxbotix Ultrasonic Range Finder - $34.99
- Standoffs - $1.49
- Battery Holder - $2.99
- 2x Pmod cable kit: 6-pin (6 in) $3.99
Step 2: Initial Testing
Test the hardware first to make sure it works and you have the pin selections right. To do this you will need MPIDE. I had used my board with MPLAB X IDE previously so I needed to reinstall the bootloader on the MX4 before I could use it with MPIDE. If you have a fresh board you will not have to do this.
Now download the example project for the PmodCLS LCD screen here. Get the one under MPIDE and follow the README contained within. Open the example project CLSDemo under CLS and upload it to the board. If all the jumpers are in the right places the program will run and show the screen you can see in the first picture.
note: If you get the error indicating you need Bounce.h get it from here and add it to your libraries.
To run the example project for the MAXSonar module on an MX4 you'll need to change a few pin definitions in the program.
#define ANpin 48
#define RXpin 49
#define PWpin 50
Get the example installed and change the pins to the following and plug the sonar module into the top row of JH. If you upload your revised example project and open the Serial Monitor window in MPIDE you should see the same output as you see in the Serial Monitor.
With that taken care of we can put the obstacle sensor together and program it.
Step 3: Hardware Layout
I wanted this project to be as portable as I could make it given the size of the MX4. The screw holes on the LCD line up perfectly with the left or right screw holes on the MX4 so I decided to screw it to the top using standoffs. They were a touch too short so I added washers on the top and bottom of the standoffs as you can see in picture 2.
To stop the LCD cable sticking out the side bend the Pmod Header pins around. Use a pair of pliers to bend all of the pins up. It doesn't take very long.
The battery will be attached to the back using velcro in a later step.
Step 4: Software
Download the MyRangeDisplay folder and open MyRangeDisplay.pde with MPIDE. Upload this to your MX4 board and it should display the distance from the sonar module to the nearest detectable obstacle. I only have one sensor displaying on the screen but when I get another one I will modify it to show both on the same screen. It might be more cramped on the display but it will help when backing towards something at an angle.
The most up to date version of this program will be on my GitHub here. I know I'll have to tweak the program to make it more to my liking.
Step 5: Check Wire Orientation
Before this step double check the length of your Cat5e patch cable. Run it all the way from the trunk, through the seats and up to where you want it on the dash and mark where you want to cut each end. I like the cable to be out of the way so I ran mine in the seams of my seats and under rugs. It is hardly visible but it uses up more cable.
- Cut the short Pmod 6-pin cable in the middle and strip the outer casing back a bit on both halves.
- Strip, twist, and tin each wire on both halves. (you can cut the wires for PWM and Analog signals. If pins 1 and 2 are Vcc and GND respectively pins 3 and 6 would be the ones to cut. Always put the edge of the connector with the three white dots closest to Vcc and you won't plug them in backwards.)
- Repeat steps 1 and 2 for a second Pmod cable if you want to add another sensor.
- Label the first and second cable accordingly to avoid mixing up the left and right sensor later.
- Cut the Cat5e patch cable at the ends where you marked it earlier and clean up the ends by stripping, twisting, and tinning the wires.
- Test that the colors of your Pmod cable match up to mine.
- Set multimeter to beep when the probes are electrically connected
- Write down what order the colors are in starting with the pin closest to the white dots. (Could be on the left or right of the connector)
- If your Pmod colors are in the same order that mine are in you can use the table in image 4 to connect the wires just like I did.
- If yours don't match up to mine write up your own table to make sure you are getting the same pin order on both ends.
- Tin the wires at this point to make soldering easier.
Step 6: Wire Extension
Attach Cat5e wires to the two Pmod cables on the microcontroller end. (images 1-5)
- Cut and slide the 1/4 inch heat shrink tube over the outside of the Cat5e cable.
- Cut and slide the 3/32 inch heat shrink tube over the first wires you will solder.
- Solder the matching wires together.
- Shrink the tubing around the individual wires.
- Repeat steps 2 through 5 with all 8 of the wires. (4 per Pmod 6-pin cable)
- Shrink the 1/4 inch heat shrink tube over the bundle of wires.
Attach Cat5e wires to the two Pmod cables on the sensor end. (images 6-10)
- Strip the Cat5e cable outer sheath enough so half of the wires can reach the left side of your bumper and half can reach the other half. (picture 6)
- Unravel the solid color wires from the white striped wires.
- Braid the solid colors with each other and the white striped wires with each other. This doesn't have to be neat just enough so they don't come undone in your trunk.
- Repeat steps 1 through 6 that you did for the microcontroller end of the cable on the sensor end. Except use two 1/4 inch heat shrink tubes, one around each wire bundle end.
Step 7: Field Testing
Check your setup to see if it works and you haven't crossed any wires. You don't need to do this on your car. The tape holding my sensor gave out and made it point sideways. If I had kept trying this out I might have bumped into the garage door.
Step 8: Velcro Time
- Cut a square of velcro the size of your sensor.
- Place the hook side of the velcro on the car making sure to clean the area first. The fuzzy side will hold onto more water and will likely not last as long on the outside of your car.
- Place the fuzzy side of the velcro on your sensor. Press firmly and it will stick well to the circuit board.
- Repeat steps 1-3 if you have a second sensor. If you're using two sensors place one on either side of your bumper but still facing backwards.
- cut a square of velcro about the size of your battery holder and secure your battery holder with it.
Step 9: Conclusion
If I were to do anything differently it would be to use a chipKIT MX3 instead of the MX4. The MX3 is smaller, which makes making an enclosure easier. I think I'll wait to get an MX3 to make an enclosure that fits my car. I have the perfect space but it's a little awkward. I'll be looking around for a container that fits that space.
This was my first instructable and I had a lot of fun making it. If you have any comments, questions, or how your build went I would love to hear about it so leave a comment down below.