2
\$\begingroup\$

I'm working on a circuit board driven by a PIC18F; one of the components on the board is a water sensor. This is pretty straightforward, there are two electrodes on a probe; when immersed in water, there's enough conductivity to complete the circuit, and it pulls a pin high on the PIC. Below is a sketch of the relevant portion of the circuit. The electrodes are CN4-1 and CN4-2, the board is powered by a 3.6 V battery.

As it stands, it works as intended, but I'm seeing some undesirable behavior. The system is highly sensitive to anything touching the second electrode, CN4-2; I'm assuming this introduces stray charge to the system, and I can get a false positive detection (even if nothing is touching CN4-1, so the circuit is not completed). In particular, there's an LED that signals the presence of water, triggered by this circuit. If CN4-2 is touched by a conductor (either water or something else, like a hand), the I/O pin gets pulled high enough to trigger the LED, but in some cases just having the LED lit is enough to pull some current from the battery, letting the signal to the I/O pin get pulled low enough that it turns off again, and we end up switch back and forth between states. Tying the ground of the board to an external ground helps reduce this, but doesn't always eliminate it.

Reducing the size of the resistor pulling the pin low reduces these false positives, but then makes it hard for the circuit to pull it high when there's a legitimate signal. Simultaneously reducing the size of the resistor that pulls it high can fix that, too, but then the total resistance of the circuit is low enough that when the circuit is connected across CN4, there's a significant current draw, which will shorten the battery life significantly.

I inherited the board design, so I won't be offended if you tell me that there's a completely different way to handle this that would be better. I'm ideally looking to have the system very responsive to a connection across CN4, minimal power draw whether CN4 is open or closed, and preventing a false positive signal when only a single electrode has some contact. If it can be done without requiring tying the system to an external ground, that would be convenient.

Water Sensor Circuit

\$\endgroup\$
  • 1
    \$\begingroup\$ You need to define for your circuit some requirements like the range of resistance that is supposed to mean "water" and the ranges that are not. Also you should think about corrosion of your probes, you are essentially doing electroplating there. \$\endgroup\$ – PlasmaHH Oct 23 '17 at 15:51
  • \$\begingroup\$ Resistance is on the order of a few megaohms when water is present, and essentially infinite when not. The problems I'm specifically concerned with show up when only one of the two electrodes is touched, meaning that resistance across CN4 is still essentially infinite, but there's a source of stray charge in contact with CN4-2. Corrosion is a potential long term issue, but the normal state of the device is for water to not be present (the purpose of the device is to trigger an alert when there is water present). So corrosion is less of a concern that if it spent more time submerged. \$\endgroup\$ – Grey Oct 23 '17 at 16:43
  • \$\begingroup\$ You will need two BJTs for adequate hysteresis to make this workable, my opinion. And, I think, six resistors. \$\endgroup\$ – jonk Oct 23 '17 at 17:33
  • \$\begingroup\$ For a related answer that takes corrosion due to DC into account see this answer: electronics.stackexchange.com/a/77005/25328 \$\endgroup\$ – Tut Oct 23 '17 at 20:40
  • \$\begingroup\$ Jonk, any chance you could sketch out what you're thinking of so I can give it a try? \$\endgroup\$ – Grey Oct 24 '17 at 13:05
2
\$\begingroup\$

You could use this circuit instead. The capacitor on its input will filter out most interference and the PNP transistor will give better output voltage levels.

If it's still too sensitive to interference, increasing the value of C1 and/or R3 will help. If the water doesn't trigger it reliably, increase the value of R2. (The circuit will work for a water resistance of about 15MOhm in its current form)

schematic

simulate this circuit – Schematic created using CircuitLab

As with any circuit that puts a DC voltage across water, the electrodes will slowly corrode when submerged in water.

You could also design a circuit that measures the capacitance between two twisted, insulated wires sticking into the water, but that would need an oscillator and time measuring circuit. It's possible to implement this in the PIC but it would be way more complex and might also need more power. The main advantage of such a circuit is that it's even less sensitive to (conducted) interference and doesn't corrode the electrodes.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Seems worth a try. I note that the BC557C is listed as "obsolete", and my usual component suppliers don't have it in stock. Any recommendations on an alternate transistor there? \$\endgroup\$ – Grey Oct 23 '17 at 17:01
  • \$\begingroup\$ BC557 is a general purpose PNP. You can use any other general purpose PNP. \$\endgroup\$ – Janka Oct 23 '17 at 17:03
  • \$\begingroup\$ @Grey You can use pretty much any general purpose PNP transistor, as long as it has a DC current gain of ~400 or more (unless you want to play with the resistor values). Just use the BC857C, it's the SMD variant of the BC557C, or any other PNP transistor with h_fe > 400. (Edit: Had a typo in the part number.) \$\endgroup\$ – Jonathan S. Oct 23 '17 at 17:07
  • \$\begingroup\$ Sounds good. I'll give it a try. \$\endgroup\$ – Grey Oct 23 '17 at 17:13
1
\$\begingroup\$

Rather than fixing terminal CN4-1 to a +3V source connect it to an output pin which you can set high or low under your exact control. If water is present then the CN4-2 input pin should go active when, and only when, you pulse the +3V onto CN4-1. Toggle the +3V on and off however many times you choose and verify that the signal is transferring to the input pin exactly as expected, and never when it is unexpected.

| improve this answer | |
\$\endgroup\$

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.