Touch input used as liquid level sensor

geezer88

Senior Member
Howdy PicAxe community! Thanks for helping a newcomer with several problems. Here's a little payback that may be useful to someone.

I've used a 18M2 as a liquid level sensor for a water tank. I posted this in Snippets because it isn't a complete solution, and it was only tested on a plastic gallon jug.

I cut out two aluminum foil strips, 25mm wide and the same length as the height of a plastic jug. They were taped to the outside of the jug, about six mm apart. One foil was connected to 0V of the test board, and one foil was connected to input C.2 of the PicAxe. Port B had each of it's eight pins connected to an LED in series with a 330 ohm resistor that was, in turn, connected to the +5 supply.
So, in summary, the only connections to the 18M2, besides the needed power supply, ground, and programming serial port connections, were a foil sensor on the jug, and eight LEDs. Quite simple.

Here's the code:

Code:
;                              USE TOUCH CONTROL FOR LIQUID LEVEL SENSING
symbol maxrd = w1					;tank full reading
symbol minrd = w2					;tank empty reading
symbol del = w3						;range from empty to full
symbol level = w0					;current sensor reading
symbol test = w4					;reading for each 1/8 tank
symbol cntr = b12					;counter for loop

main:

; This portion requires tank to be full or tipped to cover sensor strips
let dirsb = 255						;set all port B pins for output
let pinsb = 255						;set all port B pins high to turn off LEDs
pause 5000							;pause to allow getting tank to full condition
touch16 [%00010001], c.2, maxrd		;get a reading at tank full condition
low b.0								;blink that the reading has been taken
pause 1000
high b.0
;This portion requires tank to be empty or tipped to uncover sensor strips
pause 5000							;pause to allow getting tank to empty condition
touch16 [%00010001], c.2, minrd		;get a reading at tank empty condition
low b.0								;blink that the reading has been taken
pause 1000
high b.0
del = maxrd - minrd / 8				;calculate difference in eighths of tank capacity

;Now in the working part of the program
lupe:
touch16 [%00010001], c.2, level		;get current reading


for cntr = b.0 to b.7				;light up leds to creat bar graph of current level
	test = cntr * del + minrd		;this test level for each 1/8 of a tank assumes linear
									;relationship of level and depth of fluid.  For some
									;odd tank shapes, a different relationship could be 
									;found
	if level > test then low cntr	;if level is higher than a 1/8 tank increment, turn on led
	else high cntr
	endif
next cntr

goto lupe							;loop back to take a new reading
end
The first part of the routine is used to get the reading for a full jug. In my testing, I had the jug half full, and would tip it towards or away from the sensor foils to simulate a full jug, empty jug, or anywhere in between. So when the program starts, you have five seconds to tip the jug to indicate full, then another five seconds to tip the jub to empty. After that it starts lighting diodes to indicate the current level. Seems to work okay, but there are obvious improvements that could be made.

I tweaked the setup of the touch command a little, but did not do extensive experimenting to see where it worked best. The whole setup is very sensitive to how wires are run, whether or not the computer is connected to the serial port, and what I was touching. In a real application, much of this would be fixed, but you will definitely need to calibrate after all is settled. EEPROM would be the place to store the calibration settings, but I didn't bother because this was just an academic exercise. (It's nice being retired)

I think that for tanks that are not of linear proportions, it might be possible to shape the tin foil strips to account for needing more capacitance or less, but this is another area that I did not explore. It might be easier to leave the electrodes linear, and experimentally obtain constants that could be tested against a current reading.

Have fun picaxing,
tom
 

techElder

Well-known member
This is intriguing research. Nice job!

I may someday transfer your work towards a large tank problem that I have. However, it's quite difficult to tip a 500 gallon tank to get the level changes you were able to work with.

I would be really interested in calibration procedures that tended to null out 'interfering' capacitance without having to use the liquid level to set level points. I can't see a way to do it that makes any sense, though.

Perhaps this is really just wishing?
 

geezer88

Senior Member
I don't see how you could calibrate without doing some testing. I guess one way would be to run the tank low, then apply the strips to the tank, and use debug to watch the variable used to capture the output as you refill the tank.

Since the geometry of the sensor strips, the wires leading to them, and the presence or absence of the serial cable all contribute, I'd think that having an lcd display on board so that you could see the results without having the computer hooked up would be best. My routine only does a two point calibration that assumes the tank volume is a linear function of depth. For the more or less square tank I experimented with, this is a reasonable assumption. A round, horizontal tank would be a whole different beast. If you had the luxury of time, you could probably linearize the results with goofy shaped plates, but I think a multipoint scheme with data taken while filling or emptying would be the most accurate.

I don't have time for another few months, but later I want to try this on the plastic fuel cells in an aircraft. If I learn anything useful, I'll post further. Meanwhile, if more discussion results, I'll be happy to try to contribute.

tom
 

westaust55

Moderator
Great research Tom

Another field where such liquid level detection is often sought is the potable water and grey water/sullage tanks on recreational vehicles such as caravans and motor homes.

Often these are relatively shallow - maybe only 200mm deep - but considerable area with the length dimension often 15 or more times the depth
 
Last edited:

geezer88

Senior Member
Great research Tom

Another field where such liquid level detection is often sought isgrey water/sullage tanks on recreational vehicles such as caravans and motor homes.
That's definitely a place where I would place high value on 'non-contact'!
tom
 

eclectic

Moderator
@rkj
Welcome to the Forum.

It might be safer to re-register under a neutral name.

Your present Forum name may
invite the Spambots.

One of the moderators can then delete
your post above.

e
 

geezer88

Senior Member
I'm Curious about whether the "Touch Control" could be used to measure Relative Humidity with the HS1101 R.H. Sensor??? Just a thought?
That's a great idea! I forgot that many humidity sensors are capacitive in nature. I bet they could be used, perhaps with some time spent on the tuning parameters. Unfortunately, humidity is a tough one to simulate. In the case of my application, liquid level, I could just tip the tank to cover or uncover the sensor elements to simulate the level changing. I'm not sure what to do for humidity, except to note that the normal daily relative humidity changes with temperature, so it is lowest in the warmest part of the day, and reaches a maximum at the lowest temperature time of the day. Instead of getting a cycle in a few seconds, from low to high, you would only get a once per day excursion.

Best luck with your investigation. Be sure to share what you find.

tom
 

MartinM57

Moderator
hmmm...are you searching the whole forum for old touch-related threads and posting this same stuff on every one? I think that might get a bit boring....
 
Top