USR-ES1 stops working after switching 220volt line


I'm trying to develop some hardware/software project using ESP32-DevkitC-V4 board using wired ethernet connection. For the wired ethernet connection I'm using USR-ES1 board which is based on the W5500 chip. I have one board with the ESP32 and USR-ES1 boards. I'm using one of the GPIO lines to control a relay that switches a lamp. The switching electronics is on a separate board that uses a separate power supply. Following is the schematic diagram for my project:

Everything is working well until I switch the lamp. When setting the control line to low (zero), the lamp is switched off and together with it the USR-ES1 stops working. This happens almost every time. What can be the casue for it?

More information on the above question: If I'm not connecting the lamp everything is working fine. That is, I'm leaving everything as it is, the relay is switched, but the lamp is not present in the circuit, everything is well.
I also tried to put capacitors on the 3.3V line and it doesn't help.

Is your mains 5V power supply filtered? I think you have mains transients sailing straight through it (this would happen if its a cheap and nasty supply for instance)

You should be using mains protective earth too, a 2-pin power supply is always bad news.

If your 'lamp' is not an old incandescent type, then a snubber circuit across the relay contacts is likely needed.

1k base resistor should be a lower value if you want to switch a relay reliably.
Base current should be 5-10% of collector current for saturated switching (Hfe does not apply here). A typical value is 470 ohm (510 ohm on common relay modules).

Try adding a base/emitter resistor in the 5K - 10K range. It appears to me your coupler is getting a transient that is causing your problems.

There were several threads on this forum asking why the relay contacts welded together when using CFL light bulbs. A slow switching relay and not using a snubber circuit could contribute to that.