Raspberry Pi practice problem · Sensors
Lost echoes
MediumBudget $7Python · gpiozero
An HC-SR04 (TRIG GPIO23, ECHO GPIO24 through a divider, or the 3.3 V-safe module) aimed at a soft, angled target: about a third of the pings never come back. gpiozero reports a lost echo as max_distance (1 m by default), as if nothing were there.
Every 0.5 s print the distance in whole centimetres (40 cm), but never print a wrong value: drop lost echoes, filter them out, or repeat the last good reading. The target is at 40 cm, then moves to 25 cm at 4 s.
Tip: gpiozero's own queue_len keeps a median of recent readings — or check each reading yourself.