Skip to content

Instantly share code, notes, and snippets.

@chainhead
Created September 10, 2021 15:23
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 chainhead/1cc7b20a6e825d682a8a22d72ce3169a to your computer and use it in GitHub Desktop.
Save chainhead/1cc7b20a6e825d682a8a22d72ce3169a to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
#GPIO SETUP
channel = 21
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel, GPIO.IN)
def moisture_detect(channel):
if GPIO.input(channel):
print "No moisture detected"
else:
print "Moisture Detected!"
GPIO.add_event_detect(channel, GPIO.BOTH, callback=moisture_detect)
# infinite loop
while True:
print "loop"
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment