What are viable approaches to a circuit to detect wet/moist cloth (bed-wetting)?
Conductivity is probably the easiest method. However, this is a case where you have to be extra extra careful about safety. This would be a good thing to power off of two AA cells. The output could be a opto, which can then go to anything else powered other ways. The lines going to the bed would ONLY connect to the battery powered circuit, with a good 5 mm or more gap to anything else.
Detecting water is not that hard, and urine is going to be more conductive than clean water. Two lines go to the bed. Each can be driven strongly high or low, or with a weak pullup or pulldown (weakly driven high or low). Each also goes into a A/D converter.
Most of the time nothing is going on and both lines can be weakly pulled to ground. The micro periodically wakes up to run a test. There are 4 separate tests, but the micro only needs to run one of them each time it wakes up. It should cycle thru all of them in sequence to avoid any net DC flow. It drives one line solidly high or low, puts the weak pullup/pulldown on the other line in the opposite direction, waits a while, then takes a A/D reading of the second line. The four cases are which line is driven, and whether it is driven high or low.
After a complete suite of A/D readings you should know whether there is enough conduction between the two lines to declare the bed wetted. You probably want to see this asserted several times in a row to to be sure. A few seconds delay isn't going to matter, and that's a very long time for a microcontroller.
Added:
Here is more detail on the circuit I was talking about:
To take one of the four readings, for example, the micro would set digital output 1 high, output 4 low, wait a while (a few ms), then read A/D input 2. With no connection between the electrodes, the A/D will read 0. With a direct connect, it would read nearly full scale because the the 1K driving resistor R1 is 100 times lower than the pulldown R4.
In practise you can double up the A/D input and the first digital output for each line to use only two microcontroller pins per electrode. I showed the three separate to make the functions more clear.
The four different combinations come from the two choices of which electrode is driven and which is the sense wire (A was driven an B the sense in the above example), and whether the driven electrode is high or low (high in the above example). The reason for these measurements is to cancel out bias caused by any battery effects, diode effects, and to avoid net DC to keep the electrode symmetric due to electrolysis.
You should use electrodes that aren't corroded by urine, so in theory there shouldn't be diode or battery effects, but stuff happens, and doing the logic is trivial anyway.
I was envisioning parallel wires loosely stitched to the top of the mattress below any of the sheets, held maybe a inch or so apart. One pair running accross the expected wet area side to side should be enough, but you could use two or three wires for each electrode alternating to cover more area.
I don't know what a good choice of wire is, but certainly not copper. Nichrome might be good, but you have to check yourself. I don't know which metals won't be corroded by urine that you can find wires of that don't cost a fortune. For example gold would work great chemically and electrically, but would break easily, and of course cost a lot even if you could find it. Platinum wire exists and might be suitable other then very expensive. Check out nichrome first.
Added 2:
There is apparently still confusion about the test sequence I am talking about. Here are the 4 tests:
Num Drive A Drive B Read --- ----------- ----------- ---- 1 strong high weak low B 2 weak low strong high A 3 strong low weak high B 4 weak high strong low A
The final result is then (#1 + #2) - (#3 + #4). #1 and #2 should be high readings and #3 and #4 low readings. By doing all four and adding up the result as I show, you cancel out both common mode noise and any fixed differential signal, like could be caused by battery effect due to assymetric corrosion.
If you don't believe this, work thru a example or two.
I'll add a big one to your list of requirements: no direct electrical contact with the, um, liquid. That liquid is corrosive, foul, and a host of other things. For safety you'd prefer to not have direct contact, but for "sensor lifespan" you also don't want it. Further, you want cleanup to be super easy.
Here's what I would do...
I would use a capacitive touch sensor. Something based on the Cypress PSoC "CapTouch" stuff, or similar. This would allow you to sense the liquid in a non-contact way. The captouch sensors are etched onto a standard PCB and covered with soldermask and other stuff. Slip this under a 1/4 to 1/2 inch thick cotton pad, and under the sheets. When it gets wet, the captouch sensor will register something.
I did a quick test of this here in my office. No, I didn't wet the bed. We have a touch panel based on this technology. I took a wet paper towel and pressed some buttons and it worked fine. I then took a "liquid substance inside of a sealed plastic bag" and repeated the test with success.
The cotton pad is to separate the person from the sensor to avoid false triggers. It also helps to contain the mess, should it happen. Throw the pad into the washing machine as needed.
I think this meets all of your needs:
- Reliability: Based on 2 minutes of testing, it seems to be reliable! :)
- Ease of use: Just set it down and go for it.
- Safety: No direct electrical contact. Should be safe. Can be battery powered for an extra level of protection.
- Clean-up: A washing machine and some wipes are all you need.
I like @DavidKessner's solution, but a PCB on the mattress seems ... uncomfortable to me. I would sew in conductive thread (google for other suppliers) into several bedtime underwear, creating several lines across the area that gets wet. Connect every other line together so you now have a pair of sensor lines. Visualize it this way:
+----------------------------------- A
+ -----------------------+
+----------------------- +
+ -----------------------+
+----------------------- +
-----------------------+--------- B
When the underwear gets wet, the resistance between A and B will go down dramatically. You could connect A and B to any kind of small snap connector (I'm thinking of a 9V battery connector) which then leads away to the actual circuit which could be tiny and zippered/buttoned to a convenient location on the leg/front/back of the pyjama. You could power this off a couple of coin cells, and there are NUMEROUS "water detector" circuits online which could be made VERY small and light.
Washing is as simple as unsnapping the underwear from the circuit and tossing in the wash.