Here it is in a nutshell: A metal detector is hooked up to an Arduino Uno. When it detects metal, the Arduino sends power to an IRF540N MOSFET which activates a DC motor with it's own power supply for a second and then turns off.
I do not know if the IRF540N MOSFET is N-channel or P-channel (if that even matters).
My problem is, everything works fine but the motor doesn't turn off as desired even when the metal detector stops detecting soon after.
I do not know if I've connected something wrongly or if there is an error in my programming - I assume that the digital pin connected to the MOSFET must be set to low/no voltage when I want to turn the motor off but this doesn't work (I only just started learning and playing with transistors today).
Here's the code:
int metalDetector = 11;Motor datasheet:http://www.mabuchi-motor.co.jp/cgi-bin/catalog/e_catalog.cgi?CAT_ID=rs_360shIRF540N MOSFET datasheet:http://www.irf.com/product-info/datasheets/data/irf540n.pdf
int pumpCircuit = 12;
// while the metal detector isn't detecting anything, it gives a HIGH voltage (TRUE) reading
delay(1000); //leave the pump on for a second
delay(2000); //delay between reads
EDIT: Fixed reversed terminals on motor