Arduino resetting/hanging due to sparks in ac line
You should respect your voltage isolation. The way you have placed (and routed) resistors R16, R13 R10, R2, R31, and R4 compromises the isolation barrier created by your opto-isolators. Below I have marked your existing layout with your isolation path, which is fairly poor:



Have a single isolation zone that is as wide as possible (the width of your opto-isolators). Keep line circuits on the line side, and isolated circuits on the isolated side. See image below for suggestions.