This site will look much better in a browser that supports web standards, but it is accessible to any browser or Internet device.


Clubs, glossaries, museums, shops and much more......

glue-it.com

...all of your model making needs from one site.







Self Calibrating Water Tank Gauge

By: David White

This page describes the design of a water level gauge that I designed to measure the water level of tank built into the bow of a narrow boat. The tank is irregular in its shape and this gauge is designed to show a general indication of the level. To avoid having to calibrate the gauge this unit is designed to self calibrate and learn the size of the tank as it is filled and emptied. The gauge should become more accurate the more it is used.

The gauge is based round the MPXV4006 pressure transducer from Freescale. This device is designed to be used in washing machines to measure the water depth in the drum and can sense the pressure produced by a 2 (600mm) head of water. In this application the transducer is connected to a Picaxe microprocessor which displays the water depth on a 10 segment LED display. The unit is designed to work off a 9V pp3 battery and displays the tank level then the power button is pressed. The whole unit is built on a piece of vero board and fitted to the back of a brass socket blanking plate. The pressure transducer is connected to the outlet pipe of the tank via a capillary pipe.


Hardware

Parts list

  • R1 1K w
  • R2 22k w
  • R3 10K w
  • R4 - R13 330 Ohm w
  • D1 1N4001
  • SW1 Small push button
  • SW2 Momentary push button
  • Con1 3.5 mm PCB jack socket
  • C1 22uF 50V electrolytic
  • C2 220uf 10V electrolytic
  • C3 0.68uf polyester
  • LED1 Kingbright 10 LED array
  • IC1 Picaxe 18M2
  • IC2 TS2940 5V LDO regulator
  • IC3 MPXV4006

Most parts were sourced from my junk box. SW1 and IC1 were bought from Rev-ed and LED1 & IC3 were bought from Farnell.

Vero Board Layout

diracdelta.co.uk - Science & Engineering Encyclopedia

Software

This is not the world′s most efficient code but it does work. The maths routines may appear a little odd but are designed to work with the 16 bit integer maths in the Picaxe. Operating instructions are included in the comments.

'####################
'# Tank Level Gauge #
'# July 2011        #
'####################
'
'Instructions
'
'Holding down reset button on power up calibrates the bottom limit
'for the transducer. Should be done with unit not connected to pressure hose.
'This measures atmospheric pressure and calibrates for the empty tank. Also
'overcomes drift problems caused by vacuum in the pipe.
'
'Connect hose
'
'Gauge should self calibrate over a number of fill / empty cycles
'Pressing reset when powered up will reset top limit and reset the gauge.
'It will then need to re-learn the tank.
'
'Holding down reset button on power up will also display the software level of the unit.


symbol FlagReset = Bit0
symbol ADCReading = b1
symbol TankMin = b2
symbol Tankmax = b3
symbol TankQuantity = b4
symbol TankRange = w3
symbol TankLevel = w4

pullup on



'ports

dirsb = %11111111

'B0 - spare
'B1 - spare
'B2 - LED1
'B3 - LED2
'B4 - LED3
'B5 - LED4
'B6 - LED5
'B7 - LED6

dirsc = %11000011

'C0 - LED9
'C1 - LED10
'C2 - ADC
'C3 - Serout
'C4 - Serin
'C5 - Re-initialise variables
'C6 - LED7
'C7 - LED8


	'###############################
	'# check for reset             #
	'#                             #
	'# if reset whilst powering up #
	'# up then reset TankMax       #
	'###############################
	FlagReset = pinc.5

	if FlagReset = 0 then
		'read sensor
		readadc c.2,ADCReading

		'reset variable
		TankMin = ADCReading
		write 0,TankMin

	endif

displaySw:
	FlagReset = pinc.5

	if FlagReset = 1 then goto main

	'display SW level
	pinc.1 = 0	'led 10
	pinc.0 = 0	'led 9
	pinc.7 = 0	'led 8
	pinc.6 = 0	'led 7
	pinb.7 = 0	'led 6
	pinb.6 = 0	'led 5
	pinb.5 = 0	'led 4
	pinb.4 = 0	'led 3
	pinb.3 = 1	'led 2
	pinb.2 = 0	'led 1

	goto displaySW


	'read variables

	read 0,TankMin
	read 1,TankMax

