Relay or motor makes the board reset: add a flyback diode

When current through a coil is cut off, the coil makes a voltage spike. A diode across the coil gives that current a safe path.

What the message means

Relay coils, solenoids and motors store energy in their magnetic field. A sudden switch-off pushes the voltage in the opposite direction, which can reset the controller or damage a transistor.

Fix it in this order

  1. Place a diode (for example 1N4007 for a relay coil) across the coil, with the stripe (cathode) toward the positive supply side.
  2. Relay modules with a driver usually include the diode already. A bare relay does not.
  3. For a small DC motor add a diode across the terminals as well, and a ceramic capacitor of about 100 nF across the motor.
  4. Drive the coil through a transistor or driver board, not from the pin directly.
  5. Keep the coil supply wires away from signal wires.

Why it happens

A relay coil or motor is an inductor. When the current is switched off it produces a voltage spike far above the supply, which can reset the board or damage a transistor. A flyback diode across the coil gives that current a safe path.

Fit a diode such as a 1N4007 across the coil with the cathode (the striped end) to the positive side. Most relay modules already include this, but a bare relay or motor does not. A diode only helps with the switch-off spike; for noise from brushes, add a 100 nF capacitor across the motor terminals as well.

If you see this, do this

You seeDo this
Resets only when the relay switches offMissing flyback diode.
Transistor gets damagedAdd the diode and check the rating.

relay active low, reset on motor start.

Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.

Why this happens

A coil stores energy in its magnetic field: the energy equals half the inductance times the current squared. While current flows steadily, the coil looks like a resistor. When a switch opens, the current cannot change instantly, so the coil forces it to keep flowing and raises the voltage at the switch side until something conducts. With nothing else to carry it, that something is the switch, the transistor or the pin, and the spike can be hundreds of volts.

A diode placed backwards across the coil, with its cathode on the positive side, gives the current a loop to circulate. The voltage at turn-off is then limited to the supply plus about 0.7 V. The spike can still travel into the supply and ground wiring, which is what resets a microcontroller before a part is actually damaged.

How to confirm the cause

  • Reset the board on purpose by switching the coil with your code and watch whether the reset happens only at switch-off. That points to the inductive spike.
  • If you have an oscilloscope, probe across the switching transistor. A spike well above the supply at turn-off confirms it.
  • Check the diode’s direction with a meter in diode mode. It must conduct from the coil’s negative terminal to its positive terminal.
  • Read the relay module’s silkscreen or schematic to see whether a diode is included.
  • Power the coil from a separate supply. If the resets stop, the spike or the supply sag came through the shared rail.

Worked example

Working out the current the diode has to carry. A 12 V relay coil of 400 ohm:

Coil current = V / R = 12 / 400 = 0.030 A (30 mA)

At turn-off the coil keeps 30 mA flowing
through the diode, which drops about 0.7 V.
Peak voltage at the transistor is about
12 + 0.7 = 12.7 V instead of a large spike.

A 1N4007 (1 A) or 1N4148 handles 30 mA easily.

Common mistakes

  • Fitting the diode the wrong way round; it then short-circuits the supply as soon as the coil is powered.
  • Fitting it across the relay contacts instead of across the coil.
  • Assuming a transistor module has a diode; many have only a resistor.
  • Expecting a flyback diode to remove brush noise from a motor; a capacitor does that.
  • Running the coil wires next to signal wires, which couples the spike in.

If this did not fix it

  • A supply that sags when the coil switches on, which resets the board at turn-on, not at turn-off.
  • A missing common ground or a poor ground connection that shares the coil current path.
  • A coil driven straight from a microcontroller pin, which can draw more current than the pin allows.