circuitbasics.com has a new tutorial on how to measure distance using Arduino and an ultrasonic sensor.
Ultrasonic range finders are fun little modules that measure distance. You can use them to find the precise distance to an object, or also just to detect when something is within range of the sensor (like a motion detector). Ultrasonic range finders are ideal for projects involving robotic navigation, object avoidance, and home security. Because they use sound to measure distance, they work just as well in the dark as they do in the light. The ultrasonic range finder we will be using in this tutorial is the HC-SR04. The HC-SR04 can measure distances from 2 cm to 4oo cm with an accuracy of ±3 mm.
How to Set Up an Ultrasonic Range Finder on an Arduino – [Link]