main:
	'###########################
	'# check for reset         #
	'#                         #
	'# if reset whilst powered #
	'# up then reset TankMax   #
	'###########################
	FlagReset = pinc.5

	if FlagReset = 0 then
		'reset variable
		TankMax = ADCReading
		write 1,TankMax
	endif

	'read sensor
	readadc c.2,ADCReading

	debug


	'check top limit
	if ADCReading > TankMax then
		'if here then update
		TankMax = ADCReading
		write 1,TankMax
	endif

	if TankMax < TankMin then
		′if here then the transducer was calibrated on a high pressure day
		′reset transducer to a lower pressure

		TankMin=Tankmax
		write 0,TankMin
	endif


	′calculate tank quantity
	TankLevel = ADCReading - TankMin
	TankLevel = TankLevel * 256

	TankRange = TankMax - TankMin

	TankQuantity =  TankLevel / TankRange

	if ADCReading = TankMax then ′ deal with 100%
		TankQuantity = 255
	endif

	′display quantity
	if TankQuantity >= 225  then

		pinc.1 = 1	'led 10
		pinc.0 = 0	'led 9
		pinc.7 = 0	'led 8
		pinc.6 = 0	'led 7
		pinb.7 = 0	'led 6
		pinb.6 = 0	'led 5
		pinb.5 = 0	'led 4
		pinb.4 = 0	'led 3
		pinb.3 = 0	'led 2
		pinb.2 = 0	'led 1

	endif

	if TankQuantity >= 200 and TankQuantity < 225 then

		pinc.1 = 0	'led 10
		pinc.0 = 1	'led 9
		pinc.7 = 0	'led 8
		pinc.6 = 0	'led 7
		pinb.7 = 0	'led 6
		pinb.6 = 0	'led 5
		pinb.5 = 0	'led 4
		pinb.4 = 0	'led 3
		pinb.3 = 0	'led 2
		pinb.2 = 0	'led
	endif

	if TankQuantity >= 175 and TankQuantity < 200 then

		pinc.1 = 0	'led 10
		pinc.0 = 0	'led 9
		pinc.7 = 1	'led 8
		pinc.6 = 0	'led 7
		pinb.7 = 0	'led 6
		pinb.6 = 0	'led 5
		pinb.5 = 0	'led 4
		pinb.4 = 0	'led 3
		pinb.3 = 0	'led 2
		pinb.2 = 0	'led 1

	endif

	if TankQuantity >= 150 and TankQuantity < 175 then

		pinc.1 = 0	'led 10
		pinc.0 = 0	'led 9
		pinc.7 = 0	'led 8
		pinc.6 = 1	'led 7
		pinb.7 = 0	'led 6
		pinb.6 = 0	'led 5
		pinb.5 = 0	'led 4
		pinb.4 = 0	'led 3
		pinb.3 = 0	'led 2
		pinb.2 = 0	'led 1

	endif

	if TankQuantity >= 125 and TankQuantity < 150 then

		pinc.1 = 0	'led 10
		pinc.0 = 0	'led 9
		pinc.7 = 0	'led 8
		pinc.6 = 0	'led 7
		pinb.7 = 1	'led 6
		pinb.6 = 0	'led 5
		pinb.5 = 0	'led 4
		pinb.4 = 0	'led 3
		pinb.3 = 0	'led 2
		pinb.2 = 0	'led 1

	endif

	if TankQuantity >= 100 and TankQuantity < 125 then

		pinc.1 = 0	'led 10
		pinc.0 = 0	'led 9
		pinc.7 = 0	'led 8
		pinc.6 = 0	'led 7
		pinb.7 = 0	'led 6
		pinb.6 = 1	'led 5
		pinb.5 = 0	'led 4
		pinb.4 = 0	'led 3
		pinb.3 = 0	'led 2
		pinb.2 = 0	'led 1

	endif

	if TankQuantity >= 75 and TankQuantity < 100 then

		pinc.1 = 0	'led 10
		pinc.0 = 0	'led 9
		pinc.7 = 0	'led 8
		pinc.6 = 0	'led 7
		pinb.7 = 0	'led 6
		pinb.6 = 0	'led 5
		pinb.5 = 1	'led 4
		pinb.4 = 0	'led 3
		pinb.3 = 0	'led 2
		pinb.2 = 0	'led 1

	endif

	if TankQuantity >= 50 and TankQuantity < 75 then

		pinc.1 = 0	'led 10
		pinc.0 = 0	'led 9
		pinc.7 = 0	'led 8
		pinc.6 = 0	'led 7
		pinb.7 = 0	'led 6
		pinb.6 = 0	'led 5
		pinb.5 = 0	'led 4
		pinb.4 = 1	'led 3
		pinb.3 = 0	'led 2
		pinb.2 = 0	'led 1

	endif

	if TankQuantity >= 25 and TankQuantity < 50 then

		pinc.1 = 0	'led 10
		pinc.0 = 0	'led 9
		pinc.7 = 0	'led 8
		pinc.6 = 0	'led 7
		pinb.7 = 0	'led 6
		pinb.6 = 0	'led 5
		pinb.5 = 0	'led 4
		pinb.4 = 0	'led 3
		pinb.3 = 1	'led 2
		pinb.2 = 0	'led 1

	endif

	if TankQuantity < 25  then

		pinc.1 = 0	'led 10
		pinc.0 = 0	'led 9
		pinc.7 = 0	'led 8
		pinc.6 = 0	'led 7
		pinb.7 = 0	'led 6
		pinb.6 = 0	'led 5
		pinb.5 = 0	'led 4
		pinb.4 = 0	'led 3
		pinb.3 = 0	'led 2
		pinb.2 = 1	'led 1

	endif


	goto main