from hcsr04 import HCSR04
from time import sleep
sensor = HCSR04(
trigger_pin=5,
echo_pin=18,
echo_timeout_us=30000
)
while True:
try:
distance = sensor.distance_cm()
print('Distance:', distance, 'cm')
except OSError as e:
print('Out of range')
sleep(1)