Skip to content

Instantly share code, notes, and snippets.

@ikizoglu
Created February 6, 2026 16:09
Show Gist options
  • Select an option

  • Save ikizoglu/0d51a9e255d1c90b692853561503f19a to your computer and use it in GitHub Desktop.

Select an option

Save ikizoglu/0d51a9e255d1c90b692853561503f19a to your computer and use it in GitHub Desktop.
#RaspberryPi Mesafe Sensörü Kullanımı
#RaspberryPi Mesafe Sensörü Kullanımı
#------------------------------------
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BCM) # Use physical pin numbering
TRIG = 18 #GPIO18
ECHO = 23 #GPIO23
print("Distance Measurement")
GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)
GPIO.output(TRIG, False)
print("Waiting for sensor")
time.sleep(2)
while True:
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG,False)
while GPIO.input(ECHO) == 0:
pulse_start = time.time()
while GPIO.input(ECHO) == 1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = pulse_duration * 17150
distance = round(distance, 2)
print("Distance:", distance, "cm")
time.sleep(1)
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment