from machine import Pin, time_pulse_us
from time import sleep_us, sleep
trigger=Pin(27, Pin.OUT)
echo=Pin(26, Pin.IN)
while True:
#Send a 10 microsecond pulse to trigger pin
trigger.high()
sleep_us(10)
trigger.low()
#Measure the duration of the echo pulse (in microseconds)
pulse_duration=time_pulse_us(echo, Pin.high)
#Calculate the distance (in centimeters) using the speed of sound (343 m/s)
distance=pulse_duration * 0.0343 / 2
print("Distance:", distance, "cm")
sleep(1)