Measuring the Volume of Fluid in a Partially Filled Container

John Keogh | July 24, 2012

The solution that is described below stems from a problem that a few friends and I were discussing at lunch one day in Boulder, Colorado. The question is: how do you measure the volume of liquid in a partially filled, irregularly shaped container, such as a motorcycle fuel tank? The rest of this article presents one way to solve this problem based on the ideal gas law.

Throughout this article the term "gas" is used in the chemistry sense, a substance in the gaseous phase (like air). The solution I thought of to the volume measurement problem was that the ideal gas law could be used to determine the volume by introducing a known additional volume of gas into a container and determining the resulting change in pressure, which would be proportional to the volume of gas in the container. The easy way to think of this is attempting to blow air into a small space vs. a large space, it will be much more difficult to blow air into the small space since the pressure increases more rapidly.

The ideal gas law is: PV = nRT, where
P is pressure in Pascals
V is volume in cubic meters
n is the number of moles
R is the Boltzman constant (8.314 J·K−1·mol−1)
T is the Temperature expressed in Kelvin

To make this concrete, here is a table (spreadsheet) which calculates what the change in pressure should be for a 20 liter tank with the volume being adjusted with a piston which moves 5 ml of air:

Volume piston retracted (liters)Pressure (hPa)Volume piston extended (liters)Pressure (hPa)Difference (hPa)

This table ignores the difference in behavior between air and an ideal gas (this difference is called fugacity).

To test whether it is in fact possible to measure changes in volume using a piston, I used a pressure sensor on a breakout board from Sparkfun (BMP085) and an Arduino Duemilanove. You also need a sketch to read the pressure sensor, of which there are many online. I just read the serial information using the IDE, since I wanted information about the current pressure and wasn't worried about the UI. You can get a sketch here:

The apparatus was built as follows:

I used an Arizona Iced Tea container (96 ounces) and drilled 4 small holes into the cap, fed some jumper wires through and then glued them in place. Also there is a larger hole for tubing that is used to house the piston that adjusts the volume of the container.

The pressure sensor in place in the cap, which I then screwed back onto the jug.

This is a length of aluminum rod wrapped with Teflon tape. The rod plunges into the tubing to adjust the effective volume of the container. The volume is the container itself plus the tubing up to the plunger, so if the plunger moves in or out the volume changes.

The complete test apparatus with the serial port connected to my laptop. I ran several tests with different volumes of water in the container.

The results in Pascal were:

Empty container:

  • plunger out 99352
  • plunger in 99490
  • difference 138
Half full:
  • plunger out 99357
  • plunger in 99512
  • difference 155
Almost full:
  • plunger out 99356
  • plunger in 99765
  • difference 409

From the results above, this approach works. My readings fluctuated, but I could reliably determine the approximate volume of fluid in the container. The largest source of errors when I was testing was water that wasn't equilibrated to room temperature. When using room temperature water, the readings were very consistent.

Eyesbot Company

Computer vision

Artificial intelligence

Effecting the physical world