Solenoid and Diode


I’ve been designing a circuit to control 9 x 12v solenoids. I’ve have it working with a breadboard and a photon and I have started to move to a non-breadboard prototype. I started with perfboard, but have since moved on to protoboard. No real reason there, just my soldering was so bad on my first run I needed to start over and wanted to see how protoboard compared to perfboard.

Anyway, something that has troubled me since my first prototype is the diode. I understand that I’m using a 1N4001 blocking diode to prevent the discharge from the solenoid passing back into my circuit and blowing components, but even after reading several tutorials and playing with my multimeter, I’m still not really sure I understand. I want to make sure I fully understand being completing my current prototype. Not strictly a photon question, sorry.

In most of the diagrams I find, you see something like this…


The diode sitting between the two ends of the solenoid, stopping the power running back. But the diode isn’t actually “inline” with the rest of the circuit. What is to stop the power from the solenoid going straight past the diode and back into the circuit?

In my circuit, I have the middle pin of my tip120 connected to one end on my solenoid, and the 12v power going directly to the other end of the solenoid. If I put a multimeter on the solenoid I can see 12v on both ends. The 12v runs all the way back to the middle pin on the tip120. When I send current from my photon GIO pin, the current on the middle pin of the tip120 drops to 1.6v and then drops on one end of the solenoid, while the other stays at 12v, and the solenoid fires. All as expected. Nothing is actually broken here, I just don’t understand how the diode is protecting anything.

(I’ve only pictured the front, safe to assume the connections underneath between wires and components are complete, as the circuit is responding as expected)

If anyone has anything I can read or any pointers that would help me clear this up, it would be appreciated.


This way of connecting a diode to an inductive load is called flyback or freewheeling diode.
There are many resources online to read up on how and why they are used and hence little point reiterating this here IMO.

In short they “short-circuit” the induced, opposing voltage caused by the collapsing magnetic field of the coil when the driving voltage and hence current is switched off.


Essentially, the solenoid generates its own voltage when it turns off. It is a dynamic event which it difficult to observe with a DMM. You need a scope. This article should explain the details.
BTW: Don’t drive the base of the TIP120 directly from the Photon. Add a resistor in series to limit the current and protect both the Photon and the BJT. Better yet, use a MOSFET.

Dang, ScruffR is so quick.


Thanks, both.

That article cleared it up, I think, thanks…

Note that the placement of the diode does not prevent a voltage spike from travelling to some downstream load. Instead, it provides a path with low resistance that reroutes the current, thus the voltage spike at the downstream load to be much lower. Using a simple 1N4007 diode is sufficient to suppress large voltage spikes in a 24VDC relay with a diode protection circuit.


Here is a good video describing the effect in detail.

I recommend pretty much all of Alan’s videos, he knows what he is talking about (unlike many youtubers) and has a clear presentation style. His videos cover an enormous range, from basic to advanced, and there are a lot of good ones on getting the most out of test equipment.


Keep in mind that the purpose of a solenoid is to generate a magnetic field (to pull in the plunger) … Magnetic fields store energy, and when you interrupt the current that is maintaining the static field, the field begins to collapse… which in turn pushes current in the coil in that same direction. This current will be dissipated resistively in whatever path it’s able to take, and if you’ve given it a freewheeling diode to short through, that will mostly be the coil resistance.

There are a lot of descriptions about how the coil voltage flips and this and that, which is true but it’s not a good general paradigm to understand what’s happening IMO

When a current source is abruptly removed from an inductor, the magnetic field begins to collapse, and this creates a voltage spike that is opposite in polarity to the source. The protection diode keeps this reverse voltage low enough that the transistor is not damaged.

When an inductor (solenoid) is de-energized, a voltage equal to MINUS the inductance times the rate of change of current vs time or E= -L di/dt. Let’s say the solenoid inductance is 10 millihenries and the solenoid current while on is 50 milliamperes and that current is reduced to zero in 10 microseconds after the solenoid is denergized. That will produce a peak voltage of about -(10x10^-3) x (50 x 10^-3)/ (10x 10^-6) or -50 volts. So now the “bottom” end of the solenoid is positive causing the diode to be forward biased into conduction thus limiting the voltage reflected back to the driving circuit to around 600 millivolts for a very short duration as the inductive field collapses.

1 Like