Relay resets the atmega328p

Inductive loads need switching spike snubbing.

Show us a good schematic of your circuit.

Show us a good image of your ‘actual’ wiring.

Give links to components.