Motor activation using MOSFET
Depending on the current needed by the motor, select a suitable N-channel MOSFET as a low side switch:







simulate this circuit &ndash; Schematic created using CircuitLab

The flyback diode need not be physically at the motor coil - if the motor is not accessible, using a diode on the control board will work too - subject to somewhat greater EMI. Depending on the parasitic diode of the MOSFET for flyback voltage inhibiting is a really bad idea: Those body diodes typically have poor characteristics - High Vf and slow switching.

The MOSFET indicated here, IRLML2502, is a really inexpensive logic level MOSFET which turns on quite well at 4.5 Volts gate voltage, for motor current of ~ 3.4 Amperes. If you need greater current, alternatives like the OnSemi NVTFS5826NL can be used instead (20A @ 60V).

The low value gate resistor inhibits ringing, and limits current spikes from the GPIO pin. The pull-down ensures that the MOSFET remains off while the microcontroller is starting up or in high impedance state.