This circuit demonstrates how to use an HC-SR04 Ultrasonic Range finder to measure the distance to an object.

The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats or dolphins do. Power the module using Vcc, ground it using GND, and use an Arduino digital pin to send an input signal to TRIG, which triggers the sensor to transmit an ultrasonic burst of 8 x 40KHz pulses. The sound waves bounce off any nearby objects and some are reflected back to the sensor.
The ECHO pin will be “LOW” (0V) until the outgoing signal has stopped, at which point it goes HIGH (5v). Once a return pulse has been detected, ECHO is set “LOW” again. So the time for which the ECHO pin is HIGH equals the time taken for the sound wave to travel to the nearest obstacle and back.