from machine import Pin
import utime
Trig=Pin(3,Pin.OUT)
Echo=Pin(2,Pin.IN)
def ultra():
Trig.low()
utime.sleep_us(2)
Trig.high()
utime.sleep_us(5)
Trig.low()
while Echo.value() == 0:
signal_off = utime.ticks_us()
while Echo.value() == 1:
signal_on = utime.ticks_us()
timepassed = signal_on - signal_off
distance = (timepassed * 0.034)/2
print("The distance form object is ", distance, "cm")
while True:
ultra()
utime.sleep(1)