Ultrasonic sensors work similar to radar or sonar which evaluate attributes of a target by interpreting the echoes from radio or sound waves. Ultrasonic sensors generate high frequency sound waves and evaluate the echo which is received back by the sensor. Sensors calculate the time interval between sending the signal and receiving the echo to determine the distance to an object.
The technology is limited by the shapes of surfaces and the density or consistency of the material. Since piezoelectric crystals generate a voltage when force is applied to them, the same crystal can be used as an ultrasonic detector. Some systems use separate transmitter and receiver components while others combine both in a single piezoelectric transceiver.
Ultrasonic distance detector from parallax
Please read wiki‘s article on Ultrasonic sensors for more information.