from machine import Pin
from hcsr04 import hcsr04
sensor = HCSR04(trigger_pin = 4, echo_pin = 5)
led = Pin(2,Pin.OUT)
while True:
distance = sensor.distance_cm()
if distance < 20:
led.on()
else:
led.off()from machine import Pin
from hcsr04 import hcsr04
sensor = HCSR04(trigger_pin = 4, echo_pin = 5)
led = Pin(2,Pin.OUT)
while True:
distance = sensor.distance_cm()
if distance < 20:
led.on()
else:
led.off()