Arduino Mega driving 5V to 12 V
You're on the right track, but need to modify your circuit. A N channel MOSFET requires a positive \$V_{gs}\$ to turn on. If the solenoid is always on in your current circuit, you have drain and source reversed, and starting over with a fresh MOSFET would be a good idea. This configuration should get you going, but may need to play with some resistor values.







simulate this circuit &ndash; Schematic created using CircuitLab