user14298: I have the following circuit: 
And I know it works and that the diode protects the negative voltage from flowing back into the transistor. This is essentially the circuit: 
Could someone illustrate what happens when the motor stops? The current normally flows from 5V to GND (and the electrons from GND to 5V, but this doesn't matter (I think?)), and then it reverses when you switch it off, so current comes out of the top of M1, and then what? I don't get it here.

user4143: While the motor is being powered the current flows from Vcc to GND as in this circuit:

When the power is disconnected (such as the transistor in the ground connection in your circuit is switched off) amongst other things (including the collapsing of magnetic fields) the spinning of the motor turns it into a generator.  The power generated is the opposite of what was being provided to make it move.  As the magnetic field of the coils collapses additional high voltages are also generated.
When disconnected the motor can be represented as a battery connected backwards.  In that configuration the current flows from the + of this hypothetical battery through the diode into the - thus stopping any current from going elsewhere, as in this circuit:


14298: <p>I have the following circuit: <a href="https://i.stack.imgur.com/lZJDW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lZJDW.jpg" alt="Arduino circuit"></a></p>

<p>And I know it works and that the diode protects the negative voltage from flowing back into the transistor. This is essentially the circuit: <a href="https://i.stack.imgur.com/qGZ9h.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qGZ9h.jpg" alt="Circuit"></a></p>

<p>Could someone illustrate what happens when the motor stops? The current normally flows from 5V to GND (and the electrons from GND to 5V, but this doesn't matter (I think?)), and then it reverses when you switch it off, so current comes out of the top of M1, and then what? I don't get it here.</p>
 4143: <p>While the motor is being powered the current flows from Vcc to GND as in this circuit:</p>

<p><a href="https://i.stack.imgur.com/QULAI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QULAI.png" alt="enter image description here"></a></p>

<p>When the power is disconnected (such as the transistor in the ground connection in your circuit is switched off) amongst other things (including the collapsing of magnetic fields) the spinning of the motor turns it into a generator.  The power generated is the opposite of what was being provided to make it move.  As the magnetic field of the coils collapses additional high voltages are also generated.</p>

<p>When disconnected the motor can be represented as a battery connected backwards.  In that configuration the current flows from the + of this hypothetical battery through the diode into the - thus stopping any current from going elsewhere, as in this circuit:</p>

<p><a href="https://i.stack.imgur.com/1Rjim.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1Rjim.png" alt="enter image description here"></a></p>
