Electronics

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);
}

The Music of The Data Bus

One thing I’m really into is sound. A long time ago, I taught sound design and synthesis at a design college and loved being able to surround myself with everything audio. I still like to explore this area of creativity, but sometimes that can be tough to do. Especially when you are spending your days working in a very analytical mode. So, for this project, I figured “Why not combine the two?” I decided to make something to mash the two hemispheres of my brain together.

After some brainstorming and looking around my office to see what things I was currently working on that might fit, I came upon the idea of listening to the ‘music’ of a data bus. I had just finished designing a modular, CAN-based system and was fairly deeply immersed in the details of the internal communication bus. While watching data packets stream past my eyes for a few hours, I got the idea of listening in on them instead of watching them.

The idea was simple. Create an interface to the bus I just created, listen in on packets as they passed by, and trigger sounds based on the distinguishing features of these packets. I used a Microchip MCU for the brains and an MCP2551 as the CAN transceiver. The unit would listen for CAN packets, parse them, retrieve a certain value within the packet, and then turn around and output MIDI data over the serial output of the microcontroller.

Data Bus packets to MIDI device
Inside the box is a microcontroller that listens to CAN packets coming into the ‘Data Port’ and outputs MIDI note data based on the parsed values.

 

The end result was a fairly periodic recording where one can hear the late arrival of some packets from time to time. Enjoy!

 

Pick a Color… Any Color!

Gotta love Arduino!
Made a quick demo to show PWM intensity control of Red, Green, and Blue LEDs in a rotary encoder using the rotary encoder’s push button for channel selection and a 7 segment display to show the channel.

The rotary encoder in the pictures below contains three LEDS (Red, Green, & Blue).  They have a common cathode and so I tied their anodes each through a resistor to a separate PWM output of an Arduino Uno. This allowed me to adjust intensity of each independently with a value from 0-255. I then read the encoder output and push button state of the encoder (did I mention it has a push-button switch in it too? Yuup!) using a few more Arduino inputs. I used the push button to select which RGB channel the user was modifying and the encoder output to adjust the selected value. I then used a very inexpensive 7 segment display from Sparkfun with a built-in controller that accepts serial comms for control.

RGB Rotary encoder displaying full red color.
RGB Rotary encoder displaying full red color.

RGB Rotary encoder displaying full green value.
RGB Rotary encoder displaying full green value.

RGB Rotary encoder displaying full blue value.
RGB Rotary encoder displaying full blue value.

 

Using all built-in or easily available libraries from Arduino, I was able to have this entire demo functional in about an hour. After I had it functional, I easily spent hours just clicking the push button, selecting RGB channels and changing the mixture of Red, Green, & Blue. This was a simple demonstration meant to explore very minimal user interface options for input and control.

Total time spent making = 1 hour.
Total time spent mixing colors after the fact = too many!

RGB Rotary Encoder displaying PWM-mixed color as selected by user.
RGB Rotary Encoder displaying PWM-mixed color as selected by user.

 

 

 

Controlling a Servo with a Micro-controller and a Pot

In this video, you can see some very early tests I was performing to evaluate a certain servo motor for use in a mission critical application. This is all very serious business. I was turning a potentiometer, reading the position in with a Microchip micro-controller and then controlling the servo to give a roughly 1:1 response. Just wiggling the thing around was very rewarding.