I use npn transistors to power the relays. The base of each transistor is connected to its port via a 4k7 resistor. There is a flyback diode on each relay. Also, I placed a 100µF capacitor on the circuit board to decrease ripple. Each relay draws a current of 40mA.
I will try resetting the Arduino as soon as the problem occurs again. Also, I'll try adding a second capacitor. Thank you for your suggestion.