0

Basically it hooks up to a 12v relay:

https://drive.google.com/drive/u/0/folders/0BxdLxDCD6HidZDFfWHhjWEZHYVU

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
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
GPIO.setup(17,GPIO.IN,pull_up_down=GPIO.PUD_UP)
#GPIO.setup(17,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)

try:
        while True:
                input_state = GPIO.input(17)
                if input_state == False:# and GPIO.input(27)==1 :
                        print ('Button Pressed'),input_state
                        GPIO.output(18,GPIO.HIGH)
                        time.sleep(0.2)
                GPIO.output(18,GPIO.LOW)
except KeyboardInterrupt:
  print "  Quit"
  # Reset GPIO settings
  GPIO.cleanup()
7
  • GPIO 17 is connected to pin 11. Is that the pin you are using for the relay?
    – joan
    Oct 3, 2016 at 8:01
  • @joan nope. I'm using pin 18 for my relay. Oct 3, 2016 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, 2016 at 13:55
  • @joan Correct! did you encounter this issue before? Oct 3, 2016 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, 2016 at 18:10

1 Answer 1

1

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.