What´s the purpose of this diode?
From the question below:
A diode is put in parallel with a relay coil (with opposite polarity) to prevent damage to other components when the relay is turned off.
This is called a flyback diode.
See also How to choose a flyback diode for a relay?
See also the comment of Kevin White (in my own words):
- The diode prevents current spikes
- The problem happens during turn-off
The diode is known as freewheeling/flyback diode.
Imagine that the relay is energised. A current will flow through it and will set up a magnetic field around it. When the relay is de-energised, this field will collapse as there is no more current to sustain that field. Michael Faraday found out that whenever a magnetic field associated with a coil changes, a voltage will be induced in it. In our relay, this change in field is rapid and the voltage will be high. This can be damaging to the transistor. So we put a diode across the coil such that it will short circuit the coil and the voltage across it quickly settles to zero.
I believe this will help.