I have a simple ESP8266 circuit that detects as pulse when a reed switch is open or closed - nothing fancy. I have anti-bounce code configured and everything typically works as expected.

Hopefully the picture I have drawn and attached works to explain the full story.

Note: The garden reticulation circuit has nothing to do with the NodeMCU circuit other than using the same mains 240v mains power supply.

The problem I have is that there is a 24v AC (500mw~) cable as shown in red in my attached diagram about 6cm away and then in parallel for approx a 15cm length from the leads that make up the reed switch. This is creating a lot of false readings in the ESP8266 circuit when the 24v AC becomes energised.

I tried a 10 nF Capacitor (103) and it stopped the false readings for a few hours and then didn't, I suspect the capacitor was maybe too small for the job, overloaded or unsure... Or, maybe there is some weird ground or similar induced loop noise / harmonics in the circuit as they are connected to the same mains supply.

I'm open to figuring out how to calculate what size capacitor I actually need, or maybe another option.

I also considered an optoisolator for the reed switch but that would mean I need to put a battery near the reed switch for that side of the optoisolator to work, but i just want to run this simply of the USB 5 power power adaptor.

Moving the cables away from each other is not really an option as they are penetrations through an existing brick wall and not so easy to move..

Full layout

  • \$\begingroup\$ Try 100 nF down to real ground on the negative output of the 5 volt supply. \$\endgroup\$
    – Andy aka
    Feb 23, 2020 at 14:47
  • \$\begingroup\$ Did you write the software for the MCU? What is the required response time of reed switch sensor? If a short delay is acceptable, add a simple digital filter. For example, N consecutive samples (every few mS) at a new state are required before the new state is accepted. \$\endgroup\$
    – Mattman944
    Feb 23, 2020 at 15:25
  • \$\begingroup\$ @Andyaka - ok will do. I'll head to the local electronics store in the next couple of day and grab a pack - thanks! \$\endgroup\$
    – marcu5
    Feb 24, 2020 at 10:00
  • \$\begingroup\$ @Mattman944 , yes. I have allowed for 4 pulses per second max in the code and store that reading and every 60 seconds transmit the sum. The sum is right up there around 240 to 250 pulses per minute which the actual reed switch (source of the pulses) is not capable of in the deployed scenario. Changing that to only accept one pulse per second would then mean a high potential for inaccurate data. The pulses are sometimes constant and sometimes not in other words unfortunately. \$\endgroup\$
    – marcu5
    Feb 24, 2020 at 10:03

1 Answer 1


Filters are usually voltage dividers.

A voltage divider has series and shunt components.

Your capacitor is the shunt.

Now insert an overt series impedance: 1K ohm resistor, or 1 milliHenry inductor.

And ..... you must ground the capacitor at the MCU gnd pin at the IC package, or on the ground plane near the MCU.

  • \$\begingroup\$ for clarification, where would I be looking to insert the resister in my diagram? And thanks for the heads up on the grounding! \$\endgroup\$
    – marcu5
    Feb 24, 2020 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.