from hcsr import HCSR04
from machine import Pin
from time import sleep
sensor = HCSR04(trigger_pin=6, echo_pin=8, echo_timeout_us=20000)
buz = Pin(13,Pin.OUT)
while True:
distance = sensor.distance_cm()
print("distrance :", distance , "cm")
sleep(0.5)
if distance <= 100 :
buz.value(1)
print("buzzer ring")
sleep(0.5)
else :
buz.value(0)