Skip to content

Instantly share code, notes, and snippets.

@Kalimaha
Created April 20, 2018 08:15
Show Gist options
  • Select an option

  • Save Kalimaha/f472e31a4ab1e0d307e229c086c5a4cd to your computer and use it in GitHub Desktop.

Select an option

Save Kalimaha/f472e31a4ab1e0d307e229c086c5a4cd to your computer and use it in GitHub Desktop.
obstacle detection sensor
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO_PIN = 24
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down = GPIO.PUD_UP)
delayTime = 0.5
print "Sensor-Test [press ctrl+c to end]"
try:
while True:
if GPIO.input(GPIO_PIN) == True:
print "No obstacle"
else:
print "Obstacle detected"
time.sleep(delayTime)
except KeyboardInterrupt:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment