This seems like it should be really simple, so maybe I am missing something. I am just trying to open and close my relay but all it does it open's and doesnt close. I can use GPIO.cleanup() to make it close but I dont want to apply this at this point in the project.
Link to 5v relay -> https://www.amazon.co.uk/XCSOURCE-Channel-optocoupler-Arduino-TE213/dp/B00ZR3B252
UPDATE: 6th Jan 17 As suggested in the comments I have tested the GPIO's and can see that 3.3V comes out when HIGH and it goes back to 0v on LOW. But LOW does not turn off the relay oddly. I have tried 2 of these relays and both do not switch off when at LOW (0v).
I have tried to find the original documentation for GPIO.clean() function since this allows it to close but cant find it. Can anyone think why this does this?
import RPi.GPIO as GPIO
from time import sleep
relayPin = 32
GPIO.setmode(GPIO.BOARD)
GPIO.setup(relayPin, GPIO.OUT)
## Turn on the Relay (this works - it clicks gives 3.3v)
GPIO.output(relayPin,GPIO.HIGH)
sleep(1)
## Turn off the Relay (this does nothing but goes back to 0v)
GPIO.output(relayPin,GPIO.LOW)
sleep(1)
## if I add GPIO.cleanup(), the relay then closes,
## but I dont want to cleanup at this point
GPIO.setup(relayPin, GPIO.OUT)
sets the GPIO as anOUTPUT
. When anOUTPUT
a GPIO is actively driven to 3V3 or 0V. TheGPIO.cleanup()
changes the GPIO toINPUT
mode. – joan Dec 31 '16 at 14:48IN
pin on the relay module is an input, not an output. – Mark Smith Dec 31 '16 at 16:45