The HC-SR04 is an Ultrasonic ranging module. It provides 2cm - 400cm non-contact measurement function, the ranging accuracy can reach to 3mm. The module includes the ultrasonic transmitter, receiver and control circuit.

The basic principle is:
(1) Using IO TRIG Pin, trigger for at least 10us high level signal ,
(2) The Module automatically sends eight 40 kHz and detect whether there is a return signal.
(3) If the ultrasonic signal returns, the time elapsed is used to compute distance, knowing the sound speed in air: Test distance = (high level time×velocity of sound (340M/S) / 2
Datasheet: available here.

Circuit diagram:

Here are some variants created by my readers

Glide built a nice PCB for this sonar. Here are his pics and the eagle files (SCH+PCB)
sonar merge 001 sonar merge 002 sonar merge 003
glide sonar eagle

Source code:
Sonar HC_SR04
Thanks to wzona. It comes with excellent details, make sure you check it out.

A few pics with the sonar used with a 5110 Nokia graphical LCD. Code for the LCD available here.
5110_lcd_1 5110_lcd_2

Related Post