In this tutorial Techrm from Instructables presents a different use of the HC-SR04 ultrasonic module. This module is often used on robots and toy cars to locate obstacles but it can be used to measure distances as well.
The maximum range of HC-SR04 is 4 meters, and the shortest measurable distance is 2cm with an accuracy of 3mm. We made a piezoelectric speaker ring when the distance meters goes out of reach. Distances measured by the HC-SR04 will be shown on our beloved LCD 16×2 display.
Other two things are required if you want your distance meter to do more accurate measurements:
- A spirit level
- A laser pointer
Unfortunately, while making tests we discovered this device can’t be powered by a 9V battery because of a lack of energy (in terms of supplied Ampere). So, you have to supply your distance meter by using a computer or an AC adapter (yes, it’s not handy at all, but this is just an experiment!)
- Arduino UNO
- USB cable
- The Arduino IDE installed on your PC
- Set of Dupont cables
- MB-102 breadboard
- An HC-SR04 ultrasonic sensor
- LCD 16×2 display
- 10k Ohm linear potentiometer
- 2N3904 transistor (or a 2N2222)
- Number 2 10k Ohm resistor (1/4 Watt)
- Piezoelectric buzzer
How does it works?
The system transmits a burst of ultrasonic sound waves towards the subject and then receives the corresponding echo. According to the reflection time, Arduino calculates the distance thanks to the following formula:
Test distance = (high level time × speed of sound*) / 2
Read more here at Instructables.