Ultrasonic Ranging

I've been playing around with ultrasonic sensors a lot. But up to now that was just using ultrasonic sensors from old remote control systems.
I finally decided to buy a 'real' ultrasonic ranging module. TinyTronics, one of my favorite suppliers, sells the HC-SR04 module. This is a cheap sensor that might be useful for some near-distance ranging to prevent bumping into furniture on a robot I like to build.

Using the module

I found some sort of a specification of this module at electroschematics.com.

A pulse with a minimum width of 10μs triggers the module to send a series of 8 ultrasonic pulses. A positive pulse on the echo output of the module then gives the time it takes for the module to receive the echo of these pulses.
Sound travels with 343.2 m/s (in dry air at 20°C) or 29.1μs/cm so all that is needed to calculate the distance is to divide the given time by 58 (2 * 29) to get the actual distance. In our warm, humid, climate a value of 57 is a more accurate value to use.


I tested the sensor with a 20μs pulse.
The image on the right shows the signals with my Logic Analyzer. The echo output of the sensor gives a positive signal (seen from cursor C to D) of 1842μs. 1842/57 = 32.3 cm which is about the value expected. Another test (pointing at the ceiling) resulted in a pulse of 8972μs which is 157.4cm and indeed; my tape measure shows the same distance.
Some more results are: 238μs (4cm) with some plastic packaging, 547μs (9cm) with a piece of paper and 361μs (6cm) with my foam laptop sleeve.

These are all larger targets, what about smaller targets?
An AA size battery is only detected at a range closer than 30cm but the measured distance is longer than the actual distance. Measurements are only accurate when the AA battery is < 10cm from the sensor.
Still very nice for a sensor in this price range and enough for my goal.

3v3 compatibility?

I tested the sensor with one of my LPCXpresso boards, these deliver 3.3V output and the sensor seems to work very well with this.

Do note however that the sensor does deliver a 5V output signal so you cannot connect this sensor directly to a target not accepting 5V inputs (so do not connect this directly to a Reapberry Pi!).