1

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?

1
  • 2
    Why not just try it? Commented Jul 15, 2017 at 2:14

2 Answers 2

0

First, it sounds like you might be overloading your supply power circuit. (I assume you are using a wall outlet.) If that is the case, you need to address the root cause of the power supply fluctuations.

Second, what is the quality of the power adapter you are using for the RPi? Is it rated at 2 amps or more? Also, what else do you have plugged into the RPi that is drawing current?

Third, instead of changing the pins around, I would add a larger pull up resistor to reduce the current drawn by the button.

Finally, depending on the length of the transient power fluctuations induced by the external load, you could try modifying the if statement to require a period of time for the button signal to be low. The theory is that a human pressing the button will hold the signal low longer than the signal generated by the external load. This solution ignores the safety issue of resolving the source of the transient power fluctuations.

4
  • It's on a dedicated 20Amp 230v circuit, with only power adapters for my home network cabinet, which pulls a max of 600 watts. So that should not be the issue. I'm using a 5V 2.4A Adafruit power supply, and I have a Relay hat plugged into the raspberry pi aswel. Commented Jul 15, 2017 at 16:55
  • 20 amps should be more than sufficient as well as the Adafruit power supply. Based on the info you provided, I would try to filter out the transient triggers b6 programmatically requiring a certain amount of time for the switch signal to be in the low state. Commented Jul 15, 2017 at 21:37
  • The only other suggestion I have is to try using the Gpiozero library. It has some very easy to use button functions which may be tolerant of the transient triggers. Commented Jul 15, 2017 at 21:39
  • I went the route of checking if it has been pressed for 0.1 sec. And that seemed to have solved my issue. Commented Jul 22, 2017 at 10:16
-1

You don't mention having a pullup or pulldown resistor in your circuit. (Daddy the Runner) mentions it, but has other solutions as well. I have several pi's with buttons and door alarm sensors. As long as I have the pullups the inputs don't float (float is where the Pi sees various voltages based on electrical noise). This site shows some circuits: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/

So, your Pi will read the GPIO and with the pullup it will see positive 3.3 v until the button is pressed. When the button is pressed, it grounds (through the resistor so no power short) and the GPIO now sees 0 v.

You can solder the resistors into the wire junction and secure with electrical tape and don't need a circuit board. Good luck!

2
  • 1
    The third line of his code sets up the internal p/u resistor. Commented Jul 16, 2017 at 4:03
  • You are correct re the internal pull-up, however often that internal alone isn't sufficient once a switch is added. Commented Jul 17, 2017 at 9:48

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.