The use of electromagnetic relays
When the contact is turned on or off, a large electromotive force will be induced at both ends of the coil. Without isolation, it is easy to introduce interference into other circuits on the board through the ground potential, causing the microcontroller to reset.
The coil control end is isolated by an optocoupler, and the power supply of the coil is isolated from the power supply of the board.
In addition, a freewheeling diode should be added to both ends of the coil (as explained later), which can be selected from commonly used 1N4007 or 1N4148, 1N5403, etc
An RC circuit with two contacts connected in parallel to remove sparks, where R is used to suppress short circuit current when the contact is closed and C is used to suppress discharge when the contact is opened.
The R value ranges from tens to hundreds of ohms, and the C value is around 0.1uf-0.3uf. It is best to conduct experiments first to select the optimal parameter values for specific application circuits.
Electromagnetic relays will definitely generate radio frequency interference, but it is only a matter of interference size. After taking sufficient measures in the relay circuit itself, it is necessary to enhance the anti-interference ability of the board (both software and hardware should consider anti-interference measures). If the interference is severe, shielding measures should be considered