Ultrasonic sensor comparison part 2

September 07, 2014

In my previous post, I posted some comparisons of some expensive $30 ultrasonic sensors (the Parallax Ping and the RadioShack Range Finder) and some cheap HC-SR04 sensors. I came to the conclusion that the HC-SR04 sensors were not as accurate but it turns out my testing approach was deeply flawed and my results and conclusions were completely incorrect.

These tests had me confused for a while. I set up a test where I would have two sensors side by side on a breadboard and I would take a reading from sensor 1 (a RadioShack module) and then a reading from sensor 2 (an HC-SR04 module) and then show the results. The test repeated once every 1 second.

With an icstation HC-SR04, I saw identical results (around 145 cm) from both sensors when pointing them at the ceiling in my office. However, when repeating the test with an iTEAD Studio HC-SR04 sensor, the HC-SR04 was always reporting a reading around 100 cm instead of 145 cm. This was very consistent. Based on this, I assumed that each sensor varied in its accuracy, so I decided to do a more formal test of each of the sensors I had available, so I tested each sensor individual for distances ranging from 1" to 60" and put the results in a table:

ACTUALDistance HC-SR04(icstation) HC-SR04(iTEAD Studio) HC-SR04(Unbranded) RadioShack  ParallaxPing
1 0.9 1.2 1.1 1.0 1.3
2 1.9 2.1 2.0 1.9 2.1
3 3.1 3.4 2.9 3.0 3.1
4 4.2 4.2 3.9 4.1 4.2
5 5.0 5.4 5.0 5.0 5.4
6 6.0 6.3 5.9 6.0 6.4
9 8.8 8.9 8.8 8.9 9.3
12 11.7 12.0 11.8 11.9 12.0
24 23.5 23.8 23.6 23.9 23.9
36 35.2 35.6 35.4 35.5 35.8
48 47.4 47.6 47.5 47.7 48.0
60 59.3 59.5 60.0 59.7 59.6

As you can see from this test, the results are actually very similar with all sensors and doesn't reflect what I saw in my side-by-side comparison. At this point I realized that the issue was most likely interference between the sensors, maybe in the form of echoed sound, so I repeated my original test and added a delay between taking readings with the two sensors. Suddenly the two sensors were now giving near identical results.

Some sensors were more sensitive than others, but adding a delay meant I could get the same readings from any of these sensors. In this particular test, the minimum delay between readings that gave consistent results was 15 milliseconds. This resulted in 42 readings per second with the iTEAD Studio sensor compared to 131 readings per second with the icstation one, which didn't need a delay at all. Even the high end Parallax Ping sensor required a delay between readings to get accurate results.

In my previous tests I had always taken a reading from an expensive sensor first and then immediately taken a reading from the cheap one before waiting one second before repeating the test. This meant I was never seeing interference with the expensive sensors and I had skewed the test results.

So my new conclusion is that these cheap HC-SR04 sensors are every bit as good as the $30 versions I had previously been using. The RadioShack module even appears to use the same schematic as the HC-SR04 except for the fact that it has 3 pins instead of 4. Is RadioShack really manufacturing these modules for $1 and selling them for a 30 x multiple of that cost? That is a pretty shocking markup.

I will be placing another order direct with China this week for more of these sensors for sure.