Arduino Forum

Using Arduino => Sensors => Topic started by: ghokulji on Mar 15, 2018, 01:15 pm

Title: ultrasonic sensor accuracy HC-SR04
Post by: ghokulji on Mar 15, 2018, 01:15 pm
How to achieve an accuracy of .1 mm with an HC-SR04 sensor?
any tips on how to increase the accuracy?
Title: Re: ultrasonic sensor accuracy HC-SR04
Post by: robtillaart on Mar 15, 2018, 02:46 pm
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

Title: Re: ultrasonic sensor accuracy HC-SR04
Post by: wvmarle on Mar 15, 2018, 03:26 pm
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.
Title: Re: ultrasonic sensor accuracy HC-SR04
Post by: ghokulji on Mar 15, 2018, 05:16 pm
Hey
I am a newbie to this stuff, so can you tell me how do I give interrupts or how should i oversample
Title: Re: ultrasonic sensor accuracy HC-SR04
Post by: wvmarle on Mar 15, 2018, 05:55 pm
Oversampling is basically taking an average of lots of samples.
interrupts explained here (https://playground.arduino.cc/Code/Interrupts).

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.