Please help.

I am connecting 12V electric magnetic lock to a SPDT relay which is controlled via a microcontroller (MCU) GPIO output pin. Whenever the output pin is pulled low, then the relay is turned off else it is turned high when the output pin is pulled high.

Initially, I tried without using any electric magnetic load but with just relay and everything works fine with the relay turning on and off as desired.

However, when i connect it together with the electric magnetic load then the GPIO output wont pull low from high state. I checked on the MCU GPIO pin and it seems to pull high which is the previous state instead of the expected low signal. For the relay seems to have slight contact and then it switched back to high in split seconds. It would practically have no switching at all.

My circuit for connecting the relay is using NPN transistor to drive it high and low where the electric lock is supplied via 12V into the common point of relay.
12V is driving through power supply which 5V is regulated via regulator to the microcontroller. All comes from single dc power source.

My question would be why once the magnetic load is connected then the MCU GPIO cannot be pulled low. I have provided the schematic as follow.

Do provide some advice :)


simulate this circuit – Schematic created using CircuitLab

  • 2
    \$\begingroup\$ Try it with no lock attached. YOu may be drawing too much current which will drop the 12V and reset the micro. If you have spec sheets for the relay and lock it would help. \$\endgroup\$ – Trevor_G Sep 27 '17 at 17:54
  • 2
    \$\begingroup\$ U1 has no decoupling capacitors. It needs them. \$\endgroup\$ – Transistor Sep 27 '17 at 18:04
  • \$\begingroup\$ @Transistor actually I tried with decoupling capacitor but still the same. Furthermore, i tried to use power module regulator as well but result same. \$\endgroup\$ – Nick Sep 28 '17 at 5:59
  • \$\begingroup\$ @Trevor , i tried removing the lock and it works as expected. As for the voltage drop, I try to increase the current and voltage from the power supply but it is not working. I think the problem now is the MCU cannot pull low the GPIO pin. If i take the pin from GPIO and connect it to ground, the relay will work by switching it. Magnetic Lock uses 12VDC/100mA. Relay : image.dfrobot.com/image/data/DFR0017/… \$\endgroup\$ – Nick Sep 28 '17 at 5:59
  • \$\begingroup\$ @Nick is the circuit is actually as indicated the micro should have no issue pulling it low. You also mentioned it briefly activates, which to me indicates the micro is doing something else, probably resetting. \$\endgroup\$ – Trevor_G Sep 28 '17 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.