Increase voltage drop required to saturate PNP BJT to avoid noise

I have this circuit which must signal +3.3V or 0V depending on the switch status. The the switch is about 20 meters away and is getting EMI from mains.

I realized that it only takes -0.7V of interference on Vb to make the transistor saturate causing a false switch pressing event on my ESP.

How can I increase this gap in say 2 or 3 volts so it becomes less sensitive to EMI?

I thought of series diodes on base like this (which is cheaper than shielding the cables) but is it correct?

• Welcome to EE.SE! Feel free to edit the pictures in line with your text. Even better, please use the built in schematic editor here by clicking Edit and then on the schematic symbol. – winny Feb 27 at 14:54

By re-arranging the resistors you can make the PNP much less sensitive to EMI on the switching nodes:

simulate this circuit – Schematic created using CircuitLab

How does that work?

R2 and R1 are a voltage divider so any disturbance on the wires to the switch is attenuated by R1 and R2 (and optionally C2) making it much "harder" for the EMI to open the PNP transistor.

Optionally you can add C2 to suppress EMI even more if needed.

Do keep R1 and C2 close to the transistor.

What also might help is twisting the wires to the switch:

• Thank you very much! Is C2 Poliester? – Alexsander Magalhães Feb 27 at 15:36
• You can use any type you like, including polyester cap. for C2, if C2 is a polarized capacitor then make sure the "+" side is at the +12 V and the "-" at the base of Q1. – Bimpelrekkie Feb 27 at 15:39
• I simulated your circuit and now Im wondering: If I get from EMI say 14V at the switch, it would result in exceding +625mV at the PNP base, right? Wouldnt this exceding voltage try to run accross C2 to the source, and if C2 is polarized wouldnt it break? (Im asking because I only have polarized ones left) Thanks again. – Alexsander Magalhães Feb 27 at 16:00
• I'll simply buy more polyester, thank you very much again for your solution! – Alexsander Magalhães Feb 27 at 16:08
• If I get from EMI say 14V at the switch If you would reach that you're doing something weird like running the wire to the switch through an MRI scanner! And no, 625 mV is not going to damage any polarized capacitor. To break a pol. cap. you need to apply more than about 1 Volt DC in reverse and for a long time. Even pol. caps. are not that fragile. – Bimpelrekkie Feb 27 at 17:00