
Figure 1. My Maxbotix LV EZ4 ultrasonic range finder
After some encouragement, I realized this could still be a learning experience and a fun project even if I do end up spending more time and money than it would take to buy something off the shelf. This entry is really just to show off some of the cool things this sensor can do and how to interpret its outputs. In addition, I will look at a few different configuration options you have when working with these sensors.
These Maxbotix sensors give you three options to read their outputs: analog, serial, and pulse width. The analog is probably the most popular and the simplest to understand. It is also the output I have chosen to start with in my design. The analog output works by increasing the output voltage of the sensor the farther away an object is from its position. Maxbotix specs this relationship at 9.8mV/inch with a minimum distance of 6 inches and a maximum distance of 254 inches (yes we are working in SI units here). That means that the sensor’s output voltage will increase by 9.8mV every time the object you are tracking moves an inch farther away.
The serial output uses the basic transmit (TX) and receive (RX) communication standard and the appropriate COM port on your computer. I am less familiar with this operation, but all you really need to know that it is possible to communicate with the sensor using a serial port hence you are transmitting a digital value, which is typically less noisy and more accurate.
Lastly, the pulse width output uses low frequency pulses to monitor the object’s distance. The farther away the object is from sensor, the wider the pulse width and vice versa. Figure 2 below is published on MaxBotix’s website and it shows the difference between the analog pin output and the pulse width output.
My plan right now is to use a microcontroller to digitally sample the analog output and use the samples to track how close the car is to the ideal spot – meaning I will need to calibrate the sensor to the perfect spot. As the car gets closer I will write a function that controls the weights of red, green, and blue in an RGB piranha superflux LED. Right now I am still debating on whether to fade the LED between the traffic light colors or use discrete color states like a real traffic light. I will probably experiment with both and figure out which I like best, but reader input is always welcome.
Before I get ahead of myself, first thing is first: I need to make sure the sensor works. To make things simple, I built up a quick “acquisition” system using the ultrasonic sensor, my oscilloscope, and a little excel magic (and by magic I mean making a graph). Figure 3 shows the rig I built for testing. You can find my connection diagram at the end of this entry.
Figure 3. Testing rig for rangefinder
By setting my oscilloscope’s time base to 2.5 seconds/division I automatically put it into roll mode, which means that it slowly tracked the sensors response in nearly real time since it is a digital store oscilloscope (DSO). As you can see in Figure 4, the only problem is that the oscilloscope tracks the output voltage and not the distance.
Figure 4. Oscilloscope readout of rangefinder's analog output voltage
Luckily, my scope can output the samples it uses to construct the waveform in a .CSV file, making it easy to process in excel. Using the 9.8mV/inch spec I was able to convert the recorded measurements into distance. Lastly, I time shifted the scope’s output for causality’s sake. You can see the result in Figure 5 below, though it is mostly a sample of me waving my hands in the front of the sensor and moving them back and forth...hence the sine waves. You may also notice that there are high frequency spikes in the middle of otherwise naturally following waveforms. These are an area of concern for me and right now I am thinking I may need to design either a filter in hardware or using some sort of averaging of the samples in the software to correct the issue.
Figure 5. Oscilloscope output translated into distance data via Microsoft Excel
I did a few more tests using walls as my detection sources and I have to say I am really impressed with the accuracy of the sensor. I tested the measurements I was getting from the sensor against some hand measurements made with a tape measure and they were virtually spot on.
Figure 6. Oscilloscope acquisition connection diagram
