ok I haven;t played with 1 of these myself but have seen others use them successful to do what you want to do.
This is my understanding of them. Hook Vcc to 5v, GND to GND and out to your pin that you want to detect the sound on.
I believe that when a sound is dectected the sensor will pull the out pin to ground
for my code I choose pin 4 for the input pin for the sound.
Code: Select all
import RPi.GPIO as GPIO
INPUT_WIRE = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(INPUT_WIRE, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
while True:
if GPIO.input(INPUT_WIRE) == GPIO.LOW : print" Sound detected"
the code can be shortened to this
Code: Select all
import RPi.GPIO as GPIO
INPUT_WIRE = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(INPUT_WIRE, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
while True:
if not GPIO.input(INPUT_WIRE) : print" Sound detected"