Getting Started with Arduino...MOSFET Question

I am new to the Arduino but not to programming. The "Getting Started with Arduino" 2ed, 2011, pp69 Figure 5.7 diagrams the use of a Mosfet. I think I understand the mosfet but there is a diode in the diagram that I cannot understand.

9v from the Arduino powers the breadboard's power line. Under Arduino program control, when the mosfet's gate (left leg) is triggered by pin 9, the mosfet drain (middle leg) is connected to the source (right leg). When the Arduino's program powers on pin 9, power would go from the 9v of the Arduino, through the breadboard's power line, to the fan's + wire, through the fan, to the fan's negative wire, to the mosfet's drain (middle leg), through the mosfet, to the mosfet source *right leg) to ground, thereby turning the fan on.

My question is: why is there a diode pointing from the mosfet drain (middle leg) to the breadboard's power line? What is its purpose? There is no explanation in the book. The diode is directional and does not look to be a resistor. I have attached the diagram I found from google (http://manualigratis.altervista.org/it/img51.png) for reference.

Thanks in advance.

Any load with an inductance (with some kind of coil, like relays, valves, motors, etc.) will generate a big voltage spike when turned off. In such situatin a diode is always used. The current of the inductance when turning off will flow through the diode.

I do not really understand the concept of inductance, so pls bear with me.

The fan/motor is an electromagnet when power is added, turning the motor armature that spins the fan blade. When the power is cut the electromagnet, instead of using electricity then produces electricity. Is this the "big voltage spike" that you mentioned? Does the simple act of turning off the power cause some voltage spike?

What is the diode protecting, the Arduino or the mosfet? How is the diode protecting the Arduino or the mosfet? Without the diode how could the Arduino or the mosfet become damaged?

Thanks for your patience. I am a noob at electronics.

With an inductor, once you get some current flowing in it, it reaches a steady state and looks like a fixed resistance.
When you stop the current flow, the inductor tries to keep that current flow going - the diode lets the current wrap around back into the inductor to dissipate.
Without the diode, a large voltage spike is created at the transistor controlling the current can damage that transistor.

There's more to it with electromagnetic fields and back EMF, but that's the gist of it.

Without quite getting into differential equations inductors have this behaviour:

The voltage across the inductor is dependent on the rate of change of current. If you open a mechanical switch fast from which an inductor is powered the inductor will generate whatever voltage is necessary to make a spark (can easily by thousands of volts, for BIG inductors this can be enough to endanger life, note).

A transistor can switch off in timescales of the order of a millionth of a second - this is extremely fast. With an inductive load what happens is that when it switches off the voltage will jump to the voltage that causes device breakdown. With enough energy stored in the inductor the device is destroyed (or even vaporized). With the diode across the inductor the voltage jumps to the supply voltage plus one diode drop, which is harmless.

With a big device and a small inductor the energy might not be enough to damage the device (indeed some MOSFETs are rated for how much inductive energy they can safely dissipate at breakdown), but in general inductor or motor means you use a diode or have to replace a blown component.

Thanks for the explanation. To summarize, and to check my understanding, the digital input shuts off the gate very quickly but the inductor cannot do the same. This lag creates extra power, which if not safely shunted away by the diode, can destroy the transistor.

In general in a circuit with a mosfet and an inductive device should the diode always be connected from the drain back to the power source?

Can you all recommend any search terms on this topic for me to Google? What is the technical name for this power surge? Back EMF? I think I need more study.

It's called a flyback diode.
But some call it a clamping diode, or back EMF diode.

Thanks all for your effort to educate me. I'll be paying attention to flyback diodes in other electrical schematics where an inductor is involved.

TorontoBoy:
Thanks for the explanation. To summarize, and to check my understanding, the digital input shuts off the gate very quickly but the inductor cannot do the same. This lag creates extra power, which if not safely shunted away by the diode, can destroy the transistor.

In general in a circuit with a mosfet and an inductive device should the diode always be connected from the drain back to the power source?

Can you all recommend any search terms on this topic for me to Google? What is the technical name for this power surge? Back EMF? I think I need more study.

Firstly nothing "creates extra power" - the inductor is storing energy (in the magnetic field) while it carries a current - that's what inductors do - that energy is dependent on the current (squared) - and it has to go somewhere.

Its nothing to do with the MOSFET - any switching device (even a mechanical switch or relay) connected to an inductor needs protection, for DC circuits a diode is normally used, for AC a "snubber" RC network is normally used.

The term you want is possibly "inductive spike"