import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

TRIG = 20
ECHO = 21
print("Distance measurement in progress")

GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)

GPIO.output(TRIG, False)
print("Waiting for sensor to settle")
time.sleep(2)

try:
    while 1:
        GPIO.output(TRIG, True)
        time.sleep(0.00001)
        GPIO.output(TRIG, False)

        while GPIO.input(ECHO) == 0:
            start = time.time()
        while GPIO.input(ECHO) == 1:
            stop = time.time()

        check_time = stop - start
        distance = check_time * 34300 / 2 # 음속(cm/s) * 걸린 시간 / 2
        print(f"Distance : {distance:.1f} cm")
        time.sleep(0.4)

except KeyboardInterrupt:
    print("Measurement stopped by User")
    GPIO.cleanup()

4d638782f1aad001d283f5ea0f608f8d9522289d
<mask token>

<mask token>
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
<mask token>
print('Distance measurement in progress')
GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)
GPIO.output(TRIG, False)
print('Waiting for sensor to settle')
time.sleep(2)
try:
    while 1:
        GPIO.output(TRIG, True)
        time.sleep(1e-05)
        GPIO.output(TRIG, False)
        while GPIO.input(ECHO) == 0:
            start = time.time()
        while GPIO.input(ECHO) == 1:
            stop = time.time()
        check_time = stop - start
        distance = check_time * 34300 / 2
        print(f'Distance : {distance:.1f} cm')
        time.sleep(0.4)
except KeyboardInterrupt:
    print('Measurement stopped by User')
    GPIO.cleanup()

<mask token>
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
TRIG = 20
ECHO = 21
print('Distance measurement in progress')
GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)
GPIO.output(TRIG, False)
print('Waiting for sensor to settle')
time.sleep(2)
try:
    while 1:
        GPIO.output(TRIG, True)
        time.sleep(1e-05)
        GPIO.output(TRIG, False)
        while GPIO.input(ECHO) == 0:
            start = time.time()
        while GPIO.input(ECHO) == 1:
            stop = time.time()
        check_time = stop - start
        distance = check_time * 34300 / 2
        print(f'Distance : {distance:.1f} cm')
        time.sleep(0.4)
except KeyboardInterrupt:
    print('Measurement stopped by User')
    GPIO.cleanup()

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
TRIG = 20
ECHO = 21
print('Distance measurement in progress')
GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)
GPIO.output(TRIG, False)
print('Waiting for sensor to settle')
time.sleep(2)
try:
    while 1:
        GPIO.output(TRIG, True)
        time.sleep(1e-05)
        GPIO.output(TRIG, False)
        while GPIO.input(ECHO) == 0:
            start = time.time()
        while GPIO.input(ECHO) == 1:
            stop = time.time()
        check_time = stop - start
        distance = check_time * 34300 / 2
        print(f'Distance : {distance:.1f} cm')
        time.sleep(0.4)
except KeyboardInterrupt:
    print('Measurement stopped by User')
    GPIO.cleanup()

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

TRIG = 20
ECHO = 21
print("Distance measurement in progress")

GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)

GPIO.output(TRIG, False)
print("Waiting for sensor to settle")
time.sleep(2)

try:
    while 1:
        GPIO.output(TRIG, True)
        time.sleep(0.00001)
        GPIO.output(TRIG, False)

        while GPIO.input(ECHO) == 0:
            start = time.time()
        while GPIO.input(ECHO) == 1:
            stop = time.time()

        check_time = stop - start
        distance = check_time * 34300 / 2 # 음속(cm/s) * 걸린 시간 / 2
        print(f"Distance : {distance:.1f} cm")
        time.sleep(0.4)

except KeyboardInterrupt:
    print("Measurement stopped by User")
    GPIO.cleanup()
