Electronic – Protecting microcontroller from inductive loads

decoupling-capacitorflybackprotectionzener

I'm working on a project where I will be controlling a variety of loads (relay, solenoid, motor) from an Arduino and I'd like to make sure I build in enough protection for the microcontroller and other components. I've see a variety of solutions using transistors and adding decoupling capacitors, flyback diodes, and zener diodes. I'm wondering how one would choose between one or a combination of these options?

I'm wondering how one would choose between one or a combination of these options?

It's easy, if you understand how inductors work.

I think the problem most people have is that they hear words like "inductive voltage spike" or "back-EMF" and reasonably conclude something like

So, when an inductor is switched, it's for an instant like a 1000V battery.

simulate this circuit – Schematic created using CircuitLab

Indeed in this particular situation, this is more or less what happens. But the problem is that it's missing a critical step. Inductors don't just generate really high voltages to spite us. Look at the definition of inductance:

$$v(t) = L\frac{\mathrm di}{\mathrm dt}$$

Where:

• \$L\$ is inductance, in henrys
• \$v(t)\$ is the voltage at time \$t\$
• \$i\$ is current

This is like the Ohm's law for inductors, except instead of resistance we have inductance, and instead of current we have rate of change of current.

What this means, in plain English, is that the rate of change of current through an inductor is proportional to the voltage across it. If there is no voltage across an inductor, current remains constant. If the voltage is positive, than the current becomes more positive. If the voltage is negative, than the current decreases (or becomes negative -- current can flow in either direction!).

A consequence of this is that the current in an inductor can not instantly stop, because that would require an infinitely high voltage. If we don't want a high voltage, then we have to change the current slowly.

Consequently, it's better to think about an inductor in an instant as a current source. When the switch opens, whatever current was flowing in the inductor wants to keep flowing. The voltage will be whatever it takes for that to happen.

simulate this circuit

Now instead of a 1000V voltage source, we have a 20mA current source. I just arbitrarily picked 20mA as a reasonable value, in practice this is whatever the current was when the switch opened, which in the case of a relay is defined by the resistance of the relay coil.

Now in this instance, what must happen for than 20mA to flow? We've opened the circuit with the switch, so there's no closed circuit, so current can't flow. But actually it can: the voltage just needs to be high enough to arc across the switch contacts. If we replace the switch with a transistor, then the voltage needs to be high enough to break the transistor. So that's what happens, and you have a bad time.

In case A, the inductor will charge the capacitor. A capacitor is just like an inductor with current and voltage switched: \$i(t) = C\: \mathrm dv/\mathrm dt\$, and so a constant current through a capacitor will change its voltage at a constant rate. Fortunately, the energy in the inductor is finite, so it can't charge the capacitor forever; eventually the inductor current reaches zero. Of course, then the capacitor will have some voltage across it, and this will then work to increase the inductor current.