NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7

levak:
Hello!

I noticed SR06 sensor has a temperature sensor on the board as well, which can be used for temperature compensation.
Are those measurements more accurate?
How much more? Let's say I have a sensor without temperature compensation and I set my code to 20°, but ambient temperature is 30°C. How big of a deviation would I see?

Matej

The formula for the speed of sound is: m/s = 331.3 + (0.606 x C°)

So, at 20°, the speed of sound is 343.42 m/s and at 30° it's 349.48.

Towards the extreme edge of the sensor range, lets say you get a ping time of 29,000 ms. That would give you:

29,000 ms / 10,000 x 343.42 m/s / 2 = 497.96 cm
29,000 ms / 10,000 x 349.48 m/s / 2 = 506.75 cm

So, temperature does make a difference, in this example, almost 9cm. Likewise, at 100cm, the difference would still be about 1.75 cm, so still sizable.

With this said, it's typically not an issue. Because for normal uses, the sensor is not being used to measure an exact distance, but instead to see if something is approaching or too close relative to a previous ping. However, if you're using the sensor to measure an exact distance (say a water level) and you must get very precise distance results over a long period of time at various temperatures, then using a thermostat and doing the above calculation would be very important. All depends on your need. NewPing is designed to work easily with the built-in ping_cm() method, or you can roll your own with ping().

Tim