"From Payroll to Body Scanners"
PC Services (Electronics)
Ultrasonic Distance Sensing using HC-SR04
Tel: 0118 946 3634
Introduction Ultrasonic Range Sensing
This section covers mainly the physics of sound waves, to understand the limits of ultrasonics and how to use them, such items as
Other Pages after this one cover
So you have a microprocessor or computer and you are doing a project where you need to measure distances, and you have discovered you need or are using an Ultrasonic distance sensor for this, now what or why is it not working as you expected. So you have found this page amongst your searches to try and see how to do things.
No doubt from you searches and copying of examples you have a setup that is basically like the picture on the right, MCU (or microprocessor or Pi or Arduino or...) connected to an Ultrasonic module with 3 or 4 wires, and want to get this working.
First thing to understand is that the order of events is
This round trip or echo is also known as a PING from submarine and sea depth sensing.
There is more detailed explanation of the signals on the page The circuitry of the HC-SR04
So far so good all seems simple enough, but
STOP AND STEP BACK !!
First of all understand or remember some of the physics of sound waves and the unit otherwise you may not be able to make sense of some of your readings and why it does not always work in every situation.
Things a distance sensor will NOT tell you
Sound waves are pressure waves as in varying air pressure at a point in time, travelling out. For this device the opening of the sender is a defraction opening, so the wave at any one time is actually an arc that spreads out and gets flatter the further away it gets.
As the wave gets wider the energy in the wave is spread further and further and until it is not noticeable. See the diagram below showing the wave sent out and refelected back, consider the lines as the peak of the pulse transmitted.
As you will see by the time the wave is received only a small portion of the original wave gets directed at the receiver, the rest will be reflected again by the unit and anything behind the unit.
More echos will be received back as other parts of the wave hits other parts of the same object get reflected back as well.
How Fast Sound Waves Travel
To use sound waves to measure a distance we need to time the period between sending out a sound wave and receiving the echo (the round trip), to then know how far away we need to first know the speed of sound in air.
The speed of sound is variously quoted as
Realistically these variances are due to estimates, humidity, temperature, air pressure and altitude. Assumes STILL air (no winds).
For the rest of these pages and examples we will use the speed of 343.2 m/s, for your application you may have to adjust for other factors.
To convert time of signal echo to an actual distance we need to divide the time measured by the µs by a divisor in µs/cm. Considering accuracy of the devices and speed of calculations, to get to whole cm accuracy, chose a divisor of 58 should be sufficient and can be borne out by testing stationary objects at known measured distances. This way you can find what is best for you and keep maths to integer operations only.
Basics of HC-SRO4 Ultrasonic Sensor Usage
The HC-SR04 is a cheap Ultrasonic Distance Sensor available all over the price very cheap and fairly reliable, however its accuracy is +/- 3mm. This accuracy means that anything less than 1 cm measurement is at best a guess.
Beware just because you have one reading, sound waves echo around areas so to be sure the next reading is valid, always wait for at least 20 ms before any further readings are taken.
Things to remember about using the HC-SR04 -
The next Pages after this one cover
Interested in something similar contact sales.
|© 2017 onwards by PC Services, Reading UK||Last Updated: 1st February 2017|
|If you encounter problems with this page please email your comments to webmaster|