The flyback diode
The coil kicked because its current had nowhere to go. Give it somewhere: a flyback diode across the coil, pointing back towards the supply.
While the button is held, the coil's top end is the higher one, so the diode is the wrong way round to conduct and does nothing. When the button lets go and the coil tries to drive its current on, the diode lets it flow round in a loop, through the coil and back.
Place a diode from the coil's bottom end (column 19) to its top end (column 16), with the stripe, its cathode, on the top end.
Press Run, press and hold the button for a moment, then let go, and watch the scope.
During those ten milliseconds, with the button open, where is the coil's current going?
- Round a loop: out of the coil's top, back through the diode into its bottom
- Into the battery, charging it
- Nowhere: it stops the instant the button opens
The diode makes the current die away more slowly. In a relay, that means its contacts let go a few milliseconds later. When might that matter?
- When the relay has to switch off quickly, so designers add a zener in series with the diode to let the voltage rise further and the current fall faster
- Never: slower is always safer
- Only with AC supplies
The flyback diode:
- goes across the coil, cathode to the supply's side, so it's reverse-biased in normal running;
- when the coil is switched off, it carries the coil's current round in a loop, holding the voltage to about 0.7 V;
- the field then empties slowly, over milliseconds.
On a real bench every relay, solenoid and motor switched by a transistor gets one, usually a 1N4148 or 1N4007 right across the coil's terminals. Many relay modules have it built in; a bare relay on a breadboard doesn't. Leave it out and the circuit may work for days before the transistor quietly dies.