Skip to content

Instantly share code, notes, and snippets.

@getelectronics
Created December 20, 2018 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getelectronics/757a044caeffe167e75037f4e42e884d to your computer and use it in GitHub Desktop.
Save getelectronics/757a044caeffe167e75037f4e42e884d to your computer and use it in GitHub Desktop.
# Needed modules will be imported and configured
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# The input pin which is connected with the sensor
GPIO_PIN = 21
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
print "KY-010 Sensor Test [press ctrl+c to end the test]"
def outputFunction(null):
print("Sensor is blocked")
# signal detection (raising edge).
GPIO.add_event_detect(GPIO_PIN, GPIO.RISING, callback=outputFunction, bouncetime=100)
# Main program loop
try:
while True:
time.sleep(1)
# Scavenging work after the end of the program
except KeyboardInterrupt:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment