How to improve atmega328p board for solenoids control
I faced a similar problem when using a relay circuit to actuate pistons. The back EMF generated due to the actuation of the piston would short the control circuit thus resetting the micro-controller.

I would recommend adding a Optical Isolation feature to the circuit. Opto-Isolators such as ILD1, ILD2, ILD5, ILQ1, ILQ2, ILQ5 are cheap,small &amp; come in DIP Packages .


Signal information, including a DC level, can be transmitted by the drive while maintaining a high degree of electrical isolation between input and output.
The ILD1, ILD2, ILD5, ILQ1, ILQ2, ILQ5 are especially
designed for driving medium-speed logic and can be used
to eliminate troublesome ground loop and noise problems.
These Isolators will protect your microcontroller &amp; control circuit from the back emf generated by the actuation.
These couplers can be used to replace relays and
transformers in many digital interface applications such as
CTR modulation.