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 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()