Relay's Flyback Diode - Is it necessary?
-- EDIT --

If you can figure out a way to ramp the inductor's current down bit by bit without using PWM, with a MOSFET with a sufficiently high current blocking voltage rating you may be able to get away without the flyback diode. However this would require you to control this ramping precise enough not to ramp its current down too quickly and the turn down time can be very unbearable.

-- ORIGINAL POST --

TL; DR: It is necessary - it is critical you can say. It makes your circuit last longer.

Theory: Flyback diode.

Extended ELI5 answer:

Relays are switches controlled by an electromagnet, and electromagnet is essentially a BFI - big f***ing inductor. Inductors do not allow the current through it change rapidly. The bigger the inductance it have, the harder it will fight to keep its current constant, drawing energy it stored in the form of its magnetic field.







simulate this circuit &ndash; Schematic created using CircuitLab

Consider we are using a mechanical switch to control this relay. When it is constantly kept powered, it is saturated and act simply as a small resistor, passing, let's say, 500mA of current.







simulate this circuit

Now switch it off. An opened switch poses several GΩ of resistance in the circuit, being essentially an air gap. However the current across the inductor cannot drop immediately, and to keep this several amps of current flowing the inductor from changing the inductor induces enough voltage to break the air down into plasma across the open switch contacts and force the current to arc across. That is several kV (!!) of voltage and a fire hazard. (!!!)







simulate this circuit

Now let's say we have a transistor instead of a mechanical switch. I am using my personal favourite 2N7000 N-MOSFET here. With the control driven high, the coil is in a similar saturated state acting as a small drain resistor.







simulate this circuit

When the gate is suddenly grounded the similar situation will happen across the MOSFET's drain and source pins, easily break the transistor down to conduct that induced current. Such a voltage pike will take out a signal transistor after several rounds of switch-off spikes if not outright. For BJT's like 2N2222 the situation is even worse as one single Zener zap and your transistor is gone.







simulate this circuit

Now we have a diode reverse parallel with the coil there. I used 1N5819 Schottky which allows faster switching and better suited with motors that need PWM control, for relays slower 1N4007 can be used but it have a higher forward voltage. The same start situation, coil saturated. In this state, the diode is reverse biased and do not affect the circuit.







simulate this circuit

The instant the transistor is off, the current begin to flow through the diode. The transistor will only see a drain-source voltage of at most a few volts higher than the supply voltage.

This is an extended explanation why you need a diode antiparallel across the coil. It keeps your circuit from being fried by an inductive voltage spike from the coil.