Sensor Construction advice/thoughts

I'm working on a project that needs to sense the presence of liquid water. I haven't seen anything of this sort available commercially - if anyone knows of one, I'd sure appreciate a head's up.....

The sensor should be a very simple switch - no water, the switch (circuit) is open - LOW. If water should come along (spell that leak) the sensor would go closed - HIGH.

I can make what I need easily enough - cotton Q-tip and the bare ends of wire - BUT - 2 questions:

  • I'm concerned that a dead short of 5volts across digital pin 0 to ground wouldn't be the greatest thing for the processor. What would be an appropriate resistor value to tone this down a bit?
  • At the same time, I would like to filter out any milli-volt leakage that might come from humidity, etc. So my resistor should be sized appropriately for both tasks.

Thoughts?

Thanks in advance....

PB

Just found this - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1251842974

comments on the resistor value appreciated....

Thanks

If you use a digital input with internal pullup resistor enabled, there is no problem shorting that input to ground.

pinMode (pinX, INPUT);
digitalWrite (HIGH);

then to read it
pinXstate = digitalRead(pinX);
if (pinXstate == 0){
// do the action for water
}

CrossRoads,

I like this. I had thought to use attachInterrupt to change the state of the pin controlling a valve (through a relay.) This seems simpler.

I believe that to read, however, I would want to read for a state not equal to 0. The sensor would conduct (to ground) in the presence of water, so the state would effectively be HIGH - that is, 5v on the pin. Yes?

But this conjures up another question. When you query the pin state with "if," is it looking at the state as it is defined, or is it looking at the state as represented by current (or not) actually passing through the pin. It makes a difference.

TIA

what?

Either do this:

pinXstate = digitalRead(pinX);
if (pinXstate == 0){  // i.e. water has shorted the pin to ground
// do the action for water
}
//and implied
else {
// do nothing
}

Or do this:

pinXstate = digitalRead(pinX);
if (pinXstate == 1){ //i.e. pin is not shorted  
// do nothing
}
//and now this is Required
else {
// do the code for the pin being shorted, i.e. water is there
}

Instead of connection directly to 5V you could introduce a second pin that supplies the 5 V when you want to read the sensor and shuts down if you do other things

encapsulated in a function it looks like

int testWater()
{
  digitalWrite(POWERPIN, HIGH); // set 5 volt on the power pin
  int waterLevel = digitalRead(WATERPIN);
  digitalWrite(POWERPIN, LOW); // GND the power pin
  return waterLevel;
}

CrossRoads, I was saying I like your approach to the code. Straightforward.

Rob, that's an approach I hadn't considered. Thanks.

If you want your sensor to last a long time in wet conditions you will need to use electrodes that don't dissolve, this rules out nearly all metals but platinum, suggest carbon rods would be a reasonably choice. Alternatively use lower currents (up the resistors to megaohm range) and use thick copper wire (should only dissolve slowly - only the +ve electrode will dissolve BTW). Mount the electrodes in a water-repellant holder (hot-melt glue gun?).

The ideal way to detect water without electrolysing it is to use low voltage AC signal to measure resistance, not 5V DC (which is enough voltage to electrolyse almost anything).

Also be aware that pure (deionised) water has a much higher resistance than impure (mineral rich) water, so sensitivity will depend on the kind of water...

Roger that, Mark....

Thanks for the comments.

If the sensor actually every picks up water, then I'll be on it in a flash XD since it's there to detect a leak. The water in the system comes from a water softener, so it should conduct well enough. Actually, that's an interesting thought - maybe I'll measure the resistance, just for grins. It'll surely be in the milli-ohm range... LOL

I saw this item (or an item like it anyway) at Osh a while back and, after seeing your question, thought it might be fun to adapt it as a sensor for Arduino. It's a soil moisture meter.

Scimajor, that just might be an appropriate sensor for this project. Thanks!