I sort of new to all this electronics stuff, but learning fast i think
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:
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
Any ideas what i could do to make this more reliable?
Any help is most welcome!
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 ...
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.
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.
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;
}
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.
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.
Dulimir:
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.
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.