If you've been searching for distance measurement and object detection sensors at a rock-bottom price, look no further! This legendary HC-SR04 ultrasonic sensor is your perfect choice. It offers excellent range accuracy and fairly stable readings at a very low cost. It requires two digital I/O pins (an output pin and an input pin) to interface with it.
An ultrasonic sensor is created based on the principle of echolocation used by animals like bats and dolphins. Since the ultrasonic sensor uses sonar to determine the distance to an object, its operation is not affected by sunlight, spotlight, and object's surface color which will affect the readings of any infrared distance sensors. However acoustically soft materials such as clothes can be difficult to detect.