The usecase of my project is when I hear the sound of clap then only the relay channel should get triggered. But in my case, the GPIO.input(SOUND_INPUT_PIN)
is only giving me value 1(HIGH). The connection seems correct, though. Below is the configuration of my pi, relay and small sound sensor.
pin 2(5v) -> vcc of relay
pin 6(gnd) -> gnd of relay
pin 7(gpio) -> IN1 of relay
pin 4(5v) -> vcc of sound sensor
pin 14(gnd) -> gnd of sound sensor
pin 11(gpio) -> DO of sound sensor
Here is my code
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
# telling pi we are not using the pin but BCM standard GPIO names for the pins
GPIO.setmode(GPIO.BCM)
BULB_OUTPUT_PIN = 4
SOUND_INPUT_PIN = 17
# as I am refering to the BCM mode instead of BOARD mode so the output pin is
# GPIO4 which is 7th pin in the pi when starting the first pin from left.
GPIO.setup(BULB_OUTPUT_PIN, GPIO.OUT)
GPIO.output(BULB_OUTPUT_PIN, GPIO.HIGH)
# for sound sensor
GPIO.setup(SOUND_INPUT_PIN, GPIO.IN)
SleepTime = 6
# main loop
try:
while 1:
print('#######GPIO INPUT PIN##### ', GPIO.input(SOUND_INPUT_PIN))
if GPIO.input(SOUND_INPUT_PIN) == GPIO.LOW:
print("##########Sound is sensed############")
time.sleep(SleepTime)
GPIO.output(BULB_OUTPUT_PIN, GPIO.LOW)
print("#Relay is triggered in the switch 1########")
time.sleep(SleepTime)
GPIO.cleanup()
print("Good bye!")
# End program cleanly with keyboard
except KeyboardInterrupt:
print("Quit")
# Reset GPIO settings
GPIO.cleanup()
UPDATE
.