Close

Code update - improved out-of-range handling

A project log for HC-SR04 I2C Octopus "octosonar"

Connect up to 16 ultrasonic range sensors to an Arduino with I2C bus and one pin

alastair-youngAlastair Young 03/14/2017 at 06:360 Comments

Many thanks to @jlmyra for spotting an odd behavior with handling out-of-range incidents with sensors that hold the echo high for longer than the datasheet 37ms. This seems to be common - some of the ones I have hold it up for 200ms. I wasn't able to test this originally as I did not have a logic analyzer.

The software now pauses the loop until the interrupt pin goes low and when an OOR occurs it will retain the previous value one time before dropping to zero on the next pass. You can increase the ignore count for noisy environments.

There is also a significant part of the HC-SR04 supply that actually locks up indefinitely in an OOR situation. I'm calling these the "not good" ones. There is a very old thread about this here, and I have some of these "not good" ones which are subtly different from some "good" ones out there.

Note the lower component count and thinner silk screen. I got my "not good" ones from Banggood. Because these "not good" ones will pull the echo pin high permanently this fault will interfere with all sensors on the Octosonar. My original development units are a different board layout altogether and do not have this problem.

A workaround seems to be to add an LED and resistor in series between echo and ground on each sensor. I'm still experimenting with this to find component values that provide a consistent result. When I do I'll work that into future versions of the board.

Discussions