ATMEGA328P standalone sketch doesn't work as expected
The relays , wiring radiated emissions and conducted noise cause this classic failure to recognize need to clamp dI/dt of the relay coil and any inductive loads to the supply rail.  Diode clamps and twisted pairs are essential.  So are details of the above missing in your question.