steve_mcdonald:
Thinking about how I would proceed, I would remove the INPUT_PULLUP directive and set the pins as INPUT. I cannot see why your code needs to set the pins HIGH (lines 15 - 18) because it is the same thing as setting the internal pullups on. I would advise we turn them off. To do that remove lines 15 - 18 and change lines 9 - 13 to pinMode(firstLevel, INPUT); would also suggest we use an external pull down value that will give us a bit more current in the water - while this will increase ionisation somewhat, it will also reduce any effect during the microprocessor read cycle. I would try either 10k or 4k7 pull downs.
I have tried this in past before moving to 27k pulldowns but it did not work as expected.
steve_mcdonald:
(An alternative approach would be to use the internal pullups and discard the external pull down, then measure from ground to pin rather than vcc to pin .
sorry didn't get it, how can I read between ground to pin instead of vcc to pin? I can try it this weekend but it sounds like it will always show "0" ..how come I get "1" ?
That's a good question and it brings up assumptions I made but did not clarify.
- The bottom probe is currently connected to vcc. In my arrangement we would connect it to ground.
- I forgot you are using digital i/o pins (9 – 13). I would use analogue pins (A1 – A4 for example) set to inputs with ‘pinmode(A1, INPUT_PULLUP)’.
The voltage divider approach depends on using analogue pins configured as inputs with pullups. These pins will return an integer between 0 and 1023, depending on the voltage read at the pin. In my approach, the lowest probe in the water is connected to ground. The next probe is connected to analogue pin A1 (let’s say) with its pullup set. This pin will be at vcc when it is out of the water due to the pullup. The pin will read integer value 1023. When that probe is covered by water, the voltage at the pin will be pulled down due to current flow between the pin (driven by the pullup) and the ground probe. The voltage at the pin will be (referring to my earlier calculation) 1v75 above ground. The analogue read of that pin would give an integer value of 1.75 / 5 x 1024 = 358.
So, a reading of 1023 (or anything nearly that, say over 1000, would indicate the probe is uncovered, and a reading under 500 would indicate the probe is in the water.
All these estimates are made using the internal pullups with your original 27k external pulldowns. I’d dispose of the external pulldowns, in which case, the value of 358 (1v75) would be even lower than that, so the difference is even more notable.
I hope this makes sense. I am using this approach with multiple sensors at up to 20 metres. In my case I read the values at the analogue pins and can resolve daylight readings between integer values of 16 to 1022.
Let me know what I can do to help.
Steve
Thanks Steve,
I did read between "ground and pin" this time and understood that the readings vary on tank capacity and distance between probes. In my test setup I am using the "actual probe" in a small and long PVC container where I manage submerge all 4 probes and below are the readings of my 10 different attempts.
1st Probe - 400-450
2nd Probe- 400-450
3rd Probe- 450-500
4th Probe- 600- 700
I had test the same is a glass of water with a small setup of probes and it show completely different readings.
I also found that readings fluctuate a bit and then stabilize itself in 5-10 seconds when I move from battery power to wall socket power and vice versa while reading values in my laptop, but this should be fine.
For now I have choose to read anything below 800 is a "HIGH" in my code and its working perfectly but my next plan is to put my "actual probe setup" in my "actual 1000 liter overhead tank" and then read values. I will run it on different intervals and log the reading in my laptop just to see if there is any big change in readings and then I can fix which value I should put to get a "HIGH" correctly every time.
By the way 700 is way to high when the probe is completely submerged in water ..its a huge difference.
Okay, that sounds liek good progress. Let me know how your test inthe real tank goes...
in my actual setup now things are more stable and it's currently under observation, I am getting a good reading between 350-500 from all 4 probes and there is not much fluctuation.
By saying actual setup I am saying the complete system and approx. 500 lines of code including different sensor modules, display and buttons e.t.c I have mentioned in my first post so its a LIVE environment now.
Not sure if it is too early but I think its safe to say that my challenge around unstable readings is now fixed, even if not then also I have that level of control to read what It suppose to.
I am going on vacation soon and will do a full cycle of testing after one week to fix some other bugs.
Thank you for your help on this Steve.
It's a pleasure and I've enjoyed working out the answers with you. Good luck with the rest of your project.
I just finished reading through the entire thread because I was curious about the use of the conductivity of water as a level sensor.
Last summer I planned to upgrade my garden irrigation system to use a similar system. It is fed by our domestic water well. I cannot afford to overflow the tanks and create a lake. Has happened before.
So, after buying two of the conductivity sensor boards on Ebay, I built a sensor probe similar to what the OP has, but used float switches. One at the bottom of the pvc pipe to indicate the tank was nearly empty, and one near the top to indicate the tank was almost full. The top of the pipe is fixed to the top of the tank.
Using a Nano to watch the two switches and control a SSR that controls a solenoid valve to fill the tanks. Worked flawlessly all last season.
My suggestion to the OP is to change his sensor stack to use float switches to indicate the water levels. Then the off/on is truly solid on or off.
Paul
Hi Paul,
Your thinking aligns with mine. I resist the idea of sinking probes (particularly dc fed) into water tanks because of the electrolysis effect for one thing, although that can be reduced using ac or even reverse polarising dc every alternate sampling. In situations where I've used wet probes, I've used that reversing the polarity approach along with only powering the probes during measurements.
That way, the life of the probes can be extended quite significantly. Despite that, electrolysis also causes changes in the water chemistry, which I only understand superficially, but which I'd rather avoid.
I use floats in my water tanks for that reason. Mostly I care if there's risk of overflow or risk of empty tank, and I am less concerned about reading intermediate levels, but then I live in a country that never goes long without rainfall! In addition, I built an ATMEGA based weather station with a rain gauge so I always have a clue how much rainfall we're getting.
With respect to the model the OP has chosen, the probes do give a clear distinction between covered and uncovered, so it can be interpreted as on or off (although it is not exactly that). The difficulty is always that the actual readings will change over time as the probes are degraded by electrolysis. That's my ongoing concern and why I also avoid using wet probes too.
Hey, interesting discussion and thanks for your comment. Good luck with future projects and best wishes to you.
Steve
This thread is closed but i just want to provide an update and document it here which may help others that the said sensor work perfectly for around 1 year and then its strted showing issue so i have replaced it with Float switch type sensor. As stated by @steve_mcdonald and @Paul_KD7HB, one should always try to use contact less sensor in such applications.