Water leak detector schematic opinions (Comparator talk) - Page 1
Forum section: electronics / projects

author: Dannyx
author_rank: Regular Contributor
timestamp: August 18, 2024, 08:06:00 pm
content: Good day folks. I'm currently working on a water leak detector I want to attach to my alarm system. Yes, yes I know: there already exist thousands of pre-built ones out there, but that's not really my style. I want to KNOW why it works and what better way to learn about it than to design it myself.TL;DR: I'd like some (expert) opinions on the schematic I came up with. Not all the components have values yet because I have not yet prototyped it to know what they should be - I make stuff up as I go along. Not sure if the two caps I marked in red should be there or not and if they should, I was just going to go with a low-ish value, since I don't know enough about comparators to drill down into the really fine details like that....plus I don't have a scopeFeel free to comment on the schematic and the points below.The thinking behind it: this thing is going to be powered by the "bus" of the alarm panel, since I don't want additional wall-warts and wires hanging around. This "bus" is not terribly stable and gets worse when the panel loses AC power and runs on the backup SLA battery, because the battery voltage drops over time, so I knew I needed some LDO there. The "bus" sits between 14.5v when powered by mains and roughly 10.5v before the panel shuts down - this is my "12v_UNREG" in the schematic.For my LDO, I chose theMCP1826. Like I said, I'm no professional, so don't ask me why I stuck with this one specifically. The supplier I frequently buy parts from carries it, for one thing, and second, I noticed it had a fairly low tolerance and quiescent current....so it went in my shopping cartI don't have the skill and equipment to put it through its paces, so perhaps someone will comment that it's absolute garbage for the job and I should go with X/Y/Z instead - that IS the point of this threadWith my "5v_REG" sorted, it was time to get some comparator action happening.Again, at semi-random I went with aTLC3702. I knew I wanted a push-pull comparator, preferably in DIP form so it's easier to work with, so this one popped up. I must admit I don't know much about the vast world of comparators, but I do at least know "the basics". I know I misrepresented the symbol U1 there: by nature, the N/I input is at the top, but I realized I made an error in the working principle and it was too late to flip the whole schematic around, so I just flipped the signs instead....sorryI used 2 resistors and a trimmer (R1, R2, R3) on the inverting input to create a reference from my 5v rail. By my calculations, this should allow me to swing between 4.-something-v when fully CW to 2.1v when fully CCW. Hope I did it right and the comparator input is happy with this setup. Again, not sure if C3 is of any use there.With my reference point now set (and adjustable), the actual part that will be doing the "sensing" is all that nonsense at the bottom: using another voltage divider (R5 and R6) I set up a voltage of 3v, which I then send to the N/I input. I then got myself an electrode grid off Aliexpress which looks pretty much just like that washboard I drew thereBy itself, when dry, it doesn't do anything - it's completely open-circuit. When something bridges the small gaps between the traces, say a liquid, it starts acting like a resistor - self-explanatory. I attached this in parallel to R6.I adjust the trimmer R2 so the reference at the inverting input is sitting at just a little over 3v, so the output is LOW because the N/I input is 3v. Now, when liquid makes contact with the grid, it's going to connect "RGrid" in parallel to R5 which makes the voltage at the N/I input rise by some degree, until it eventually goes higher than the Inverting input, so the output goes high. R4 provides the all-so-important hysteresis so the thing doesn't chatter, but I haven't figured out what value it should have just yet...Would this work ?Cheers.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 18, 2024, 09:27:35 pm
content: You don't really need a regulator. Just a simple comparator circuit with hysteresis would be enough. Your circuit has negative feedback which doesn't really make sense here. A comparator circuit with with positive feedback (hysteresis) is what you're looking for. Your relay coil needs a diode across it for back EMF suppression when Q1 turns off.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 19, 2024, 09:50:44 am
content: Indeed, I was planning to build this thing straight on the "bus" Vcc, (with a comparator that can actually take 12v, since this one doesn't), but then I discovered this wouldn't work as expected. The reason I went with a regulator is because unless the input voltage remains completely stable, the reference voltage (and thus hysteresis) shifts up/down with the voltage, which makes sense, since a voltage divider is directly affected by its Vin.Taking a look atthis article from TI, equation 7 on page 21 confirms this: if I crunch the numbers and leave all the values untouched EXCEPT the value of Vcc, the VL and VH values shift up and down, which I WAS expecting, but they don't do so "symmetrically". If I use a VCC of say 5v and use the values TI provides in the example above (page 7, eq. 1), I get 2.3v and 2.7v for VL and VH respectively, so they are 0.4v apart (0.4v of hysteresis). Now if I change 5v for say3vand run the formula on page 21 again, I get 1.38v and 1.67v for VL and VH respectively, so the hysteresis is no longer 0.4v - it's only 0.24v. Likewise, if I do the opposite and increase VCC to 10v, I get a "wider" Vhyst ! I was expecting the hysteresis to always stay the same relative to VCC, given the resistors are always the same, but it turns out it doesn't and the numbers don't lie. This is also backed up by the fact that I tried this setup on my bench before and if lower the input voltage on my power supply enough, the comparator eventually triggered the relay with nothing touching the grid and now I know why.Initially, I had the reference at the top on the N/I input just like you said, but that meant the comparator's output would stay HIGH when "dry" and go LOW when "wet", so short of using a PNP transistor, I thought the simplest thing to do was to just switch the inputs around. Is that a good idea or is there more to it ?Yes, I know about the diode, I simply forgot to draw it in.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 19, 2024, 01:49:54 pm
content: You're over thinking it. You really want to compare the resistance of your moisture pad with a reference resistance. We don't really care about the voltage, as long as it's within the limits of the comparator.A jelly bean OP-AMP like LM358 will work all the way up to 32V on a single supply.For example, the "RM resistance" trigger points are the same no matter if Vcc is 5V or 15V:

author: Dannyx
author_rank: Regular Contributor
timestamp: August 19, 2024, 02:59:15 pm
content: That IS indeed how I started this project (except I had the reference adjustable with that trimmer), but I went down this rabbit hole because I kept discovering potential flaws.I assume RM in your schematic refers to the sense pad ? If so, this means that, when dry, with RM being infinite, the Inverting input is pulled up to VCC at all times, keeping the output LOW. When RM starts conducting, it causes the voltage at the Inverting input to drop more and more until it hopefully goes lower than 1/2 VCC. This makes sense, but I have two questions/issues:1) the N/I input is "fixed". This means the circuit might react differently depending on the type of liquid - is it more or less conductive ? Wire length to the pad might also affect this. This is where my idea to make that ref adjustable came in. I assume there aren't any issues with that.2) Going back to my original issue: I too ASSUMED VCC wouldn't matter because both dividers would drift/up down at the same time and I was just about ready to roll with that, until I noticed that doesn't quite happen in real life (or I'm doing something wrong) and stumbled upon that article and did the math ! I mean everything about me tells me that's how it should be - it's jut two bloody resistors on each side ! - but who am I to argue with the guys who conjured up those formulae

