UPDATE Issue only happens when load is connected, triggers every time without load
This 3.3 V .relay, link to the the >>> Datasheet
As the title mentions, it works fine until I try to switch it off the second time round, then I see the red LED turning on (it looks a touch dim).
Tapping the relay housing(lightly) triggers the relay Stuck relay then!
But why only after the second attempt and never on the first power off ?
EDIT: I looked at the datasheet thinking it needs a bit more voltage, but max is 3.9v!
import RPi.GPIO as GPIO
#from time import sleep
pin =2
# Set up input pin
# set bcm pin mode
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT)
# turn on relay in revese mode so sety pin to low
state = GPIO.input(pin)
if state:
print('on')
GPIO.output(pin, GPIO.LOW)
else:
print('off')
GPIO.output(pin, GPIO.HIGH)
Edit schematic
Sorry I have really bad drawing skills!
I have posted this on the raspberry pi.stackexchange but think the question may be better suited here. Thank-you.