I have the attached circuit using an Arduino UNO to control a 12V motor via a MOSFET:
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.
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?
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.