I'm a hobbyist, trying to instrument my heating system so that I can control a three position valve. I have an ESP8266 integrated with a DRV8825 stepper motor controller, and a no-name Chinese 220vac mains detection module with three independent channels. On the bench, everything works perfectly, and I can read the state of 220vac signals that I connect to the detection module, and drive the stepper motor appropriately. Unfortunately, when connected to the actual heating system, I find that the wires I wish to monitor (which run around my house before reaching the heating system) have capacitively coupled voltages on them (up to about 20vac) that cause the detection module to give false positive readings. Rerouting the wires to reduce the coupling voltages isn't possible (they're mostly buried in walls), so I'm looking for any suggestions on how to overcome those false positive readings in the detection module; I've reverse engineered the circuit of one channel in the detection module, see below, and would appreciate any help: 220vac detection circuit to interface with a microcontroller via an optocoupler

  • \$\begingroup\$ Can you add a dummy load so that the capacitive coupling does not matter? \$\endgroup\$
    – Justme
    Commented Feb 25 at 20:10
  • \$\begingroup\$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. \$\endgroup\$
    – Community Bot
    Commented Feb 25 at 20:12

1 Answer 1


You need to reduce the sensitivity of the mains detection module. This can be done by attaching a resistor across C1.

If we assume that the zener is dropping the voltage to 5V and that the opto coupler is drawing 20ma a value of 1k will divert 5ma. Those assumptions may not be correct and you may need to experiment with the resistor value but it is a starting point.

  • \$\begingroup\$ Thanks Roy, that's exactly the kind of help I was hoping for. The voltage actually doesn't seem to be limited by the zener. I'm only seeing around 2.75vdc at the zener when the lines are in the off state, and 3.05vdc when there is 220vac applied to them. But I assume your method still stands - divert some current away from the optocoupler with a resistor until the false positives stop, but the real positives still register? \$\endgroup\$ Commented Feb 25 at 20:37
  • \$\begingroup\$ @RichardAppleby Assuming the LED and optoisolator are OK, the zener will be useless. But you also don't know which zener it is. Even if it is a 5V1 zener, it needs 5mA through it to reach 5.1V \$\endgroup\$
    – Justme
    Commented Feb 25 at 20:43
  • \$\begingroup\$ Won't R4, which is 150K in series with one AC mains input wire, limit the available current through the diode bridge in the mains detection module to less than 20 mA? \$\endgroup\$ Commented Feb 25 at 20:48
  • \$\begingroup\$ I can at least confirm that the LED and optoisolator are apparently working :) The zener is an unknown, but I hope I can still use my measured voltages at the zener and apply ohms law to calculate resistances that will move current away from the optoisolator until it doesn't register the false positives... \$\endgroup\$ Commented Feb 25 at 20:56
  • \$\begingroup\$ Just a quick follow-up. This answer by @RoyC solved the problem perfectly. It transpires that a 6K2 ohm resistor is perfect for removing the false positives while still giving good registration of the true positives (so far, at least!). Many thanks for the assistance everyone! \$\endgroup\$ Commented Feb 26 at 14:22

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.