Ultrasonic ranging has a number of applications and advantages compared to alternatives such as infrared. Two specific applications of current interest include being used as a 'trip wire' for security alarm scenario and for measuring the height of water within a tank.
The output 'beam' from ultrasonic transmitters is generally restricted to a relatively narrow beam (the specification for the HC-SR04 is 15o). In comparison passive infrared sensors (by which I mean the PIR detector with a suitable lens etc) have detection angles of 90o or more. This enables an ultrasonic beam to be used analagous to a 'trip wire' in an alarm system. This would be advantageous in a situation such as a doorway or walking path, with the sensor set ~1m above and parallel to the ground, which would be 'tripped' by a person walking through the beam, but not be set off by pet dogs/cats for example.
Another situation potentially advantageous for ultrasonic ranging is determining the height of water within a tank or other container. The ultrasonic sound waves are reflected from a water surface, so this enables a non-contact method of measuring a water level. This avoids the necessity of having a probe in contact with the water and the resultant corrosion.
Ultrasonic transducers can be purchased relatively cheaply, but then require the necessary circuitry for excitation of the transmission, and a receiver with the necessary amplification and discrimination. Alternatively the HC-SR04 provides within a single breakout board a ultrasonic transmitter, receiver and control circuit, all for the cost of a few dollars (via ebay).
A number of HC-SR04 were purchased to evaluate against the publicised specifications and to test applicability for use as a water level measuring device and 'trip wire' in a potential security alarm. Some bench testing was performed to determine the performance of the HC-SR04 in terms of range, measuring angle, sensitivity and accuracy. This testing and evaluation was done using PIC18F248 microcontroller.
In many situations, a smaller, less expensive microcontroller such as the ATtiny85 is adequate (which if purchased as a 'module' in the form of a Digispark board or similar, as the further advantage of having onboard voltage regulator, a USB style connector on the PCB, etc). This project demonstrates interfacing the ATtiny85/Digispark with the HC-SR04 Ultrasonic Sensor, producing a circuit and firmware that enables distance readings in centimetres to be reported to a PC connected via RS232-USB.