the long wires acts as inductor which shutdown and sometimes damage my microcontroller(IC1), for the AC part ill be implementing an optoiso along with triac and snubber circuit (lemme know if you have a better idea) but the SW1 is the part where i'm stuck, usually in simulation they turn the wire into inductor to add the diode (with resistance or zener) parallel to it but in this case i'm kinda lost of to how to snub that switch in addition ill be adding a low path RC filter as suggested in the answers, thanks in advance
The 100m wire from SW1 to pin 3 of IC1 acts as a long antenna that will pick up all sorts of electrical noise. Almost any electrical equipment nearby that switches current will induce a transient voltage into it, and the voltage can easily be 10's or 100's of volts. If you are unfortunate enough to have a thunderstorm nearby this can easily be 1000's of volts. Any voltage over about 6V can damage the IC, so you need to protect input to the IC. A simple RC low pass filter is surprisingly effective. I would use the following circuit. This will protect IC from damage, but will not effectively debounce the switch. You can do this in software.
I suggest to break up the problem in pieces as it looks like different (but perhaps related) problems.
Starting with BL1, you mention that it lights up very dimly. Let's debug this first, it might help with the IC burning out.
- When BL1 lights up dimly, it's when the relay contacts close. Right?
- With the relay contacts closed, can you measure and post a)the voltage drop accross the relay contacs, b) the Vout of V2 and b) the V accross BL1
- To be sure, also measure and post the voltage on BL1 when the relay contacts are open.
- Indicate with which type of instriment you measured.
- What happens with BL1 when you short the cable ends at the relay contacts?
This way we can analyze it further.