SCHEMATIC:
Python Code:
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
#GPIO SETUP
channel = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel, GPIO.IN)
def callback(channel):
if GPIO.input(channel):
print "Gerakan Terdeteksi!"
else:
print "Gerakan Terdeteksi!"
GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300) # let us know when the pin goes HIGH or LOW
GPIO.add_event_callback(channel, callback) # assign function to GPIO PIN, Run function on change
# infinite loop
while True:
time.sleep(1)
reff : http://www.piddlerintheroot.com/vibration-sensor/
Tidak ada komentar:
Posting Komentar