Pages: [1]   Go Down
Author Topic: Arduino UNO simple single point water level indicator help!  (Read 2216 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone!

I sort of new to all this electronics stuff, but learning fast smiley i think smiley-razz

So i got this project that ive been working on for a while now and basically i want my Arduino rev3 UNO to water my plants!
I plan to do this by with a digital pin wired to a transistor (2n2222) that will switch a 5v relay powering up a submersible pump.
Thats all fine and dandy, but, submersible pumps are notorious for dying if the water level gets too low. So... i need a water level sensor.

My first idea was just sticking 2 wires into a cup of water. One is connected to ground while the other is connected to an analog pin.
i wrote the following code to get a reading:

Code:
float water;
int waterpin = 5;

void setup()
{
  Serial.begin(9600);
  analogReference(INTERNAL);
  
}
void loop()
{
  water = analogRead(waterpin);
  Serial.println(water);
  delay(1000);
  if(water < 100.00)
  Serial.println("water level OK");
  else{
    Serial.println("no water");
  }
}

The values im getting from this "sensor" are a bit erratic, i put a 1K resistor in line with the positive side of the circuit and that seems to have calmed it down a bit.
When the two wires are submerged in water the reading is close to 0, so i put that if the reading is below 100 the water level is OK, if the wires are out of the water the reading jumps to 1023, meaning that the water level is not OK.

Most of the time its pretty good, but there are still fluctuations in the reading, it just randomly drops down, sometimes to 0 and then goes back again, messing with my plans smiley

Any ideas what i could do to make this more reliable?
Any help is most welcome!

Cheers!
Logged

Sydney, AUS
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

chemistry ... make the water more conductive, put some NaCl (salt) in it. Aim for around 0.5% by weight, to avoid making seaweed out of your daisies ...
Logged

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your probe won't last long using DC due to corrosion.  Do some research and you'll find that AC measurements are the only way to go when moisture is involved.  Maybe you could hack an off the shelf soil moisture probe if you can find one cheap.  A float arm something like the way old toilets connected to a pot could give you more accurate readings with less maintenance at the expense of bulk.  Then there's ultrasound or even IR; you'll have to be a little creative to have good success with the IR, like floating something on top of the water to detect.
Logged

Experience, it's what you get when you were expecting something else.

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys!
yes, corrosion, im aware of that - but im sure there is a way to protect the leads from corrosion - but that might mess things up... 

ultrasonic sensor seems to be the best solution here.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


you could use 2 digital pins and alternate them (reversing the current) to minimize corrosion and let the current only flow when you make a measurement!

A bit like this code, you can give it a try.
Code:
int pin1 = 4;
int pin2 = 5;

void setup()
{
  Serial.begin(9600);
  analogReference(INTERNAL);
}
void loop()
{
  water = readWater();

  if (water == HIGH) Serial.println("water level OK");
  else Serial.println("no water");

  delay(1000);
}

int readWater()
{
  // reverse the pins
  if (pin1 == 5) 
  {
    pin1 = 4; pin2 = 5;
  }
  else
  {
    pin1 = 5; pin2 = 4;
  }
 
  pinMode(pin1, OUTPUT);
  pinMode(pin2, INPUT);

  digitalWrite(pin1, HIGH):
  int rv = digitalRead(pin2);
  digitalWrite(pin1, LOW); // switch off  current!

  return rv;
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 93
Posts: 3980
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Corrosion requires current, yes? How much current flows into a MOSFET gate?
I'd try using two pins rather than sensing to ground.
One pin is a digital output, drive it high to deliver a sense voltage for just a few milliseconds, the rest of the time make it an input pin (i.e. high impedance). The other pin is an analog input as already configured.
Use a resistor in series with each pin, maybe 10K or even 100K.
If the electrodes were stainless steel, I wonder how much corrosion would occur with this setup.
But the electrodes could still be reversed as Rob suggests.

I wouldn't worry about some variation in readings. Just define two thresholds, e.g. 800 or more means there is water, 200 or less means there is no water. Keep a state variable that doesn't change unless one of the thresholds is exceeded. With that amount of hysteresis, it should work well. Mount the electrodes solidly so that the spacing doesn't change.

Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow thanks guys!
using a digital pin to drive the circuit for a short amount of time just to take a measurement sounds like the simplest way, ill give that a try!

i thought of maybe tinning the copper wires beforehand, maybe that would slow corrosion down even more?
even if there is no current, they will corrode eventually, if they last 6 months its good!
its only a stop gap measure to prevent a submersible water pump from ingesting air.

Thanks again!
Logged

alabama
Offline Offline
Full Member
***
Karma: 1
Posts: 183
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Easy and cheap http://www.ebay.com/itm/New-Liquid-Water-Level-Sensor-Right-Angle-Float-Switch-/230697910942?pt=LH_DefaultDomain_0&hash=item35b6aac29e, second result of thousands for "water level switch" on E-bay. Or use a straight one on a pipe if you can't drill a hole in your supply tank.
Logged

Einstein once said you don't really understand anything until you can explain it to your Grandmother

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 93
Posts: 3980
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i thought of maybe tinning the copper wires beforehand, maybe that would slow corrosion down even more?
even if there is no current, they will corrode eventually, if they last 6 months its good!

I have a high-water alarm where I just used some stainless steel bolts from the hardware store as electrodes. But they're out of the water most of the time, your project would obviously be the opposite.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Just tested the above water level meter (the code and alternating input on digital 4 and 5) And it works great.
I have one added problem and that is that the water tank is metal en grounded. So it shorts out the signalling to the arduino.
Any suggestions on how to overcome this ?.
I am bound to use the 3 Stainless steel rodds that are allready in place, on is main, 2 and 3 are level low and high.
Any help would be great.
Logged

Pages: [1]   Go Up
Jump to: