# Electromagnet stays energized after being switched off

I've designed a circuit to turn on/off a 12V electromagnet but when I turn off power to the magnet it still has a magnetic force. The magnetic force when OFF is not as strong as when it is ON but it still has more magnetic force than desired. The electromagnet has no magnetic force before the circuit is powered up and current is applied to the magnet. Is there a modification I can make to my circuit that will eliminate the magnetic force when the magnet is switched off.

The 100nF capacitor is to absorb flyback current caused by the coil into the switch which is actually a digital I/O pin of an Atmel 328p

simulate this circuit – Schematic created using CircuitLab

• Try to disconnecting the electromagnet after it has been turned off. If there is still too much magnetic attraction, the metal part of the electromagnet is being magnetized. Please modify your question with the result of this test and we can provide further assistance. Commented Aug 8, 2018 at 23:58
• The electromagnet has no magnetic force when disconnected. Commented Aug 9, 2018 at 0:07
• @Dwane:Switching off the transistor shuts off current. How will disconnection change anything? (Looking at the comment above though the transistor may be short-circuit.) Commented Aug 9, 2018 at 0:07
• @Jeff: You need a snubber diode across the solenoid rather than the capacitor across the transistor. Commented Aug 9, 2018 at 0:10
• The capacitor is actually working well as a snubber. Without it the micro-controller will reset when the magnet is switched off. Commented Aug 9, 2018 at 0:18

You actually have a Darlington transistor with internal resistors rather than the BJT that you show.

I will assume that your solenoid draws quite a bit of current. You need much more than a 100nF capacitor across the transistor to absorb the energy. You have probably damaged the transistor (or possibly the capacitor).

When the Darlington turns off, the inductance will try to maintain the same current flowing, and the voltage at the Darlington collector will rise to make that happen. If the solenoid current is substantial, hundreds of mA or more, the capacitor will have little effect and the voltage will rise, probably to over 100V, causing the transistor (or possibly the capacitor) to break down. With enough energy that will kill the transistor. If the capacitor breaks down it has failed and probably short.

You can leave the capacitor on there, it does control the EMI and is not high enough value to cause problems for the transistor, but you must add a flyback diode across the coil (or something similar).

If you want the solenoid to drop out faster, you can add a resistor in series with the diode. The voltage across the coil will rise to a maximum of I*R +Vf where I is the operating current of the solenoid and Vf is the diode forward voltage. So if the solenoid draws 500mA and you want to allow the collector voltage to rise to 30V you can allow the (coil + diode) voltage to rise to 17V so R should be less than 34$\Omega$.

• I added a diode parallel to the capacitor and it had no effect on the magnetic force of the electromagnet when switched off. I suppose this does give better surge protection to the circuit but does not address the fundamental issue. Commented Aug 9, 2018 at 1:13
• The diode parallel to the capacitor does exactly nothing. The diode goes across the coil, as I said above. Commented Aug 9, 2018 at 1:47
• I've done some measurements and discovered that when "OFF" there are 46mA flowing through the electromagnet. In this state there is only 8mV present on the base of the transistor. Is the 8mV really significant? Perhaps I should ground the base with a 10K resistor? Commented Aug 9, 2018 at 1:47
• There are already resistors inside the TIP120- 8K and 120 ohms. If there is 46mA flowing through the coil either the transistor or the capacitor are toast. Commented Aug 9, 2018 at 1:49
• Yes, the transistor is fried. It measures 222 ohms from collector to emitter which accounts for the current flowing when it's switched off. A good TIP120 measures 3.2M ohm. It's odd that the fried transistor still switches current it just can't turn off completely. Commented Aug 9, 2018 at 12:22