Hi, I’m having some problems getting a 5v relay to drive a 12v mag lock.
Starting with the easy bit, I have a 12v power supply with +ve going into COM on the relay, and then NO to +ve on the mag lock. Then -ve straight from the supply to -ve on the mag lock.
On the other side, I had vcc connected to 5v, gnd to gnd, and IN to a few different GPIO pins 4/5/12/13/14. In ESPHome I’ve defined a basic switch for those respective GPIO pins.
When the power is connected to the esp8266, the light on the relay goes green, and the lock closes (relay activated).
The problem is no matter whether the GPIO pin is switched on or off, the relay stays powered. I noticed there’s a very small amount of voltage 100-150mV coming from the GPIO pin. If I completely disconnect the wire from the GPIO pin (so voltage drops to zero) then the light on the relay goes out, and the lock opens.
The same behaviour exists on all GPIO pins, all supply a very small current.
Have I wired these up correctly?
Should the GPIO pins be giving out a small voltage even when not pulled high/low?
Is there a way to work around this?
It’s a very basic switch, my thinking was this would supply enough voltage to drive the relay, and then when switched off it would no longer provide enough voltage for the relay.
Apologies not too familiar with the terminologies.
As I say when the switch is “on” it outputs ~3.3v which appears to be enough to drive the relay - relay LED is lit and I can see the mag lock close.
The issue is when the switch is “off” it still outputs 0.1-0.2v, within that Out Low voltage range your diagram shows. Which doesn’t appear to ‘stop’ the relay - the only way I’m able to do this is by pulling out the wire which obviously then has 0v which switches off the relay.
I’ll see if I can put together a diagram if that helps.
Put a resistor, 1000 Ohm = 1KOhm across the relay to offset the 0.1-0.2v in open state. That should work. Better yet, what kind of relay are you using? I looks like the relay might be “latching” meaning it needs 0 V to open.
Wow! If you have an advanced relay module with opto-coupler input: DC+ and DC- get 5V from the RPI. Then IN goes to the output pin of the RPI. “IN” via (LTV 817) turns on the LED that isolates the input.
Note: this does not really isolate the relay 100%. The jumper has a setting to fix that. Check the docs.