Arduino project frying atmegas

Hi.
I'm new to this forum so hello to everyone! :slight_smile:
Recently I started making my little access control RFID Arduino project.
I had everything wired up and tried to use it. It worked, so I unplugged my Uno and started cable management. After a few plugs and unplugs, my Arduino stopped responding. The "L" led was still, wasn't blinking on start and I couldn't load up any sketch to it. I tried rescuing it but I got the avrdude error.
I went ahead and bought a new atmega 328p, burned a bootloader onto it and uploaded a sketch.
It worked flawlessly but only for a few minutes. I plugged it back after I got my cables managed and the new atmega also stopped responding. The same issue, the rst button does nothing, you can't burn a bootloader to it and the fuses are empty. Do you know what might be the issue? Only the mosfet was laying loose, but it was in shrink tubing so it shouldn't short anything. Here's "my" code and wiring:

Also, I'm using original Arduino Uno R3.

My guess is that the MOSFET is wired incorrectly (ie, wrong pinout used), and is in a configuration where the body diode is applying 12v to the arduino pin (ie, what you think is the gate isn't). Instantly killing the '328p (unusual in and of itself - we get about an order of magnitude more reports here of the 16u2 serial adapter chip on official arduino uno getting damaged vs the '328p) like that requires something pretty dramatic, like applying a voltage greater than Vcc or lower than ground to a pin.

Also - are you plugging it into USB while its connected to external power? Some people report that that causes potentially damaging glitches on Vcc (though this usually takes out the 16u2 not the '328p)

I'm unplugging 12v when connecting USB, also i forgot to put it in my scheme, but there's a 10k pulldown on the mosfet.
Is that possible, if data wires short (like pin10,12, 13) to kill the atmega?
The "kill of the atmega" happened when the 12v mosfet wasn't even activated. It just happened when i plugged the 12v in.

Olafkr:
Is that possible, if data wires short (like pin10,12, 13) to kill the atmega?

Not that quickly - if you've got the pins as outputs, and they're shorted to eachother or the opposite power rail, it can cause excessive current draw, which can eventually result in the pin failing. But brief shorts are a common occurrence in hobby electronics, and as long as not shorted to a voltage higher than Vcc or lower than ground, and don't result in instantly trashing the chip like you report. That requires something a lot more dramatic. Now, if any pin was shorted to the +12v, that would do it.

Olafkr:
The "kill of the atmega" happened when the 12v mosfet wasn't even activated. It just happened when i plugged the 12v in.

That it happened when you plugged in the 12v suggests that somehow, +12v is reaching the '328p.
That is the sort of extreme abuse that will instantly trash the chip.

The fact that the serial adapter on the board is still functioning indicates that it's not getting there through the 5v rail via a damaged or defective power supply circuit on the arduino, as that would trash the serial adapter too. That leaves an I/O pin being exposed to +12v as the remaining plausible cause. I already told you that I think it's coming through the "gate" of the mosfet, due to a damaged mosfet, wiring error, or damage to wiring from handling, none of which depend on trying to switch the mosfet. Could also be a short of a +12v wire to an I/O pin somewhere else, but that seems less likely.