I'm working on a project that uses SW-420 sensors to detect vibrations. I was originally following this tutorial and my code is pasted below. I used a previous post to determine that I should be using the 3.3V pin instead of 5V, so I swapped that. In every tutorial I've seen, both lights on the sensor have worked, but regardless of what GPIO pin I use, the DO-LED doesn't work. (Not sure if that's relevant.)
If I run the code, it will tell me that a vibration has been detected only if I remove and replace the DO cable (using GPIO 27/pin 13) from the pi--but the sensor doesn't register taps/shakes/hard knocks.
Does anybody know what I'm doing wrong? Pic of offending Pi unit
#!/usr/bin/python import RPi.GPIO as GPIO import time channel = 27 GPIO.setmode(GPIO.BCM) GPIO.setup(channel, GPIO.IN) def callback(channel): if GPIO.input(channel): print("Collision Detected!") else: print("Collision Detected!") GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300) GPIO.add_event_callback(channel, callback) while True: time.sleep(1)