Go Down

Topic: ultrasonic sensor accuracy HC-SR04 (Read 1 time) previous topic - next topic

ghokulji

How to achieve an accuracy of .1 mm with an HC-SR04 sensor?
any tips on how to increase the accuracy?

robtillaart

What is the accuracy according to the datasheet?

You can gain some accuracy by oversampling but 0.1 mm is imho impossible.

Sound goes ~340 000 mm per second
 
That means that 0.1 mm extra distance is a time difference of 1/3.400.000 second which is roughly 1/3 -1/4 of a microsecond. 250-300 nano seconds

OK because the distance is traveled twice, it you can double that, to 500-600 nanoseconds. That is between 8-10 clockcylces of an Arduino. You should write your own library that use hardware timers to see that kind of difference in timing. It will be on the edge of what is possible. 0.1 mm will be pretty impressive if you succeed.

Practical problem is that the speed of sound in air changes when
(1) temperature changes
(2) humidity changes
(3) air pressure changes
(4) gas mix changes

Have a detailed read here:
https://www.engineeringtoolbox.com/speed-sound-d_82.html
https://www.engineeringtoolbox.com/air-speed-sound-d_603.html

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

wvmarle

Using interrupts it's quite straightforward to reach that precision. On the ESP8266 I've reached better than 10 ns timing precision using oversampling (on 4-10 ms signals, 12.5 ns clock signal - haven't tried running the processor at 160 MHz as it's good enough for me).

Indeed the big issue is in the system itself, and them mostly the production and detection of the sound waves and changes to the medium (air) they travel through throwing off your accuracy.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

ghokulji

Hey
I am a newbie to this stuff, so can you tell me how do I give interrupts or how should i oversample

wvmarle

Oversampling is basically taking an average of lots of samples.
interrupts explained here.

That said, your accuracy is possible with optical methods, not with ultrasound. Use the appropriate tool for the job - ultrasound is not useful for such accuracies. Optical methods can do this, but of course cost a wee bit more.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up