author: selcuk
author_rank: Frequent Contributor
timestamp: August 19, 2024, 03:13:13 pm
content: Don't you need to use alternating current to prevent electrolysis on the sensing element?

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 19, 2024, 03:43:49 pm
content: 1) If all you want to know is if there is a water leak, then make the input sensitive enough to trigger on the types of liquids expected. (Experiment with pad before building) There is no need for super precision here.2) The only way I see Vcc voltage influencing the "pad resistance trigger point" is because the OP-AMP's (Or comparator's) output does not go 100% rail to rail. Again, this slight variation shouldn't matter.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 19, 2024, 04:13:53 pm
content: Quote from: selcuk on August 19, 2024, 03:13:13 pmNo, not really. It will not be submerged in liquid all the time - only if there's a leak or slight puddle around it. Second, the two parts of the grid are made of the same material, so I doubt there would be corrosion even if it WERE submerged 24/7.Quote from: Kim Christensen on August 19, 2024, 03:43:49 pmTrue, but I like to start with a simple idea and over-engineer the hell out of itAs far as the math is concerned, your example does confirm one part of my "discovery": the hysteresis (in volts) DOES drift up/down with input voltage. In the 15v example: 8.1v-6.9v=1.2v of hysteresis, whereas in the 10v example 5.4v-4.6=0.8v of hysteresis. It may not be that important in this application, but I assume it would be relevant in others.I was going to use a LM393 and a PNP transistor in my original idea.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 19, 2024, 05:36:18 pm
content: Thanks for the schematic. I revised mine as well based on it, since I quickly figured out that my setup was not going to work, since I was messing with the ref. voltage on the N/I input, which meant that every time I altered that trimmer, the math would go all over the place because Rh stayed the same.I still wanted to be able to adjust the threshold when the thing trips, so I moved R adj. down by the sense pad. The thinking behind it is that if the grid appears to be too sensitive, you turn the trimmer towards the Vcc rail, which causes the whole voltage divider to shift towards Vcc and "away" from the trip point. Conversely, if it takes toomuchwater to finally trip, you turn the pot towards the grid itself (towards GND), which causes the voltage on the divider to drop, based on the minimum possible resistance of the pad (which I haven't measured, TBH).Not sure how all of this is going to play out when the pad is across, say, 4-5m of wire....

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 19, 2024, 10:35:53 pm
content: You can add a lowpass filter to help suppress any noise picked up by the longish wires. You don't need/want a capacitor at the junction of R1 and R2.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 20, 2024, 08:24:50 am
content: That's good.I see you made the trimmer a 1 Meg, which is WAY above what I was expecting. True, I'll have to experiment to see what happens. If it's too low a value, it won't do much either.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 20, 2024, 02:57:50 pm
content: The 1 Meg comes from my own over engineered water alarm, complete with microcontroller.The probes for that were a pair of 3mm stainless machine screws about 3-4cm apart. Your PCB sensor may be more sensitive than my setup.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 20, 2024, 03:06:01 pm
content: I would've gladly gone the micro route myself, but I figured that would be too much. Just out of curiosity: what micro DID you use ?Second: I got tired of crunching numbers, so I put together an Excel to do my bidding

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 20, 2024, 04:19:53 pm
content: Used a PIC12F675 (8 pin DIP) because I had a bunch in the drawer. Plus I had some unprotected Lithium cells, driverless piezo buzzers, a desire to mess with Kicad again, and try out getting PCBs made at JLCPCB.So the PIC does it all and sleeps 99.9% of the time. Detects the voltage drop (water), checks battery level, drives the piezo, etc.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 20, 2024, 04:49:08 pm
content: Always wanted to try PIC but never got into it, so it's a foreign language to meI've been in the Arduino ecosystem all this time.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 20, 2024, 07:23:45 pm
content: If you're already into Arduino, you could use an ATTINY13 or similar. I simply used PIC because that's what I have the tools for and am already familiar with. Nothing wrong with using some other small MCU that fits the task.Or just stick with your simpler comparator version. Usually, keeping it simple is the way to go anyway.

author: Zero999
author_rank: Super Contributor
timestamp: August 21, 2024, 11:49:43 am
content: Quote from: Dannyx on August 19, 2024, 04:13:53 pmThere would be corrosion if it were submerged 24/7, even if the two parts of the grid are made of the same material. Electrolysis doesn't need dissimilar metals. It will work with two conductors made of the same material. I believe carbon is often used, rather than metal, because it corrodes less, but I know, that's not what you're trying to do and yes, if it's not submerged for long periods i.e. this is just an alarm, then don't worry about it.QuoteWhat's wrong with that?Note, that the supply voltage doesn't matter. As you said in another post, the voltage on all of the dividers varies, with the supply voltage, so it cancels it out. Here's a simulation. The resistance for the on threshold is about 500k and off threshold just under 2M, irrespective of whether the supply voltage is 5V or 20V.The MCP1826 is a bad idea because it's only rated for 6V in and will smoke at 12V.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 21, 2024, 12:35:24 pm
content: Quote from: Zero999 on August 21, 2024, 11:49:43 amAh yes.....let the f-ups begin...that's strike #1....No idea how I missed that....must've been so focused on the output voltage I forgot to check the input...Quote from: Zero999 on August 21, 2024, 11:49:43 amI see you made a couple of changes to my schematic: if I understand it correctly, you went back to my original idea of having the sense pad on the N/I input as R_water and the reference on the Inverting one, lik. Second, you moved R4 (the feedback resistor) to the transistor's collector and made it much larger. I haven't done any number crunching yet, but since R2 and R3 are identical, the reference is going to be Vsupply/2.Like I said, it made perfect sense from the very beginning that the numbers should stay the same regardless of Vcc, but the math says otherwise (at least on paper !), which is what sparked up this whole dilemma in the first place, otherwise this would've been in operation by now.What software is that ? LT spice ? I used it once and WAS going to run a simulation myself but completely forgot how to do it and wasn't feeling like watching tutorials again

author: Zero999
author_rank: Super Contributor
timestamp: August 21, 2024, 04:19:08 pm
content: Your calculations must be wrong, if they show the supply voltage affects the resistance threshold.Yes, I used LTSpice. I didn't look at your schematics, just threw some component values in there and ran the simulation. There isn't anything magic about a simulator. It's just performing calculations.Forget the feedback resistor for the moment. Say there are just three resistors. If R1 = R3, then the threshold resistance at which the circuit switches is simply equal to R2.Here's a simplified schematic, with an idealised comparator model (just an op-amp with a large gain and rail-to-rail output). The threshold is 1.5M in this case. The simulation is even simpler than the one before because it just looks at the steady state, not transient, by calculating the voltages at different parts of the circuit for different values of R_in.Also note that it's the ratio of R1 to R2 which determines the threshold.Comparator resistance threshold.asc(1.23 kB - downloaded 42 times.)Now if we go back to the feedback resistor, we can see that when the output is high, then R4 is in parallel with R1 and when the output is low, it's in parallel with R2. This shifts the threshold from 500k to 2M, depending on the output state.Comparator resistance threshold hysteresis.asc(1.63 kB - downloaded 22 times.)

author: Dannyx
author_rank: Regular Contributor
timestamp: August 21, 2024, 04:31:19 pm
content: Quote from: Zero999 on August 21, 2024, 04:19:08 pmYes, they do ! I'm so glad you brought it up again, because that's what I've been trying to understand myself from the get-go, as it overthrew everything I THOUGHT I had already figured out !You probably missed it, but I linked toTHISarticle a while ago. Notice the formulae on page 7 and 21 respectively. VCC is involved in both of those, meaning that no matter how you put it, it invariably affects the results in some way. These results are the value of the feedback resistor (page 7) OR the values of the low/high "trigger" points (page 21). THAT'S what I based my schematic and values on since then. It's also entirely possible that I used them wrong ! Also see that XLS "calculator" I attached a couple of posts back, so you don't have to crunch those numbers yourself. I can confirm that it works - I made it myself

author: Zero999
author_rank: Super Contributor
timestamp: August 21, 2024, 04:55:56 pm
content: Quote from: Dannyx on August 21, 2024, 04:31:19 pmYes, I'm familiar with that paper. The reason why the supply voltage is irrelevant in your case is, the input voltage is also scaled to the supply voltage, because it's a potential divider.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 21, 2024, 05:15:49 pm
content: Oh, so the chaps are assuming Vin is not the same as Vcc ? I just had a look at the schematic on page 5 again and indeed, Vin is shown as a different source, which is not explicitly given a value in V, while Vcc is assumed to be a constant 5v, regardless of Vin. In their case, Vcc does affect all but one of the results: formula (1) on page 7, because Vcc is not part of it, so we can still use it to work out the value of Rhyst, regardless of our VCC.....if I understand this correctly.

author: Zero999
author_rank: Super Contributor
timestamp: August 21, 2024, 08:52:50 pm
content: Quote from: Dannyx on August 21, 2024, 05:15:49 pmForget the voltage. It's the ratios of the resistors which are important.R_in_off = R3×R2/(R1-1+ R4-1)-1R_in_on = R3/R1×(R2-1+ R4-1)-1Note the voltage doesn't factor in the above formulae.I've put the above into a spreadsheet as well as simulated it. I haven't put any units in the spreadsheet, because it doesn't matter whether it's in Ohms, k Ohms, or M Ohms.It agrees quite well with the simulation.This will also work with the LM393 and be quite accurate, as long as R4 is much larger than the pull-up resistor and even if it's not, it's fairly easy to calculate.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 21, 2024, 09:28:17 pm
content: Thanks for putting in all that effortI suck at math big time, so it took me a while to figure out what those negative 1s were doing there, but I did some digging and realized you used them to say "1 divided by THAT value"...had to look up what the negative power of 1 doesThe moment it all started to make sense and it began to click is when I finally understood that the comparator is throwing R4 ("Rhyst" as I like to call it) in parallel with either R1 or R2 depending on whether it's "on" or "off" (hence your the parallel resistor equation). I figured it out when I read the TI article and I still stuck with involving the voltage in my "analysis", which made it easier for me to understand because it served as the "proof". Turns out it can be left out, which made logical sense from day 1, but I still needed a way to calculate the value of Rh (R4) for future use, instead of stabbing in the dark, esp. since I don't have a scope. To make my life easier, I try to go with nice round numbers for R1 and R2. Can't stop thinking I should check the voltage value on that "node" thoughFor the comparator I'll go with the TLC3702....since I ordered it anyway for its push-pull config (saves the pull-up resistor) and I can use a NPN. That 16v limit is a little close for comfort, so I might just add a 15v zener on the Vcc pin just for good measure....I guess....

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 21, 2024, 10:07:10 pm
content: One thing you might find very useful is learning how to calculate theThévenin equivalent. For example, the circuit on the right is the simplified Thévenin equivalent of the circuit on the left:

author: Dannyx
author_rank: Regular Contributor
timestamp: August 22, 2024, 10:13:42 am
content: Quote from: Zero999 on August 21, 2024, 08:52:50 pmOk, total math noob here again, back with some more questionsGoing back to this for a moment, the second part makes sense:(R1-1+ R4-1)-1.It's the parallel resistor formula (similar for the second case whereR2is the one being paralleled to R4).It's the first part I realized I'm having trouble with: R3×R2 and R3/R1 respectively. Why are we multiplying R3 by R2 in one state and dividing R3 by R1 in the other state ? The math works and I was able to confirm it several times across multiple values, but I don't want it to just "work" - I want to understandwhyit worksI was thinking it's based around the resistor divider formula.......but there's no voltage here

author: Zero999
author_rank: Super Contributor
timestamp: August 22, 2024, 09:38:38 pm
content: Quote from: Dannyx on August 22, 2024, 10:13:42 amYes, that's the resistors in parallel formula. I could have written (R2×R4)/(R2+R4) or1/(⅟R2+ ⅟R4).I probably haven't help, by the way I wrote it.Look at the circuit again, without the feedback resistor.The output will turn on, when:R_in/R3 < R2/R1Calculate R_in at turn on, given the values of R1, R2 & R3.For simplicity's sake, then say the output starts to turn on when R_in/R3 = R2/R1. In real life it'll be unstable when the two potential divider ratios are equal, but it makes the calculation easier.R_in/R3 = R2/R1Multiply both sides by R3, to get rid of the divide on the left hand side and we get:R_in = R3×R2/R1Now you can put R4 in the above calculations, depending on whether it's in parallel with R1 or R2. If you do it correctly, then you'll end up with the same formulae, as in my previous post, even if it's written differently.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 23, 2024, 05:20:19 pm
content: Quote from: Zero999 on August 22, 2024, 09:38:38 pmYes, it's that last form I'm familiar with. I'm not good with numbers to begin with, so any kind of shorthand or rewrite of a formula I know "my own way" kills meQuote from: Zero999 on August 22, 2024, 09:38:38 pmThat was the NEXT thing I was going to ask, so I'm glad you caught it: it all made sense (save for the small arithmetic dilemma), but no matter how I looked at it, the ratios on the two inputs were always identical, which made me wonder how the comparator would behave in real life, since it would be close to an "undefined" state. In practice, I thought about adding "+1" to one of the resistors, or a factor of "1"...

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 23, 2024, 07:24:49 pm
content: Quote from: Dannyx on August 23, 2024, 05:20:19 pmAdding +1 to a resistor will simply change the trip point where it's unstable. "R_in" is always variable, so changing R1, R2, or R3 doesn't really fix the problem.That's why we use positive feedback: So that the comparator circuit has some hysteresis. This eliminates any noise/oscillation around the trip point. (Noise has to be less than the amount of hysteresis.)

author: Zero999
author_rank: Super Contributor
timestamp: August 23, 2024, 09:30:14 pm
content: Quote from: Dannyx on August 23, 2024, 05:20:19 pmA comparator is a type of amplifier with a very high gain. For example, the LM393 has a typical gain of 200V/mV, or 200k, so if the input voltage changes by 0.1mV, the output will change by 20V. The input offset voltage is ±0.37mV, which means that when the inputs get this close, the output voltage will fluctuate.https://www.ti.com/lit/ds/symlink/lm393.pdfThis is where the feedback resistor comes in. As soon as the output voltage starts to rise, it starts to increase the voltage at the non-inverting input, which then causes the output voltage to increase more, until the output saturates close to the positive voltage. In other words, the positive feedback, increases stability.Another option is to make it latching. The diode causes the output to be connected to the non-inverting input, when it's positive. R4 is still there but reduced to a much lower value, to avoid large current pulses, when SW1 is pressed to reset the circuit.EDIT:I've noticed a bug in the above circuit. When it goes completely dry, it'll unlatch, so another resistor will need to be connected across the input to ensure it doesn't go completely open circuit. Attention also needs to be paid to avoid the common mode range of the comparator. Most comparators work as intended, as long as one input is within range.

author: floobydust
author_rank: Super Contributor
timestamp: August 24, 2024, 03:04:44 am
content: I appreciate the discussion about adding hysteresis to the comparator, maths included.But I think you don't need any hysteresis at all for this application. The difference between dry and wet electrodes is huge, many orders of magnitude of resistance.You can't reliably tell water level by looking at electrode resistance. The water purity, electrode capillary action, electrolysis, corrosion - all make the value move around too much, inconsistent. You can see the presence/absence of water though.These water alarm sensors FAIL when connected to the real world. They are fine to theorize as floating, battery-operated circuits.OP's alarm panel will be PE grounded for the 12V supply. Although, I understand his building is a bit dodgy there.If the electrode is referenced to +VCC, when wet it will quickly corrode unless you have a big resistor there to slow that down. It depends if this is a once in a while gets wet, or frequently sees water application (use AC).Powering a water alarm sensor from a wall-wart false triggers due to the high common-mode voltage from the Y-cap.If the sensor is wet on a basement floor, you get galvanic potential between each electrode and other grounded metals, could be cast iron, copper. One (electrode) end is grounded at the panel, other in the water or concrete if it's touching that- which does not register beyond corroding. A DC half-cell voltage tries to appear on both electrodes, and polarity is also a concern, but you get a DC voltage at the electrode of interest which confuses the resistance seen.These circuits are very important but can bite you in the ass. Many of them on the Internet are garbage. I'm in a commercial one right now and measured short-circuit current at the sensor electrodes as 4mA. It's using a BJT there.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 24, 2024, 04:53:43 pm
content: Ok guys, I just got my box of stuff delivered yesterday, so I definitely want to start playing aroundA few more details: the sense "pad" looks likethis, although I'm sure you already know that. In fact, I actually have that same exact gadget I linked to, so you might be asking why not use it as it is and get it over with ? Where's the fun in that ?Plus, it also gives me the satisfaction of building my own and learning about something I always thought I understood.....until I tried it myself and realized it's not quite so !The pad will definitely NOT be submerged in water - HOPEFULLY not, in this case ! Actually, under normal circumstances, it should stay completely dry at all times and should only become moist if my LPG hot water heater/central heating boiler (not sure what you call these here in the EU) decides to leak or barfs the pressure relief valve all over the floor for some reason. The reason I wanted to make its sensitivity adjustable is because I noticed that with just the right conditions, when I was messing with the cell on the breadboard, it can react when touched. It makes sense, since skin IS conductive ! It shouldn't normally be touched by anyone, but I wouldn't want the alarm going off just because someone tried to adjust its position and grabbed the pad by the grid rather than the edges - you never know !In fact, to keep the ball rolling and just for a bit of fun, I put together a little experiment where I hooked the pad to my multimeter and measured its resistance under different situations. Far from scientific or exact, but I ended up with this "data" (although calling it "data" is like calling an electric scooter an EV - bit of a stretch):-thumb, middle of the pad, one side, hard to light pressure: 70k-260k-finger, middle of pad, one side, hard to light pressure: 90k-200k-tap water, sucked into syringe, make a 2cm drip on the middle of the pad, one side: 500k-600k-tap water, water line just about bridging the first 2 "segments" of the grid on both sides: 600k-tap water, cell fully submerged: 100kNow this is where it got....weird:-distilled water, sucked into syringe, make 2cm drip on the middle of the pad, one side: 200k-distilled water, cell fully submerged: 20kDistilled water more conductive than plain-@$$ tap water ?? Ok, it's worth mentioning I didn't just buy brand new distilled water for this ! I just found a near-empty jug somewhere in the house that said "distilled water" on it. My folks apparently use it to fill the clothes iron to (hopefully) prevent scale buildup. It might be that it somehow became contaminated over time by sitting there, OR they just dumped the remaining water from the iron back into the jug once they were done using it....either way, that definitely doesn't look like distilled water to me !

author: floobydust
author_rank: Super Contributor
timestamp: August 24, 2024, 05:20:26 pm
content: Remember that when you are measuring Ohms with a multimeter on the sensor wet, that it is not a resistor. It is actually a battery or 1/2 cell of that, you are "charging" it. The Ohmmeter reading will not be steady you might have noticed as it climbs in a direction up/down. You can also reverse-polarity with the probes and note the reading is way different due to the electrolysis happening. Changing the water removed or replenished the electrolyte I would say, and no chlorine/calcium/iron ions getting in the way?That sensor PCB looks like it's tin-plated, not (enig) gold plated.Is it using the People's op-amp LM358 or I've recently seen a 555 used. I have a zillion schematics of water sensors and there are 1,000 ways to do that. From transistors, CD4093, MCU, even a TL431 could pull it off.Be careful if the sensor has one end connected to power, then I would say it's not a good design.Did you look for the schematic of the board?

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 24, 2024, 07:06:44 pm
content: Yea, I'm not really a fan of these PCB moisture sensors. It'll probably be OK in your use case because it'll rarely get wet. With something that regularly gets wet, I'd be worried about the PCB material absorbing moisture and the thin traces corroding away.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 24, 2024, 08:30:40 pm
content: Quote from: Kim Christensen on August 24, 2024, 07:06:44 pmJust to keep the discussion going: what WOULD you use for "electrodes" ? Stainless steel ? I know that's the most commonly used for stuff that comes in contacts with liquids...

author: Dannyx
author_rank: Regular Contributor
timestamp: August 24, 2024, 08:57:45 pm
content: Quote from: Zero999 on August 22, 2024, 09:38:38 pmOk guys, I know I keep obsessing over this, so please bare with me as I go back to being a math noob once again ! Really sorry about that, but please read on to at least see what I have to sayWhen I first read the reply where this was explained (#27), I quickly scanned my eyes across the part I quoted above and thought I got it, but then I had another look at the associated schematic above it and it fell apart again !See, I THOUGHT R2 and R1 were the "top" and "bottom" resistors for the same input (say, the N/I input), while R3 and R_in, the "unknown" resistor, are on the other input......but they're not ! I didn't notice this at that time and just rolled with it. I thought "oh, ok, that makes sense: you divide the "bottom" by the "top" and get one "side" of the formula. Repeat for the other side, where the "unknown" resistor is. I went to check this again today and noticed it's not like I thought: R1 and R2 are in fact NOT arranged like I thought (schematic in #27): they are both "top" resistors for EITHER input, so we go back to the "why" of this, I'm afraid...We divide R2 by R1....but they're both tied to VCC, soooooo.....There's probably some super-technical textbook reason for this that for the average Joe doesn't go beyond "doesn't matter WHY - just because, so roll with it and quit asking questions"...but you know me !

author: floobydust
author_rank: Super Contributor
timestamp: August 24, 2024, 09:49:09 pm
content: Quote from: Dannyx on August 24, 2024, 08:30:40 pmIf the electrodes are wet most of the time, like in a tank- then brass or stainless steel is used. For rarely wet use, I see zinc/galvanized or chrome plated hardware is good enough. They are usually about 1-3mm off the floor though which I think is no good at detecting a wet film. People have put that in a kitchen sink cabinet... and they never got wet of course. The wood and drywall got soaked and the water ran like that.There is also water leakage detection cable. This is a 2 or 4-wire cable with permeable jacket you string on the floor etc. So any portion getting wet you get conductance between the pair, second pair I forgot what it's about, it seems to be an antique Wheatstone bridge configuration that became a standard? It's good for data centers and large rooms for early warning but expensive.Alihas some.I have to laugh, there is a consumer-grade IoT WiFi water alarm that uses a sponge! It expands when wet and pushes up and closes a metal switch contacts. Not so reusable lol.

author: Zero999
author_rank: Super Contributor
timestamp: August 24, 2024, 09:55:36 pm
content: Quote from: Dannyx on August 24, 2024, 08:57:45 pmR1 and R2 are supposed to be the top and bottom resistors. I messed up the labelling. I'll go back and edit the posts, so the labelling is consistent.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 24, 2024, 10:00:14 pm
content: Quote from: Zero999 on August 24, 2024, 09:55:36 pmOOOOOOOOOOOOOOOOOHHHHHH THAT was it ?!Ok, so I WAS right !Crisis averted

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 24, 2024, 11:31:37 pm
content: Quote from: Dannyx on August 24, 2024, 08:30:40 pmYes... Stainless probes are good. Long enough that the wire connection points are out of the water.For things that are going to be immersed continually or on a regular basis, I'd use something like a float switch if the extra water depth was acceptable.For water levels in plastic tanks, I like the capacitive method. (Two strips of metal on the side of tank whose capacitance varies with level) I've also heard these can be used for soil moisture measurements, so it also might work for a leak detector.

author: Rerouter
author_rank: Super Contributor
timestamp: August 24, 2024, 11:47:06 pm
content: I can suggest an alternate, a capacitive sensor on a sponge (just 2 interleaved pads on a pcb) used in an oscillator and connected to a missing pulse detector (a 556 can work for this, 1 for a moisture based frequency, the other for detecting the missing pulse / too low a frequency)A normal sponge will have a dielectric around 4-6, water is 80, so a little water changes the frequency a lot, and this does not care how conductive the water is, only its presence,easy to make SMD on a single PCB, the sensor on the bottom and the components on the top covered in some kind of coating to keep it able to survive multiple events.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 25, 2024, 09:47:03 am
content: Looking at #30 again, that latching circuit actually looks interesting for my particular case, since it ensures the relay the comparator drives actually stays on when triggered just once, which makes sure the alarm panel picks it up. If it bounces back and forth too quickly before finally settling on a state, it might not trigger.Also, which of the 4 resistors (except R_in, of course) would you typically tweak to adjust the circuit's trip point up/down ? Do you modify the reference on the N/I input (R1 and R2) or do I tweak R3 ? Or even a trimmer before R_in to GND to change the minimum possible resistance it can reach. When the trimmer is fully CW, let's say, it's basically out of circuit and R_in goes straight to GND, so the minimum possible resistance R_in can have is only limited by whatever's touching it. When fully CCW, R_in is now the resistance of the pad PLUS "R_trim", so even with R_in short-circuited, R_trim is the minimum resistance, whatever that might be. Unless we're sensing mercury or something that can completely short-circuit the pad, it's an unrealistic scenario, so R_trim probably needs to be really small, like 10-20k max ? Just speculating....

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 25, 2024, 05:43:51 pm
content: R3 is the one I'd tweak for different sensors and water salinity, etc.

author: Zero999
author_rank: Super Contributor
timestamp: August 25, 2024, 06:49:57 pm
content: Quote from: Kim Christensen on August 25, 2024, 05:43:51 pmNote theedit to the postmentioning the bug.It's better to add the diode between the output transistor and input, so it pulls it down. The switch can go on the other input to pull it down below the diode voltage and reset it.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 25, 2024, 07:39:04 pm
content: Is it a good idea to short the op-amp's input directly to GND via the button like that ? In practice, I'm sure it doesn't matter, esp. since it's for a very brief moment.Also, going back to the "basic" version, with just the 4 resistors and R_in and adjusting its "sensitivity": someone mentioned tweaking R3 to adjust it, while I was thinking more along the lines of R1/R2. True, I'm not sure what the resistance of the pad (R_in) is ACTUALLY going to be in practice, since, as previously discussed, directly measuring across it with a multimeter is sub-optimal at best, so those resistance figures are probably WAY off...which is what I thought from the get-go: how's human skin more conductive that goddamn WATER ??

author: floobydust
author_rank: Super Contributor
timestamp: August 25, 2024, 07:52:38 pm
content: Quote from: Dannyx on August 25, 2024, 07:39:04 pmYour finger is not only a resistor. A real world sensor will pick up common-mode noise like mains hum, RF from WiFi and cellphones etc., it will false-trigger.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 25, 2024, 08:30:54 pm
content: Quote from: Dannyx on August 25, 2024, 07:39:04 pmWithmostmodern op-amps and comparators, it doesn't matter. LM339, LM393, will be OK.QuoteTake an extreme example:Lets say you've chosen a value for R3 that, when "R_in" is wet, the voltage at "-in" is 11V and you've used a LM339 or LM393 as the comparator.This puts with voltage change within 1V of the positive supply rail. If you look at theLM393 datasheet on page 7, the "Common mode range" must be 2.0Vlessthan the +supply voltage. Now you try and adjust R1 & R2 to make it work, putting the "+in" also between 10-12V. The comparator won't operate properly and you won't get the result you want.Personally, I would make R1 & R2 the same so the trigger point is 1/2 the supply voltage (6V) which is closer to the middle of the LM393's common mode range. Then adjust R3 so that the voltage at "-in" falls well below 6V ( less than 2-3V) when R_in is wet. This keeps the voltages well with in the common-mode voltage range which is between 0V and VCC – 2V.

author: Zero999
author_rank: Super Contributor
timestamp: August 25, 2024, 09:46:05 pm
content: Quote from: Kim Christensen on August 25, 2024, 08:30:54 pmWell he's using the TLC3702, but it should be fine.https://www.ti.com/lit/ds/symlink/tlc3702.pdfQuoteI agree, but also note the LM393, will be fine, so long as one of the inputs is within the common mode range.Quote from: LM393 data sheetPerhaps the original poster should consider the LM311. Its output can sink up to 50mA which can drive most relays directly so no additional output transistor is required. Its common mode range only extends to 0.6V above the negative supply though, but it should be fine as long as one input is within the common mode range.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 25, 2024, 10:09:15 pm
content: QuoteIn the extreme example I posted above,bothinputs would be outside the common mode range as Dannyx attempts to compensate for R3 being too low resistance by adjusting R1/R2 instead.ie: +in could be at 11.5V, after user adjustment, and -in would be varying between 12.0V (dry) and 11.0V (wet). If +in was adjusted below 10V, to put it within the common mode range, then the alarm would never trigger because wet = 11V and dry = 12V. (Due to R3 being too low of a resistance)An extreme example I know, but gave that example to answer this:Quote from: Dannyx on August 25, 2024, 07:39:04 pm

author: Dannyx
author_rank: Regular Contributor
timestamp: August 26, 2024, 07:56:33 am
content: Thanks guys.I have both the TLC and 393 available. The only reason I switched to the TLC at the last minute when ordering my sh!t is because it's a push-pull config, which SEEMED to make stuff more logical when it came to hysteresis - almost like a "comfort zone".Speaking of which: in an open-collector jobbie, the comparator itself no longer "pulls-up" internally to VCC - an external resistor does that - so I assume IT has to be part of the hysteresis formula too when the internal transistor is in the "off" state.

author: Zero999
author_rank: Super Contributor
timestamp: August 26, 2024, 10:12:15 am
content: Quote from: Kim Christensen on August 25, 2024, 10:09:15 pmAnother interesting thing about the LM393 is, assuming the internal schematic on the data sheet is correct, if both inputs exceed the common mode range, the output will go low. Q1 to Q4 will all turn off, which will leave Q7 with no base drive, causing it to also turn off and Q8 will turn on, because its now pulled up to +V via the current source. I have not tested it to verify this. It's something I would breadboard first, if I were going to rely on.Quote from: Dannyx on August 26, 2024, 07:56:33 amYou'll often get discussion about other ways to do things in threads. Don't worry about it. Either will part will do.QuoteYes that's true but normally the pull-up resistor value is very low, compared to the feedback resistor, so it makes little difference.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 26, 2024, 11:38:22 am
content: Another noob question at this point, but it's a big one I see thrown around a lot when it comes to op-amps: what IS common-mode voltage in practical terms ? Ok, everyone out there will probably want my head on a pike for not knowing this, but I'm asking so late only because I had it confused for something else all along: OFFSET voltage. I thought it referred to the "resolution" of the op-amp - the minimum difference required between the inputs for the output to switch state.

author: ArdWar
author_rank: Frequent Contributor
timestamp: August 26, 2024, 11:42:41 am
content: Quote from: Zero999 on August 26, 2024, 10:12:15 amItISa feature, up to a point.Checkhttps://www.ti.com/lit/pdf/snoaa35page 11 and up

author: Zero999
author_rank: Super Contributor
timestamp: August 26, 2024, 12:22:55 pm
content: Quote from: Dannyx on August 26, 2024, 11:38:22 amThe common mode voltage is the average voltage on the inverting and non-inverting pins, so if the inverting input is +1V and the non-inverting input is -1V, the average and thus the common mode voltage is 0V. The common mode range, is the common mode voltage range, which the amplifier will work properly over. Some op-amps, for example the TL072 go into phase inversion, when the common mode range is exceeded, the functions of the inputs exchange i.e. the inverting input becomes the non-inverting input and vice versa. This can result in latch-up, as negative feedback, becomes positive, similar to how the comparator circuits work, with the feedback resistor/diode.In this case, we're using a comparator, so common mode range isn't really the right term to use. In the case of a linear amplifier, negative feedback ensures both inputs are nearly the came voltage. In a comparator, the inputs will be at different voltages, so input voltage range is more appropriate. The input voltage range is simply the range of voltages either input must be within, in order for the comparator to give a valid result. In the case of the LM393 and many other comparators, only one input needs to be within the input voltage range, in order for it to give a valid output, but note that in most cases both inputs need to be within the supply voltage range, although the LM393 has protection diodes, which enable the inputs to exceed the positive supply.For example if the input voltage range of a comparator is -V to +V-2 and it's run off 12V, then the comparator will give a valid output voltage, when the input voltage on one of its inputs is between 0V and 10V.The application note linked to by theprevious postexplains the difference between the common mode and input voltage range. Note that some data sheets don't use the correct terms, which confuses things.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 26, 2024, 02:50:59 pm
content: Quote from: Zero999 on August 26, 2024, 12:22:55 pmOk, so using the same example, connecting an input straight to VCC would not be an ideal thing to do because it would be an "invalid state" ?THISwas an informative read and eye-opener, starting fromPage 23, when I fudged up a while ago while playing with this same exact setup. I wrote a post about this, when I knew even less about op-amps than I do know, trying to figure out why my 393 doesn't "do" anything, thinking it's dead - turns out it's not a push-pull config, so expecting it to "do" anything on the output without a pull-up resistor was hopeless......anyway. That's beside the point.Page 23of that article describes something I did wrong in a couple of my experiments: I directly connected the inputs to the supply rail and GND in order to "test" the op-amp. It CAN be done, just through a resistor, as described. This however brings me back to the current topic: taking theTLC3702as the example, the "common-mode input voltage range" is 0v to VDD-1V (page 3). Isn't pulling the input up to VDD, like the article recommends, going outisde that range ? Resistor or not.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 26, 2024, 04:16:03 pm
content: From page 18 of the datasheet you linked. They don't really say what happens when one input is within the common mode range and the other is not:

author: Dannyx
author_rank: Regular Contributor
timestamp: August 26, 2024, 04:58:33 pm
content: Well they do say "inputS" (plural), implying it's probably good practice to keep both of them within the limits.Let's bring in some values now (ideal circumstances, of course):-Vcc = 12v- R1, R2: some examples show some very high values for them - in the order of M-ohms. I know there's very little current flowing into the inputs, but shouldn't I bring these lower still ? Say, 10-20k ?- R4 (R_hyst): tricky one ! I played around with the formulae and the gist of it is that the lower the value of R4, the higher the hysteresis. The higher the value of R4, the smaller the hysteresis. This makes perfect sense, since the lower R4 is, the more it impacts the resistive divider formed with R1 in one state and with R2 in the other, so the more the Inverting input must "travel".- R3: the smaller the value, the smaller R_in also needs to be, otherwise it never triggers. Too large a value and it triggers too early. Could be a trimmer ?

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 26, 2024, 05:19:45 pm
content: Quote from: Dannyx on August 26, 2024, 04:58:33 pmYou generally want the impedance at both inputs to be the same. This prevents the comparator's input bias currents from adding to the input offset voltage. In your use case, it doesn't really matter since you're not trying for a ultra precise measurement or trip point. (Talking a few millivolts error here)QuoteFor a prototype, a trimmer could be useful. Once adjusted, I doubt you'd ever have a need to adjust it again and it could be replaced with a fixed resistor for greater reliability.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 26, 2024, 05:37:50 pm
content: Another problem I spy with R3 being a trimmer, even a multi-turn one, is that there's nothing stopping the average Joe from turning it into a 0-ohm path to VCC (if this were a build for someone else than myself where I KNOW its limitations).A second resistor in series with it could prevent that.

author: Zero999
author_rank: Super Contributor
timestamp: August 26, 2024, 06:07:17 pm
content: Quote from: Kim Christensen on August 26, 2024, 04:16:03 pmMost comparators should work, so long as one of the inputs is within the input voltage range specification, but I wouldn't be sure. My advice is try it.

author: floobydust
author_rank: Super Contributor
timestamp: August 26, 2024, 06:22:24 pm
content: Breadboarded it with a newer TI LM311P to see if the one input pulled to VCCwould cause trouble, and no phase-inversion noticed. Just AC hum lol.I didn't know TI changed the process and design of these old comparators. The 311 is not part of the club it seems."In 2021, Product Change Notifications (PCN) began to be issued to notify customers that the classic die is to be replaced with a new die for most of the LM339 family.""Application Design Guidelines for LM339, LM393, TL331 Family Comparators Including the New B-versions"SNOAA35E revised this June 2024.5.7 Input Voltage Range Feature"A nice feature of the LM339 family (and ONLY applies to the LM339 family devices listed in Table 1-2) is that only one input needs to be within the valid input voltage range for a valid output. The other input can be above the input voltage range or, even above VCC and the output maintains the correct state"I did a teardown of Basement Sentry Water Alarm148138it's 9V battery powered. Had to laugh, the input stage is a PNP BJT so 4mA across the shorted electrodes and it triggers very easily even 3MEG does it. Rest of it is a HEF4093.The electrodes are up off the floor a mm ot two which I again, dislike- you want early detection. You can parallel electrodes to give better coverage of a room.Note you can get a negative voltage on an electrode. It is uncommon but a stainless steel electrode and nearby (grounded) iron, zinc, aluminum etc. will cause this. It's low current but might be something to cover.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 27, 2024, 06:57:51 pm
content: Ok guys, after so much waffle-waffle, it was time for ME to finally breadboard the damn thing, so I did so today.The results were...slightly different than I was expecting.Using the TLC3702 as the comparator, I threw together the circuit this whole discussion was based on (save for the latching diode - we don't care about that right now):I chose 100k and 220k for R1 and R2 respectively.A 200k trimmer served as R3 (one end to VCC, wiper to Inverting input, the other end floating).The sense pad was connected between the Inverting input and GND, forming a resistive divider with the wiper terminal of the trimmer.R4 is 560k.I powered up the contraption and measured the output of the comparator. Since the pad was open-circuit, the Inverting input was pulled UP to Vcc via the trimmer, regardless of its value, so the output stayed off.I poured a drop of water on the pad and began turning the trimmer, trying to figure out the point at which it trips. It got there eventually, but I had to turn the trimmer so much that it was sitting at only 5k away from VCC....not the figure I had in mind. Because of this, another problem quickly became apparent: the drop of water I put on the pad started to sizzle and bubble up VERY quickly, eventually leaving a nice dark stain on the traces, so it was obvious this wasn't the ideal way to go ! (see the picture)I had no idea how I'd fix this, or if there even IS a solution to begin with, so I thought I'd take a step back, because I felt like I rushed into things, without taking it step by step, so:I pulled it apart and left just the N/I input alone: same values for R1,R2 and R4.I pulled the Inverting input down to GND via a 10k resistor.Powered up.Measured the output to make sure it's actually high. It was.Measured and took note of the "ref" voltage now present at the N/I pin - 8.73v, exactly as the math says, given the values of R1, R2, R4.Left the trimmer in place, still connected to VCC, but instead of using the pad as the lower resistor of my resistive divider, I used a fixed 100k resistor in its place (without the pad for now). I now had an adjustable voltage divider, so without the pad connected to anything, I turned the trimmer until it reached the trip point.Checked to see if output was low. It was.Added the pad in parallel to the trimmer, to VCC.Adjusted the trimmer so the output is NOT tripping when I touched the pad with my finger.Drop of water on the pad again.Output goes low.Less sizzling action this time, so by increasing the resistance to GND, I decreased the current through the water, meaning less bubbling...The end product is in the last picture.STILL not ideal though, as the drop still managed to leave a little bit of corrosion behind, but I think there comes a moment where corrosion is unavoidable, as going any higher in resistance to further limit the current is impossible/impractical/unstable...

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 27, 2024, 07:20:48 pm
content: Quote from: Dannyx on August 27, 2024, 06:57:51 pmSounds like you had something miswired becauseincreasingthe resistance of the trimmer should be what makes it trip.Reducingthe resistance should make itnot tripwith water/finger on the pad.Or, you had the logic level inverted in your mind: When turning the pot to a lower resistance, you made it "untrip"... Hence the fizz due to excessive current via the pad.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 27, 2024, 07:38:03 pm
content: Can't remember for sure what I did the first time.One thing is certain: the second iteration works better, but I'm still looking to lower the current through the cell (if at all possible).

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 27, 2024, 08:01:13 pm
content: Whether you go with the single pullup for R3, or use a voltage divider, the key to running less current through the cell is to use higher value resistors while keeping their ratios the same.If you're using the divider method, you can think of it as it's thévenin equivalent as I mentionedearlier on in this thread.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 27, 2024, 08:33:31 pm
content: Quote from: Kim Christensen on August 27, 2024, 08:01:13 pmIronically, even though it sounds really complicated, I now realize I used it several times without knowing itNow one thing I haven't entirely decided on is what the best "logic" of the circuit is: whether to have the pad pull UP to VCC or DOWN to GND, while also taking into account what the N/I input is doing on the other "side".If I understand this right: if I wire the cell to pull down to GND and it's fully dry, the output will stay LOW, because R3 will pull UP the - input to VCC at all times. As the pad starts to conduct (as R_in), the voltage at the - input begins to drop. Once it's below whatever the + input is set as, the output goes HIGH.By contrast, if I switch R3 and R_in, the opposite happens: the output stays HIGH until R_in begins to conduct, until it eventually causes the - input to go higher than the + input and the output goes LOW.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 27, 2024, 11:15:20 pm
content: I would connect one side of the cell to GND especially if it's going to be line powered and referenced to building ground. This would ensure that the max current though the cell was limited by R3. If it's an isolated battery powered device, it wouldn't matter.You have a few other choices for changing the output logic state for wet vs dry:1) Change which input that the cell connects to.2) Use a transistor to invert the logic.3) Use the 2nd comparator in the package to invert it.What would you be driving with the output?

author: Dannyx
author_rank: Regular Contributor
timestamp: August 28, 2024, 08:28:23 am
content: Quote from: Kim Christensen on August 27, 2024, 11:15:20 pmThe power comes from the alarm panel's "AUX" output, which is in turn powered by a SMPS. The whole system is not earthed, so the GND of the system is floating relative to PE and most likely capacitive-coupled to HV GND inside the wall wart, as it usually is via that Y cap, so there is going to be some leakage current there.At the same time, if the AC goes out, there's a 12v SLA battery that takes over, as is usually the case with alarm systems.Quote from: Kim Christensen on August 27, 2024, 11:15:20 pmWhat if swapped R_in and R3 ? From a purely theoretical point of view, assuming their values remain unchanged, the current would still be the same in either orientation, because they're effectively 2 resistors in series, so swapping them around doesn't affect the current, right ?Quote from: Kim Christensen on August 27, 2024, 11:15:20 pmMost likely a transistor to drive a relay. I initially experimented with a 2n2222a because I have a bunch of those on hand. Since it's an NPN, I'd need the circuit to stay "off" when dry, otherwise the relay would stay on all the time.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 28, 2024, 04:49:31 pm
content: Quote from: Dannyx on August 28, 2024, 08:28:23 amYes. From a purely theoretical point of view.In reality, as others have mentioned, there will be a path to other metal objects via the water you'll be detecting. It is best to minimize the potential difference between those and your sensor.QuoteThat should work fine:

author: Dannyx
author_rank: Regular Contributor
timestamp: August 28, 2024, 05:49:27 pm
content: This is the setup I currently have on the breadboard and I'm quite happy with it (save for the output part and the transistor - haven't added those yet). I came to the conclusion that the difference between human skin (especially when moist) and water is way less than I originally anticipated and I kept trying to combat it to no avail, because a dumb set of electrodes cannot possibly tell what's touching it - it just changes the resistance by X amount, which is always the same.I managed to bring the "error" down to something I'm willing to live with by playing with the values until I eventually settled on this setup: a 200k trimmer in series with the pad to GND seems to yield the best results. A 500k trimmer would probably be even better, since it would give me more "headroom", but I don't have one yet.I adjusted it so that the voltage at the - input falls to just below the "off" threshold (4.9v) when the cell gets wet. The reason I needed the trimmer is because, by itself, connected straight to GND, the resistance of the pad drops SO low that it brings the voltage down to less than a volt. Decreasing R3 to bring the voltage up would also allow more current to flow, which causes oxide build-up, as previously discussed, so the trimmer basically increases the minimum resistance of the pad.With the 200k turned all the way "up" (R_trim = 200k) even if the pad shorts, the maximum possible voltage becomes 5.7v by my observations. A 500k trimmer would allow it to go up to 8.4v.

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 28, 2024, 06:22:30 pm
content: Quote from: Dannyx on August 28, 2024, 05:49:27 pmLetting the voltage at the input go down below 1V shouldn't be an issue, so there'd be no reason to decrease R3 if no trimmer was installed.As long as the voltage at the input to the TLC3702 doesn't go below it's GND pin (negative supply), there shouldn't be a problem.One reason I can see for the trimmer would be to reduce the sensitivity of your detector without increasing current in the pad. (You don't want it to trip if it's just a little bit moist) Setting it at too high of a value would stop the detector from triggering at all.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 28, 2024, 06:27:44 pm
content: Quote from: Kim Christensen on August 28, 2024, 06:22:30 pmYes, that's the reason. I guess I just didn't explain it properlyAgain, the main struggle I had with this is making it react to liquids more than it does to contact with skin. I think I've reached the point where nothing more can be done with basic materials like these. It'd require some sort of chemical sensing element to actually tell if it's water.....beyond the scope of this project.What I CAN do is install the cell inside a mesh-like material, that allows water to reach it, but not grubby fingers....sometimes, simple solutions just click like that

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 28, 2024, 11:45:52 pm
content: Just to throw another idea out there. Since you have two op-amps in a package, you could make an adjustable on/off trip point like this:

author: Irilia
author_rank: Regular Contributor
timestamp: August 29, 2024, 03:31:22 am
content: Personally I will recommend to avoid having anything in contact with the water, the cheep ultrasound technology is is probably the best option even if you do it yourself, because the air always contain humidity and so the detection part of the PCB will always corrode at some point.

author: Zero999
author_rank: Super Contributor
timestamp: August 29, 2024, 07:56:45 pm
content: Quote from: Dannyx on August 28, 2024, 06:27:44 pmIt will do that, because it's a conductivity sensor and skin is more conductive than ordinary water, because sweat contains salts which make it much more conductive.The only way round this would be to use a window comparator, to make it so it doesn't trigger the alarm, when the resistance is too low. Failing that, mechanical protection against being touched is much easier.I still think you should consider AC. Here's an idea. U1 is a Schmitt trigger oscillator, R5 acts like the pull-up resistor to the water, C3 couples the signal to D1 & D2, a rectifier which converts the waveform back to DC, R6 and C4 a smoothing filter for the rectified signal, U2 a comparator with hysteresis and C2 couples the AC to the water. If the resistance between the input and 0V is high, the signal is coupled from the oscillator, to the rectifier and filter to U2, which switches its output low, as its inverting input will exceed the non-inverting input. When the resistance between the input is very low, the signal is attenuated to a very low level, so not enough of it gets to the rectifier.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 29, 2024, 08:05:50 pm
content: Those open up a whole new can of worms. Although interesting for sure, it would be quite hard to implement without an oscilloscope to actually watch what's going on, plus it takes up a lot more real-estate.How would a window comparator be able to tell between a more conductive material and a less conductive one ? I kind-of know the concept, but it's late now and I'm having trouble focusing enough to figure it outI guess I'd just create a mirror image of the circuit I built...sort-of.What would the main benefit of using AC be ? Less corrosion ? Again, I REALLY need to buckle down for that schematicI've just graduated "comparators 101"

author: Zero999
author_rank: Super Contributor
timestamp: August 31, 2024, 08:10:18 am
content: A window comparator uses two open collector comparators wired in AND configuration, so the output only goes high, when the input voltage is within a certain range, or resistance range in this case. If you want to do this with a comparator with a push-pull output then each output will need to have a diode in series and a pull-up resistor to +V. If you want to add a latch, then some filtering will be required, as the output from the window comparator will briefly turn on, when it encounters a low resistance, since the voltage has to fall through the range which will turn it on.Here's an article about window comparators by Texas Instruments.https://www.ti.com/lit/an/sboa221a/sboa221a.pdf

author: Dannyx
author_rank: Regular Contributor
timestamp: August 31, 2024, 11:39:43 am
content: I still spot a potential issue, given the operating principle, though I haven't experimented yet: as R_water slowly goes down, it triggers once, then "un-triggers" once it goes below the "window". This would still respond to human skin, as its resistance doesn't go low *bam* just like that - it still needs to pass through the "window", even if it doesn't actually stay there for long.I may be wrong, as this is more complex. I assume R5 still acts as R4 (the hysteresis resistor in the original example).

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 31, 2024, 12:29:03 pm
content: I like the idea of a clothespin, some regular pins and an aspirin (or similar). You put the pins though the clothespin, and add the aspirin. When the aspirin gets wet, it dissolves and the clothespin closes the contacts made form the pins. This hack has been around for very long. Probably from before transistors were invented.And of course the aspirin can be replaced by anything that gets soft when it becomes wet.A fun experiment:1. Take a piece of toilet paper, roll it up and pull on it untill it breaks to test it's strength.2. Repeat step 1). but apply a lesser force so it does not break.3. While still pulling gently make the toilet paper wet.

author: Zero999
author_rank: Super Contributor
timestamp: August 31, 2024, 01:20:28 pm
content: Quote from: Dannyx on August 31, 2024, 11:39:43 amYes. Please re-read my previous post. That's why a filter is required, if you want it to latch. The filter will prevent the latch from being triggered on short pulses.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 31, 2024, 02:55:27 pm
content: Would the traditional "resistor in series with capacitor" qualify as a "filter" ? The only way I see it is to slowly charge up a cap until something trips. If it doesn't trip, that means whatever was charging it dropped out too quickly. That's in layman terms, OFC

author: Kim Christensen
author_rank: Super Contributor
timestamp: August 31, 2024, 06:25:40 pm
content: While a window comparator will work in theory, using one in this case doesn't really make sense to me.So what happens when you have a water leak where the water that reaches your sensor is briny enough to be detected as a finger? Plus, there's going to be a difference between yours, mine, & zero's finger resistance as well has a difference as to how tight we grip it, etc.

author: Dannyx
author_rank: Regular Contributor
timestamp: August 31, 2024, 06:54:00 pm
content: That's one way to look at it. I wasn't going to dig any further into this project, outside theoretical discussions. I'm pretty happy I managed to learn something and piece together something that works in a pinch.

author: Zero999
author_rank: Super Contributor
timestamp: August 31, 2024, 07:12:06 pm
content: Quote from: Dannyx on August 31, 2024, 02:55:27 pmYes, that would work, but as Kim said deigning a circuit for an exact resistance range is unreliable. I think a mesh to stop people from touching it is a more reliable solution.

author: SCSKITS
author_rank: Regular Contributor
timestamp: August 31, 2024, 08:04:42 pm
content: If you can, please add connection/junction dots to the schematic to highlight wires that are actually connected.ed