Building a Sonar System
and that’s all we’ll say about the circuit shown in Schematic
1. After all, we’re only interested in putting the EZ0 to work.
All of the ultrasonic engineering has been done for us
by the MaxBotix engineers. All we really have to do to bring
the EZ0 online is to apply some power and follow some
very simple operational rules. The LV-MaxSonar series of
ultrasonic rangefinders can be powered by voltages as low
as 2.5 volts and as high as 5. 5 volts. This power rail range
allows the LV-MaxSonar ultrasonic rangefinder family to
work with 3. 3 volt systems, which are gaining popularity
due to their lower power consumption characteristics.
These ultrasonic rangefinders draw approximately 3.0
ma of current when powered by a 5.0 volt power source.
When powered by 3.0 volts, the rangefinders draw only
2.0 ma of current. That kind of current consumption allows
the LV-MaxSonar ultrasonic rangefinders to easily operate in
battery powered mobile systems.
As you can see in Schematic 1, the EZ0 (and all of
the other LV-MaxSonar ultrasonic rangefinders) interfaces
to the outside world with five I/O lines and two power
connections. A physical look at the EZ0 interface can
be seen in Photo 2. Let’s walk through each line of the
Pin 1 is labeled “BW.” This pin is used when multiple
ultrasonic rangefinders need to be triggered. If triggering
multiple rangefinders is not part of your application, you
must tie the BW pin low or leave it open. Otherwise,
holding the BW pin logically high will force the EZ0’s TX pin
to produce a pulse instead of serial data. The pulse is used
to trigger other ultrasonic rangefinders in the rangefinder
network. An initial seed pulse to the RX pin of the first
LV-MaxSonar ultrasonic rangefinder in the chain is all that’s
needed to fire off the rest of the ultrasonic rangefinders
behind it in the chain.
“PW” marks pin 2 of the I/O interface. When the EZ0 is
ranging, the PW pin will emit a pulse that is relative to the
distance to the target object. The ranging pulse is defined
as 147 μs per inch.
If measuring pulse widths is not something your host
microcontroller will do easily, you can opt to receive your
ranging information from the EZ0’s AN pin. However, your
microcontroller will need to have an on-chip analog-to-digital (A-to-D) converter subsystem to capture the AN
pin’s output. As you’ve probably deduced, the AN I/O pin
provides an analog voltage that is relative to the distance
to the target object. The distance is calculated as Vcc/512
volts per inch. Doing the math, we can count on 9.7656
mV per inch from the AN pin. The Vcc/512 ratio works
will with 10-bit A-to-D converters.
When the 10-bit A-to-D reference voltage is set to
+ 5. 12 volts, each A-to-D step (not including zero) is 4.8828
mV, which happens to be half of the EZ0’s volts-per-inch
figure of 9.7656 mV. If we put my HP-15C to work on the
3. 3 volt A-to-D figures, we come up with 6.4453 mV per
inch. The 3. 3 volt ratio is not as pretty as the 5. 12 volt
ratio, but if that’s what you have to run, you run it and
work with the hand you’re dealt. The LV-MaxSonar-EZ0 will
44 SERVO 06.2008
supply precise A-to-D voltages. Your microcontroller must
be able to handle the 3. 3 volt A-to-D information accurately.
The AN output voltages are buffered and represent the
most recent ranging data.
You already have a clue as to the operation of the
LV-MaxSonar-EZ0’s RX pin. Recall that a pulse applied
to the RX pin of a chained ultrasonic rangefinder will
trigger a ranging operation. The RX pin is pulled logically
high. In single ultrasonic rangefinder designs, ranging
operations will be continuous if the RX pin is left open.
The RX pin can also be held logically high if your host
microcontroller needs to control the ranging process.
Otherwise, if the EZ0’s ultrasonic rangefinder RX pin is
pulled logically low, ranging will cease. A low-to-high
logical pulse with a duration of 20 μs or greater will trigger
a ranging operation.
The EZ0 TX pin is very interesting. As long as the
LV-MaxSonar-EZ0’s BW pin is open or held low, the TX pin
spouts asynchronous serial data in RS-232 format. Recall
that when the BW pin is forced to a logical high, the TX pin
will revert to sending pulses instead of RS-232 ranging data.
Although the TX pin issues data in RS-232 format at zero-to-Vcc levels, you can hang the EZ0’s TX pin on your laptop’s
serial port interface. The signal levels at the TX pin are logic
levels and don’t adhere to true positive and negative RS-232
voltage levels. So, to be politically correct, you’ll need an
RS-232 converter circuit or IC to interface the EZ0’s TX
signal to a true RS-232 port. You can take your chances
with a direct interface between a PC serial port and the TX
pin as long as you never connect the serial port’s TX pin to
the LV-MaxSonar-EZ0 I/O interface. As long as you’re
pushing properly polarized data into the PC’s RX pin,
there’s a chance the serial interface will actually interpret
the zero-to-Vcc logic transitions as if they were RS-232
signals. My Lenovo laptop has no problems with the
LV-MaxSonar-EZ0 serial interface.
Once you’ve decided how to connect the EZ0’s TX pin,
your firmware should expect to see an ASCII “R” with three
ASCII character digits following. The three ASCII digits will
be your ranging data in inches. The maximum value of the
ranging data will be 255 inches. A carriage return character
(ASCII 13 or 0x0D) denotes the end of the ranging data
stream. Speeds and feeds for the TX I/O pin’s serial data
are standard: 9600 bps, eight data bits, no parity, and one
All of the methods of obtaining ranging data from
the EZ0 can be used simultaneously. All we need to do is
provide the necessary microcontroller interface to capture
the ranging data from our desired ranging data portal.
However, before we can start writing our I/O interface
code, we need to understand the LV-MaxSonar-EZ0’s timing
and power-up specifications.
The LV-MaxSonar-EZ0 needs 250 ms of idle time
following power-up. After the 250 ms have passed, the EZ0