What happens if you replace the relays with LEDs?
or
if you disconnect all relays an add a serial print at each place where a relay is switched on/off ?
Does it work then?
The behaviour of your device sounds like there is a hardware-problem
Too big current drawn by the relays
electromagnetic noise or maybe even electric transients causing the microcontroller to crash.
So it will be crucial to post a schematic.
Free hand-drawn with pen an paper an then taking a picture with your smartphone to get the "analog" drawing digital is totally sufficient.