I'm having problems with my PCB board based on atmega328p microcontroller (very similar to an Arduino standalone board).
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?