3 Phase AC Motor controled by an atmega328pb
What you are experiencing is interference caused by ground. To reduce or eliminate the noise you could do the following:


Best option would be to have the microcontroller and Relays/other power circuitry not sharing power supply at all and have optical isolation. This would mean you have a seperate dedicated power supply derived from utility and you would not have a common ground/power supply then the one being used for your relays. Many high quality SMPS power supplies like laptop chargers have a lot of filters/noise management circuitry that would even run your micro-controller for a few seconds if utility supply is completely out.
Ensure that on your PCB, you are maintaining distance between tracks that contain Utility voltage, AC and then DC power supply.
If your operation is critical and should run 24hours, you may want to shift to a higher end processor that comes with a predesigned PCB rather then using a microcontroller on a bare metal PCB, this is because usually many such vendors provide higher quality PCB and onboard power power noise management that leads to less chaotic problems like the one you are facing. You may want to explore Prebuilt Atmega32 kits or an ESP32 kit or Raspberry Pi if your budget permits.


I hope this helps.