Why can't the HC-SR04 sensor detect objects that are very close to it?
If the time is longer than 0.04 then it means that the Pi &quot;missed&quot; the return because it wasn't fast enough to see the rapid return.  It's basically a sanity check because after 0.04s it would mean the return pulse was missed or the object is physically out of range of the sensor.