Ultrasonic Sensor (HC-SR04) + Arduino
The HC-SR04 ultrasonic distance sensor uses sonar to determine distance to an object with stable readings and high accuracy of 3mm. The module includes ultrasonic transmitter, receiver and control circuit. In order to generate the ultrasound, you have to set the trig on high state for 10 microseconds. The trig pin will send out the sonic burst which travels at the speed of sound. The soundwave will be bounced back once it interacts with a solid or liquid and will then be received in the echo pin. The distance between the sensor and the object will be calculated using the time of travel. More explanations of work principles are outlined here if interested. One of the outstanding features of this distance sensor is that it can detect not only the distance between itself to a solid object, it can also detect liquids (used in the Cheers group).
There are four pins on the HC-SR04 Ultrasonic distance sensor:
- Vcc: power.
- Trig: sends out the sonic burst, connected to pin 10.
- Echo: receive the returned soundwave, connected to pin 13.
- GND: ground.