Learning to measure distances
If you have ever wondered how touchless soap dispensers or touchless blow dryers register that there is a hand beneath them, there is a good chance that they are using the HC-SR04 ultrasonic sensor. We are going to use this sensor to measure the distance between an object and the sensor. Let's begin with the HC-SR04 sensor.
Understanding the HC-SR04 sensor
The HC-SR04 sensor emits an ultrasound at 40k Hz, which travels through the air and bounces back if the emitted pulse collides with any object in its path. The sensor cannot be used as a detector for other ultrasound pulses, as it only registers echoes from the exact same pulse that it itself emitted. Typically, these sensors look similar to the one in the following photograph:
This sensor has the following technical specifications:
- It has a detection range from 2 to 400 centimeters.
- It draws less than 2 mA current...