Is my mosfet IRF540N OK ? Help to understand MOSFET behaviour
Hook it up like this. R2 can be much higher than 10K, very high values will cause it to switch off slower. 

The MOSFET is switched on by having a positive voltage of a few volts on the gate relative to the source. It is switched off by having 0V. The gate behaves electrically like a capacitor of some nF, so you have to charge and discharge it just like a capacitor. If you leave the gate open (floating) it will tend to maintain the same state, sometimes for a surprisingly long period of time, before eventually leakage causes it to change. 

If you're using a heavy load instead of R1, you want to make sure that the MOSFET is always cleanly on or off, not somewhere in-between where it will get hot. For example, if your 12V was a car battery and R1 was a heater, if you allowed the car battery to discharge to flat, there might be a point where the MOSFET was destroyed because it got too hot. Same thing could happen a lot faster (with a heavy load) if you allow the gate to float. 







simulate this circuit &ndash; Schematic created using CircuitLab