i am using raspberry pi 3 for vibration sensor with the following code:
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
#GPIO SETUP
channel = 27
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel, GPIO.IN)
def callback(channel):
if GPIO.input(channel):
print ("Movement Detected!")
else:
print ("Movement Detected!")
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)
and produces an error like this:
Traceback (most recent call last):
File “/home/admin/project/project.py”, line 16, in
GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300) # let us know when the pin goes HIGH or LOW
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Failed to add edge detection
how to fixed???
code will be running
New contributor
Fikri Fadli is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.