For over a year now, I have been using one of
these with my Pi (2B and now 3) to switch a 12 volt supply on and off to control some fans in a server cabinet I made when none of my Network Attached Storage devices are on. It worked perfectly, so I thought I'd set up a similar one to switch the actual power on and off to the source of power for the NAS's (in total they draw less than 100W). I setup my circuit as attached and used
this (I tried both high and low mode) and then
this relay. Both worked a few times and turned the plug on and off a few times and then stopped working and the power was always on. The relay would click, but wouldn't turn the power off. What am I doing wrong? I even tried it using the second unused relay that was controlling my fans and that did the same thing. I've seen people use these things to control their heating so I don't see how it can be the power draw!
I can't see how it can be a software issue as it has worked fine with the 12v switching and also worked a few times with the 240v before stopping but I'll post a sample of the code I've tried:-
Code: Select all
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
#should be off now
GPIO.output(17, True)
raw_input()
GPIO.output(17, False)
#should be on now
And also switching between in and out mode:-
Code: Select all
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)
#should be off now
raw_input()
GPIO.setup(17, GPIO.OUT)
#should be on now
I'm currently using one of
these to control 240v in another room using a BBC micro:bit with exactly the same wiring on the mains side and that works fine. I'm considering buying another one, but I heard that the 3v source on the Pi can't provide enough to power a relay. As a last resort, I can control a micro:bit via serial to control one of those relays, but I'd rather use the GPIO as I'm already using it very successfully to switch 12v!
Any help would be very gratefully received. I've spent hours trying to get this working as I over-engineer everything when mains power is concerned and spend a lot of time checking and double-checking and enclosing everything in enclosures. Please don't reply just to tell me I'm being dangerous/could fry my Pi etc. I've been doing all sorts with electronics for years and everything is insulated very safely and the whole setup is connected via an RCD plug anyway. The relays all have opto-couplers - so there's no reason any voltage should get back into the Pi (and if it was going to happen it would have done by now anyway).
P.S. Sorry about the terrible quality of the diagram!
