Digital pin turning off spontaneously when driving a 12V motor

I have the attached circuit using an Arduino UNO to control a 12V motor via a MOSFET:

Picture1.jpg

It uses a HC-06 bluetooth module to receive commands, and when instructed it activates pin 13. Pin 13 is connected to an N-Channel MOSFET (FDP8880), which then switches on the motor. Both the arduino and motor receive power from the same 12V input.

The problem I have is when controlling the motor with pin 13 (ie not the switch), it will nearly always turn off after a few (1-10) seconds. The LED for pin 13 on the Arduino board also turns off whenever this happens, suggesting that pin 13 is refusing to stay HIGH, and for some reason is switching back to LOW.

What could be causing this? I have tested the circuit without the motor (just an arduino and bluetooth module) and it works fine, with pin 13 staying high for as long as needed. So I'm confident it's not a coding problem, but a problem with the circuit. When using the switch the motor operates fine, so I'm also confident I don't have a dodgy motor. I have made two of these units and had the same problem on both, so I also don't think it's a defective arduino board etc.

Picture1.jpg

Installation & Troubleshooting
For problems with Arduino itself, NOT your project

TheMemberFormerlyKnownAsAWOL:
For problems with Arduino itself, NOT your project

My arduino digital pin is not staying HIGH, is that not a problem with my Arduino?

Does your code include pinMode (pin13, OUTPUT); ?

CrossRoads:
Does your code include pinMode (pin13, OUTPUT); ?

Yep. I'm confident it's not an issue with the code as without the motor in the circuit the pin stays HIGH fine.

I'm assuming (ie guessing) it must be something to do with the power of the motor travelling into pin 13 and causing it to go haywire?

Maybe I'm totally mistaken but to my knowledge motor should be between power and drain and souce should be connected to ground; see e.g. https://www.gammon.com.au/motors

I think your MOSFET is miswired.
Drain should go to Motor- (anode of diode) and Source to Gnd.
That way the MOSFET acts as a low-side switch for the motor.

Thanks, I will try that. I originally thought it didn't matter whether the MOSFET was at the positive or negative side of the circuit. But why would it result in the Arduino pin turning itself off?

Your circuit shows a MOSFET connected as if its a p-channel FET, with source to +12V.

That, however, cannot be driven without a level shifter from the Arduino as the gate would
have to be at +12V to turn the motor off.

So:

Is your MOSFET n-channel or p-channel? What actual device is it?

Its far more common to use an n-channel MOSFET, and it would need to be logic-level to
be driven direct from an Arduino pin.

An n-channel device would be used as a low-side switch, source->GND, drain->motor -ve

@MarkT

from opening post

N-Channel MOSFET (FDP8880)

You can prove the pin is turning itself off by disconnecting the motor and connecting a LED and resistor to the pin, set the pin to HIGH, and wait till the LED turns off on its own.

Idahowalker:
You can prove the pin is turning itself off by disconnecting the motor and connecting a LED and resistor to the pin, set the pin to HIGH, and wait till the LED turns off on its own.

It’s a Uno; there’s already a LED there

TheMemberFormerlyKnownAsAWOL:
It's a Uno; there's already a LED there

Cool!