Voltage on the transistor and release time with each way of protecting an inductive load
If you do not know the inductance, small 5 to 24 V relays are usually between 0.1 and 1 H; it can be measured with an LCR meter or from the time constant with an oscilloscope. The calculated time is how long the current takes to fall to the release level; the contact then takes a few more milliseconds to separate because of the relay mechanics.
A coil opposes changes in current. While the transistor conducts, the current I = V/R creates a magnetic field that stores energy. When switched off, the coil tries to keep that current flowing and generates whatever voltage it takes:
If the current has nowhere to go, di/dt is huge and the voltage on the collector or drain rises to hundreds or thousands of volts in microseconds, until something gives: the transistor breaks down, an arc jumps or interference is radiated that resets the microcontroller. A transistor can survive a few of these hits and fail weeks later, which makes the fault hard to diagnose.
The freewheeling (flyback) diode is placed in parallel with the coil, with the cathode towards the positive. While the transistor conducts, the diode is reverse-biased and does nothing. When it opens, the coil current keeps flowing through the diode and the voltage on the transistor is limited to the supply plus about 0.7 V. The energy is dissipated gradually in the coil's own resistance:
Here Va is the voltage opposing the current in the discharge loop: 0.7 V with a diode alone, or 0.7 V plus the Zener voltage. The higher that voltage, the sooner the current reaches zero.
With the diode alone, the current falls slowly and the relay takes longer to release. The contact opens slowly, more arcing occurs and it wears out sooner, especially with DC loads. In solenoid valves and brakes the delay can be noticeable in the process. The solution is to discharge the energy at a higher voltage, without exceeding what the transistor can withstand:
| Protection | Voltage on the transistor | Release | Notes |
|---|---|---|---|
| Diode | V + 0.7 V | The slowest | Simplest and cheapest. Fine for most signal relays |
| Diode + resistor | V + 0.7 V + I·Rs | Faster | Rs of the order of the coil resistance; the peak grows with Rs |
| Diode + Zener | V + 0.7 V + Vz | Very fast | Best balance between speed and voltage; the voltage is well defined |
| TVS or Zener across the transistor | VTVS | Very fast | Also protects against spikes coming in through the cable |
| RC network or varistor | Depends on the values | Fast | For AC coils, where a diode cannot be used |
| MOSFET avalanche | MOSFET breakdown | The fastest | Only if the datasheet guarantees repetitive avalanche energy EAS |
Many relay modules and drivers such as the ULN2803 already include the diode; in the ULN2803 it only works if the COM pin goes to the positive of the coils.
Related: transistor as a switch, ULN2803 for relays and loads, optocoupler and RLC circuit.