Basically it hooks up to a 12v relay:


If button is pressed, it should send high to the relay.

The problem I encounter is that if I run the gnd of RPi to Gnd input of relay, my code continues (or it sends an input to pin17) even without me pressing the button...me just holding the wire satisfies the false state.

Do you have an idea what's causing this?

import RPi.GPIO as GPIO
import time

        while True:
                input_state = GPIO.input(17)
                if input_state == False:# and GPIO.input(27)==1 :
                        print ('Button Pressed'),input_state
except KeyboardInterrupt:
  print "  Quit"
  # Reset GPIO settings
  • GPIO 17 is connected to pin 11. Is that the pin you are using for the relay? – joan Oct 3 '16 at 8:01
  • @joan nope. I'm using pin 18 for my relay. – user3610216 Oct 3 '16 at 13:26
  • Okay. The input (button) is using GPIO 17 which is physical pin 11. The output (to relay) is using GPIO 18 which is physical pin 12. Is that correct? – joan Oct 3 '16 at 13:55
  • @joan Correct! did you encounter this issue before? – user3610216 Oct 3 '16 at 17:37
  • No, you seem to have done everything correctly. To take this further I think we need a photo of your Pi set up and connections. – joan Oct 3 '16 at 18:10

If I'm reading this correctly, the relay is being triggered even without a trigger from the RPI? If that's the case, I would think that you would need a pull up resistor on the output of the RPI to the relay. It would stabilize the floating output state that might be triggering the relay.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.