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:
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
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
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