Electronic – arduino – Atmega328p resets and crashes when powering up solenoids

arduinoatmegaflybacksolenoidsolenoid-valve

I'm having problems with my PCB board based on atmega328p microcontroller (very similar to an Arduino standalone board).

This is my current PCB schematics and Eagle board.

SCHEMATICS UPDATED!

enter image description here

I use connectors on VSX, VDX, MOT1A, MOT2A, MOT2A, MOT2B to switch ON and OFF solenoid valves (the valves are rated as 12VDC, 2A at max).

The board works randomly fine only for few seconds or minutes until the micontroller crashes or resets and I think this happens due to solenoids noise.

The main power is 12VDC, 35A (used for the valves and the relay) and then I use a 5VDC voltage regulator to power on the atmega328p.

As you can see, I already added flyback diodes across each mosfet, but may be this is not enough to prevent solenoid noise. I also twisted each couple of wires (maximum wire length is 90 cm) which connect the valves pins to VSX, VDX, MOT1A, MOT2A, MOT2A, MOT2B connectors and I added an additional diode in parallel on each valve pins.

How can I solve the problem?
I was thinking to add 100nF ceramic caps between VCC and GND and AREF and GND and AVCC and GND as close as possible to the microcontroller pads and another 100nF cap in parallel on each valve pins.
Do you think it can be enough to solve the problem?

Unfortunately, I think I can't separate the solenoid power source from the atmega328p power source since they are currently sharing the same GROUND.

What can I do to solve the problem by continuing using the same PCB board?

Best Answer

Cut that trace running up from pin 22 and jumper it directly back to the middle pin on the 7805 with a fly wire.

Add a 10uF X7R or X5R cap directly between pin 7 and 8.

Make the layout better next time or use a 4-layer board.