Arduino UNO-CH341 keeps resetting randomly
Welcome to the wonderful world of EMI, and why real industrial-hardened PLCs cost much more than the limited processing power might suggest.

Add series resistors on each digital output line and on the analog input line. Maybe 4.7K on each (except the LEDs, keep them within the box if possible, and the relay drive lines, which are  probably opto-isolated).

Connect the power supply negative to earth at one point.

The shield on the sensor line should be connected to the housing at the point of entry. And there should be a shield.

Assuming your relay board is opto-isolated (as in the below schematic), use a separate supply for the 5V relay coils, not the Arduino. Do not connect them together, either ground or 5V. Keep the wires well separate. This and the sensor lines are my guess for the main culprits.

Keep all the low voltage wires separate from the mains switched wires, at least 150mm where possible.