Arduino nano breaks when using a common 12 volt power supply.

Hey guys, so here's some background

I'm working on an escape room puzzle, modified from this guys projects:

https://www.patreon.com/posts/connect-wires-15900367

Attached a schematic of his project with the following changes:

-No LEDs
-10 total Sockets (pins 12-3)
-Using sparkfuns RFP30N06LE N-Channel MOSFET kit instead of the 5v relay SparkFun MOSFET Power Control Kit - COM-12959 - SparkFun Electronics

Now the puzzle works fine, I connect the MOSFET to the 12volt power supply with a common ground, use analog 1 to switch mosfet on and off. Now I wanted to run the arduino off of the same 12 volt power source, so I added another line from the positive end of the power jack to the VIN pin in arduino.

This is when I started having issues, ranging from the arduino not executing the code when the puzzle is complete, or just straight out frying. Went through two nanos.

I've been able to run an UNO of a 12 volt power supply, but not sure why the nano is having issues.

Use an external 5v regulator (linear if current is fairly low, or buck converter otherwise - suitable buck (step down) converters are a dollar or two on ebay), the one on the nano is only suitable for running the nano itself with nothing connected to it, and even then with 12v input, only barely. I think some of the nano clones use regulators even less suitable than the official ones, but even the official ones have a regulator that is not good enough for any real application with 12v input. With 7v in, it is usable in low current applications, barely. With 12v, drawing almost any current will overheat the regulator

DrAzzy:
Use an external 5v regulator (linear if current is fairly low, or buck converter otherwise

Any recommendation for one?

I would also suggest a flyback diode across the electromagnet.

MarshaJ847:
I would also suggest a flyback diode across the electromagnet.

I would connect this between the Positive and negative or the magnet correct?

Yes, band toward positive side.

As for regulator recommendations - 1117-series for linear (that's what the Uno uses), or just search dc-dc step down on ebay for cheap buck converter (pololu has nicer but more expensive ones)

DrAzzy:
Yes, band toward positive side.

Is a 1N4004 Rectifier Diode 1A 400V good for a fly back diode?

IN4004 is fine .