Errors in hc-sr04 sensor readings

The HC-SR04 does occasionally return erroneous values. One way to accommodate that is to take a number of readings, say 5 or more, and use the median value. The NewPing library has a median "method" that makes this very simple.