Choose an HC-SR04 timeout from a distance budget
At about 343 m/s, sound travels roughly 0.0343 cm per microsecond.
0 of 3 complete · Progress saved on this device
Work out the example
At about 343 m/s, sound travels roughly 0.0343 cm per microsecond. A 100 cm target requires a 200 cm round trip, or about 5,831 μs. A roughly 7 ms timeout adds headroom for this example.
Decide what to check next
A zero pulseIn result means no complete pulse arrived within its allowed wait. Keep that result out of any distance average and leave a suitable interval between triggers. Physical temperature and sensor behavior can change results.
Compare with the serial result
The sketch prints 5830 as a truncated timing estimate from constants.
Open the exact Uno example
The sketch prints 5830 as a truncated timing estimate from constants.
void setup() {
Serial.begin(9600);
const uint32_t roundTripCm=200;
Serial.println(roundTripCm * 10000UL / 343);
}
void loop() {}Verified with [email protected] on Uno R3 (2026-12-05 UTC). This check did not use physical hardware.