I want to read the state of a normally closed switch (waterlevel sensor) with a MCU. The NC-switch is connected over two about 20 meter long cables. The MCU wakes up periodically and enables a external pullup (R5) and reads then back the signal on a GPIO input pin. The pullup is switched on by a transistor to minimize the idle current. The schottkey diodes and the series resistors are for protection against external induced voltages.

Will this circuit work? If the switch is opened one wire-end will float most of the time when the pullup isn't active while not reading the state...Is this a problem?

Thank you for any comments on this.

schematic low power reading NC switch


You are already using a 1M pull-up... how low current do you want to go?

That is also a wonderful antenna you have which is why I assume you have that 10nF cap in there.

You are aware the charge up RC time is 10mS right.

You need to do the math and see if the current drop you gain by switching outweighs the current you lose by staying awake long enough to let that settle. Which I doubt.

As for the floating part, since you protected it with diodes you should be ok though providing a discharge path for the cap would be prudent.

Personally I think something more on these lines would be more prudent. Use the output pin to drive the line directly and sense with the other. Also adds the benefit that you can modulate the output if need be to detect it is really the wire and not a short somewhere.


simulate this circuit – Schematic created using CircuitLab

| improve this answer | |
  • \$\begingroup\$ oh that's a mistake from the previous sketch/version without the transistor. With it i would choose R5 in the Range 10K... \$\endgroup\$ – wildcard Mar 20 '17 at 18:40

The MOSFET... can be safely removed. You can drive your Pullup directly from a microcontroller output pin instead of using a FET. The load doesn't draw enough current to justify an external FET.

You can also use an internal pullup (switched on/off) instead of an external one, saving a pin.

Making R1 higher will provide better protection against EMI, ESD, etc.

BAT54 has about 0.5-1µA leakage at your low voltage . Decide if this is bad for your battery life. If so, use standard diode (not Schottky). Thanks to R4, current which can flow into input pin is quite limited anyway.

1Mohm pullup makes me uneasy. Slight humidity along the wires would be sufficient to leak a few µA, making your micro believe the switch is closed.

Also, 1Mohm * 10nF will need a long time to settle. If you really want to conserve power, you'll need to put the micro back to sleep while you wait for it to settle...

Here's my proposal.

The amount of charge you'll consume is what is needed to charge C2 up to a voltage which the micro reliably reads as a "1", let's say 3V * 10nF = 30nC.

Here's my solution:

  • Remove MOSFET, remove R7
  • R1 = 1k
  • Set C2 to 1nF, and put it in parallel with the diodes for better EMI filtering
  • Replace R5 with 33nF capacitor
  • Set SW_EN as output, driven to GND

To query the sensor:

  • Set SW_EN to HIGH. This allows the 33nF cap to send a pulse into the cable, and charge C2. If the switch is open, C2 will charge to 90% VCC. If it is closed, its voltage will quickly decay back to 0V.
  • Wait 500µs (TBD)
  • Check GPIO_IN
  • Set SW_EN to LOW
  • Go to sleep

This consumes 100nC on each check (charge in the 33nF cap under 3V), so if you check 10 times per second, it is 1µA.

The current sent through the cable will be quite high (a few mA). This should be enough to overcome any leakage due to moisture.

You can also use a resistor instead of a 33n capacitor, but then you'll need to compromise on the input protection resistors.

| improve this answer | |
  • \$\begingroup\$ nice thoughts. very much like the idea of charge transfer. thank you! \$\endgroup\$ – wildcard Mar 20 '17 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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