Hi there,
I have a PCB that has relays to turn on a pump motor, some electrovalves and a heating element inside a water heater. To detect the water level inside the water heater, I have a simple AC detection circuit that I copied from another PCB:

The ground of my circuit is connected to earth because the water heater is connected to it as well. However, here's the issue: When I turn any of the electrovalves (230VAC) or the water pump, there's high frequency noise on the power rails. The microcontroller was resetting and going into some weird states on those ocasions. I tried adding some 11pF capacitors in parallel with the capacitors on the voltage regulators, which dampened the effect but the microcontroller was still going crazy sometimes. After removing the earth connection, the water level detection doesn't work but there is no more noise on the voltage rails and everything is back to normal. How do I stop this ? Does adding a ferrite bead with a roll off frequency well above the PWM frequency be enough for this ? And how do I even choose the specifics of that ferrite?