from machine import Pin
from hcsr04 import HCSR04
from time import sleep
meter = HCSR04 (trigger_Pin = 4, echo_Pin = 5)
led = Pin (2, Pin.OUT)
while (True):
try:
distance = meter.distance_cm()
print("Distance = ",distance, "cm" )
if distance >= 20:
led.value(1)
print("movement detected")
else:
led.value(0)
print("no movement detected")
sleep(1)
except:
print("Error")