I'm working on making a Doorbell powered by a raspberry pi,
I connected the existing wires from the button to the raspberry pi at GPIO pin 18 and the Ground Pin. I'm using the following while true loop to detect the button press.
GPIO.setmode(GPIO.BCM)
GPIO.setup(Relay_Ch1,GPIO.OUT) #Relay Ch1
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Detect Bell Press
while True:
input_state = GPIO.input(18)
if input_state == False:
print('Bell Pressed')
# Start Buzzer
GPIO.output(Relay_Ch1, GPIO.LOW)
print('Relay Opened')
# Play Sound trough Sonos HTTP API
GET(sonos, async=True, resp=True)
print('Sonos API Send')
# POST with form-encoded data
POST(push, params=payload, async=True, resp=True)
print('Push Request send')
time.sleep(3)
# Stop Buzzer
GPIO.output(Relay_Ch1, GPIO.HIGH)
time.sleep(2)
This is working great, except whenever I put a load on the power circuit where the raspberry pi power adapter is plugged in, it will for some reason trigger the script.
Would it be better to connect one of the wires to the 3.3v and the other to a GPIO pin, and then check if it's high, instead of pulling it to ground?