Calculating Tank Volume in LOGO! with 4-20mA Pressure Sensors

David Krause18 min read
PLC HardwareSiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Five vertical cylindrical tanks, each 800 mm in diameter and 800 mm tall, hold liquids of different density: water, salt solution, sugar syrup, yeast slurry, and vegetable oil. A hydrostatic pressure transmitter (4-20 mA, 0-16000 Pa) is mounted at the bottom of every tank. The control task is to compute, on a Siemens LOGO! logic module, the live liquid volume in liters and the live mass in kilograms for every vessel and to expose those values to an attached LOGO! TD or push them upstream via Modbus TCP.

The hydrostatic math chain is short on paper but creates real numeric-range problems inside a LOGO!. A raw 4-20 mA signal is normalised to a 0-1000 internal count, which scales to a water-equivalent head that can exceed 1.6 m for a tank only 0.8 m tall. Once that head is multiplied by the 5027 cm² cross section, the result sits well outside the 16-bit signed range (±32 767) that older LOGO! generations are bound to. The cure is unit selection: work in decimetres for height, decimetres squared for area, and decimetres cubed (= litres) for volume. Every intermediate product then stays inside a numeric range the LOGO! math blocks handle natively.

1. Problem Overview and Architecture

The complete signal chain is short: pressure transmitter → AM2 analog input → LOGO! math → LOGO! TD / Ethernet / HMI. The signal chain diagram below shows the topology from sensor to display.

Tank h (dm) P 4-20 mA LOGO! 8.3 + AM2 AI → k × ρ → π × r² × h m (kg), V (L) Modbus TCP HMI / TD / SCADA V = 245.3 L m = 245.3 kg

The control objective is straightforward, but the LOGO! imposes three constraints that the program must respect: (a) integer math blocks top out at ±32 767, (b) the analog input normalisation is 0-1000 over the full input span, (c) the AM2 module provides only two AI channels, so three AM2 modules are needed for six tanks. The sections below resolve all three constraints.

2. Tank and Sensor Specifications

Parameter Value Notes
Tank inside diameter 800 mm (8 dm) Perfect cylinder, vertical orientation
Tank inside height 800 mm (8 dm) Freeboard above the liquid level assumed constant
Cross-section area A 50.265 dm² A = π × r² = π × 4²
Max water-equivalent head 800 mm Full tank, ρ_water = 1000 kg/m³
Max liquid volume 402.12 L V_max = A × h_max = 50.265 × 8
Max mass (water) 402.12 kg m = ρ × V
Pressure sensor range 0-16000 Pa / 4-20 mA Hydrostatic, gauge reference
Sensor full-scale water head 1.631 m 16000 / (1000 × 9.81)
Sensor utilisation at 800 mm water 49.0% 800 / 1631 = 0.4905
Current at full water tank 11.85 mA 4 + 0.4905 × 16
Loop voltage drop (250 Ω input) 1.0 - 5.0 V LOGO! AM2 input impedance 250 Ω
Base LOGO! module 6ED1052-1MD08-0BA2 (12/24 RCE) Ethernet variant required for Modbus TCP export
Analog expansion 6ED1055-1MA00-0BA2 (AM2) Two 0-10 V or 0/4-20 mA inputs each
LOGO! firmware LOGO! 8.3 (FS5 or later) Stable Analog Math block
Programming software LOGO! Soft Comfort V8.3 FBD or Ladder editor

Reference: Siemens Industry Online Support for the LOGO! 8 system manual and the LOGO! Soft Comfort V8.3 programming manual. The LOGO! product page is at siemens.com/logo.

3. Hydrostatic Pressure Principle

The pressure at the bottom of a static liquid column is given by:

P = ρ × g × h

Where:

  • P = hydrostatic pressure (Pa)
  • ρ = liquid density (kg/m³)
  • g = gravitational acceleration (9.81 m/s²)
  • h = vertical liquid height (m)

Rearranged to solve for height:

h = P / (ρ × g)

For a transmitter calibrated against water (ρ = 1000 kg/m³) at 9.81 m/s², the head in millimetres is:

h_water (mm) = P (Pa) / 9.81

This gives the water-equivalent height. When the tank holds a different liquid, the same pressure corresponds to a different actual height:

h_actual = h_water × (ρ_water / ρ_liquid) = h_water × k

Most industrial hydrostatic transmitters are calibrated against water at 4 °C and g = 9.81 m/s². The 9.81 divisor above is exact enough for field work; for laboratory-grade accuracy use 9.80665. Re-derive k for any liquid whose density deviates from the design value by more than 2%.

4. Density Table for the Five Process Liquids

Tank Liquid Density ρ (kg/L) k = ρ_water / ρ Max mass at 402.12 L (kg)
1 Water (4 °C reference) 1.000 1.000 402.12
2 Saturated NaCl solution (~26% w/w at 20 °C) 1.200 0.833 482.55
3 Sugar syrup (~65 °Brix at 20 °C) 1.320 0.758 530.80
4 Yeast cream slurry (~18% dry solids) 1.050 0.952 422.23
5 Rapeseed vegetable oil (20 °C) 0.920 1.087 369.95

Reference density values are taken from standard handbooks (Perry's Chemical Engineers' Handbook, CRC Handbook). For exact process-grade density, sample the liquid with a hydrometer or oscillating-tube densitometer and enter that value into the LOGO! parameter.

Density varies with temperature and concentration. Recalculate k whenever the recipe changes or whenever the bulk temperature drifts more than 10 °C. Yeast slurry in particular exhibits thixotropic behaviour: density readings taken at rest differ from those taken during agitation.

5. Sensor Scaling: 4-20 mA to Liquid Height

The LOGO! AM2 module presents the analog input as a normalised integer in the range 0-1000 corresponding to the configured input span:

Current (mA) AI raw Pressure (Pa) Water head (mm) Tank fill (%)
4.0 0 0 0 0
8.0 250 4000 408 51 (water)
11.85 490 7848 800 100 (water)
20.0 1000 16000 1631 Sensor FS

There are two ways to map the sensor inside the LOGO! program.

5.1 Method A — full sensor range (recommended)

Use the full 0-1000 raw range and clamp the result at the tank's inside height in software. This preserves sensor resolution at the bottom of the tank and keeps the formula correct for sub-water-density liquids (which produce an actual head larger than the water-equivalent head for a given pressure).

h_water (mm) = AI_raw × 1.631

h_actual (mm) = h_water × k

h_clamped (mm) = MIN(h_actual, 800)

5.2 Method B — direct mapping to tank range

Stretch the 0-1000 raw range so that 100% raw corresponds to the tank height:

h_water (mm) = AI_raw × 0.800

This wastes the unused upper sensor span and produces a direct percentage readout. Do not use this method when the process liquid is less dense than water, because the actual head can exceed 800 mm for a 0.8 m fill and the formula must still compute a valid (if clamped) result.

6. Volume Calculation: Cylinder Geometry

The inside of the tank is a vertical cylinder:

V = π × r² × h

With r = 400 mm = 4 dm and h in decimetres, the cross-section is:

A = π × 4² = 50.265 dm² ≈ 50.27 dm²

Volume in decimetres cubed (= litres) becomes:

V (L) = 50.265 × h (dm)

With h_max = 8 dm, V_max = 402.12 L. The same value in cm³ is 402 123 cm³ and in mm³ is 402 123 858 mm³. The cm³ and mm³ representations exceed the LOGO! 16-bit signed range (±32 767) and force the use of floating-point math. Working in decimetres keeps every intermediate product within ±32 767 even on legacy firmware.

Unit for h Unit for V Maximum numeric value LOGO! 8 integer safe?
mm mm³ 402 123 858 No — use Analog Math
mm cm³ 402 124 No — exceeds 16-bit
cm cm³ 402 124 No — exceeds 16-bit
cm L 402.12 Yes
dm L (dm³) 402.12 Yes

7. Mass Calculation: Density Compensation

Mass in kilograms equals volume in litres multiplied by density in kg/L:

m (kg) = ρ (kg/L) × V (L)

The density constants are entered directly in the LOGO! Math block "Gain" parameter. Implement a separate gain per tank so that swapping a tank's content only requires changing one parameter.

8. LOGO! Numeric Limitations and Workarounds

LOGO! 8 supports two arithmetic modes:

  • Integer blocks (Addition B001, Subtraction B002, Multiplication B003, Division B004, Math B020 with integer flag): signed 16-bit range ±32 767. Adequate for head (0-8 dm) and volume (0-402.12 L) when all inputs are scaled to dm and L.
  • Analog Math block (B021 in LOGO! Soft Comfort V8.3): 32-bit floating-point, full ±3.4 × 10³⁸ range. Required if the calculation stays in cm³ or mm³, or if intermediate gains exceed ±32 767.

Choose one approach and keep it consistent across all five tanks so that the engineering and troubleshooting logic stay uniform.

LOGO! 6 and earlier generations used 16-bit signed integers for every analog value. On those modules, decimetre-based arithmetic is mandatory. On LOGO! 8.3 firmware the Analog Math block removes that constraint, but converting to decimetres remains the cleanest implementation and is portable to older hardware.

For each tank, three Math blocks in series run the formula end-to-end:

  1. AI → Gain 1.631 → h_water (mm)
  2. h_water × Gain (0.01 m/dm) × Gain k → h_actual (dm)
  3. h_actual × Gain 50.265 × Gain ρ → mass (kg)

Alternatively, combine steps 2 and 3 in a single block by entering Gain = (k × 50.265 × ρ) and Gain = 1.631 / 100 to keep the chain at two Math blocks. The exact gain depends on the liquid in that tank.

9. Hardware Wiring and AI Channel Allocation

Each tank requires its own AI channel. The base LOGO! 12/24 RCE (6ED1052-1MD08-0BA2) has no onboard analog inputs; expansion is required:

Module Order number AI count Type
LOGO! AM2 6ED1055-1MA00-0BA2 2 0-10 V or 0/4-20 mA
LOGO! AM2 AQ 6ED1055-1MB00-0BA2 2 AI + 2 AQ 0-10 V or 0/4-20 mA
LOGO! AM2 RTD 6ED1055-1MA00-0BA2 (RTD variant) 2 Pt100/Pt1000 only

Three AM2 modules cover the six required AI channels. Wire each transmitter's positive lead to the AI terminal and the negative lead to the module's M terminal. Provide 24 V DC loop power from the LOGO! power supply or from an external 24 V rail; the AM2 input impedance is 250 Ω, so a 4-20 mA loop drops 1-5 V across the AM2 terminals.

AI channel addressing in LOGO! Soft Comfort V8.3:

  • AM2 #1 slot: AI1, AI2 → tanks 1, 2
  • AM2 #2 slot: AI3, AI4 → tanks 3, 4
  • AM2 #3 slot: AI5, AI6 → tank 5 (uses only one channel)

10. FBD Implementation in LOGO! Soft Comfort V8.3

Open LOGO! Soft Comfort V8.3 and create a new project for the LOGO! 12/24 RCE base module. Insert three AM2 expansion modules in the hardware catalog. The function block diagram is repeated identically for each tank, with only the density constant changing.

10.1 Step-by-step for one tank (water, tank 1)

  1. Insert an Analog Input block. Select AI1, set sensor type to 0-20 mA with 4 mA zero offset enabled.
  2. Insert a Math (B020) with arithmetic option = Gain: Gain = 1.631, Offset = 0. Input is AI1. Output is h_water_mm (range 0-1631).
  3. Insert a second Math (B020) Gain: Gain = 0.010 (mm → dm conversion). Output is h_water_dm (range 0-8.131).
  4. Insert a third Math (B020) Gain: Gain = k_tank1, where k_tank1 = 1.000 for water. Output is h_dm (range 0-8.131).
  5. Insert a Min block (B021): input A = h_dm, input B = constant 800 (mapped to 8.00 dm in 0.01 dm resolution). Output is h_clamped_dm.
  6. Insert a fourth Math (B020) Gain: Gain = 50.265 (cross-section area in dm²). Output is V_L (range 0-402.12 L).
  7. Insert a fifth Math (B020) Gain: Gain = 1.000 (density of water in kg/L). Output is m_kg (range 0-402.12 kg).
  8. Route V_L and m_kg to the LOGO! TD display blocks or to the VM address mapping for Ethernet export.

10.2 Parameter set for the four non-water tanks

Tank Liquid Density ρ (kg/L) k = ρ_water / ρ Density gain (kg/L)
1 Water 1.000 1.000 1.000
2 Salt solution 1.200 0.833 1.200
3 Sugar syrup 1.320 0.758 1.320
4 Yeast slurry 1.050 0.952 1.050
5 Vegetable oil 0.920 1.087 0.920

10.3 Combined gain shortcut

The chain in 10.1 can be collapsed into two Math blocks per tank by combining the gains:

  • Block 1: AI1 → Gain = 1.631 / 100 × k_tank = 0.01631 × k_tank. Output is h_dm directly.
  • Block 2: h_dm → Gain = 50.265 × ρ_tank. Output is m_kg.
  • Min block: clamps h_dm at 8.00 dm.
  • Display: V_L = m_kg / ρ_tank (a single division block).

For tank 1 (water, k = 1.000, ρ = 1.000): Block 1 Gain = 0.01631, Block 2 Gain = 50.265. For tank 5 (oil, k = 1.087, ρ = 0.920): Block 1 Gain = 0.01773, Block 2 Gain = 46.244.

11. Resolution, Refresh, and Display

The LOGO! analog input increments in 1000 steps over 0/4-20 mA (16 µA per step). For a 0-1631 mm water head, one AI step = 1.631 mm. For a 402.12 L full-scale volume, one AI step = 0.402 L. That resolution is sufficient for batch tracking but is too coarse for inventory control of small batches.

For higher resolution, substitute an AM2 module with a sensor whose full-scale matches the tank height:

  • If a 0-10 000 Pa sensor is installed, the AI mapping becomes 0-10 000 Pa / 1000 = 10 Pa per step. Head resolution: 10 / 9.81 = 1.02 mm per step.
  • If a 0-5 000 Pa sensor is installed, head resolution is 0.51 mm per step.

LOGO! analog blocks update at the program scan rate, typically 50-100 ms with full expansion. The displayed value flickers if scanned too fast. Use a moving-average filter (PT1 block B005 in LOGO! Soft Comfort) with T = 2 s on each AI before feeding it into the math chain to suppress pump-induced pressure spikes.

12. Verification and Commissioning Procedure

  1. Power the LOGO! base and AM2 modules. Confirm the green LED on each module and the absence of the SF (system fault) indicator on the LOGO! display.
  2. Open the LOGO! online test in Soft Comfort V8.3. Right-click AI1 and select Force AI. Force AI1 = 0 (corresponds to 4 mA, 0 Pa, empty tank). Verify V_L = 0 and m_kg = 0.
  3. Force AI1 = 490 (corresponds to 11.85 mA, 7848 Pa, water at 800 mm). Verify V_L = 402.12 L and m_kg = 402.12 kg for the water tank.
  4. Force AI1 = 1000 (corresponds to 20 mA, 16000 Pa, sensor full scale). Verify the Min block clamps h_dm at 8.00 dm and V_L remains at 402.12 L. If V_L exceeds 402.12, the Min block is missing or the constant is wrong.
  5. Repeat for AI2-AI6 with each tank's density constant. For tank 5 (vegetable oil), forcing AI5 = 490 should give h_water_mm = 800, h_dm_actual = 800 × 1.087 / 100 = 8.696 dm (above tank height). The Min block must clamp it to 8.00 dm, giving V_L = 402.12 L and m_kg = 402.12 × 0.920 = 369.95 kg.
  6. Fill tank 1 with water to 50% height (400 mm). Read the live value on the TD. V_L should read 201.06 ± 0.40 L and m_kg should read 201.06 ± 0.40 kg.
  7. Pull the 4-20 mA loop off the sensor and inject a calibrated 12.00 mA from a precision current source. Confirm h_water_mm = 500 × 1.631 = 815.5 mm → h_dm = 8.155 → Min clamps to 8.00 → V_L = 402.12 L. Any value above 402.12 indicates the Min block is bypassed or misconfigured.
  8. Inject 6.00 mA. Confirm h_water_mm = 125 × 1.631 = 203.9 mm → h_dm = 2.039 → V_L = 102.49 L. Cross-check against a manual tape measurement of the water column.

13. Troubleshooting Matrix

Symptom Likely cause Diagnostic Corrective action
V_L reads 0 even when tank is half full Sensor loop polarity reversed or loop open Measure DC voltage across AI+ and AI- terminals Swap loop wires at the AM2 terminal; restore 24 V loop supply
V_L pegs at 402.12 L continuously AI raw = 1000, input saturated Check sensor excitation voltage; confirm 24 V at transmitter Restore loop power or replace defective transmitter
V_L negative Sensor installed above the lowest expected liquid level Inspect sensor mounting height relative to tank bottom Mount sensor at or below the lowest expected liquid level
V_L oscillates ±10 L Pump-induced pressure spikes or unfiltered AI Inspect process piping; monitor raw AI on Soft Comfort Add a PT1 filter (B005) with T = 2-5 s on the AI input
m_kg reads lower than expected for the oil tank Density gain was left at 1.000 Check parameter block for tank 5 Set density gain to 0.920 kg/L for vegetable oil
m_kg reads higher than expected for the syrup tank Density gain left at 1.000 or k applied twice Inspect Math blocks in the chain Set density gain to 1.320 kg/L; verify only one k block is in the head path
SF (system fault) LED on AM2 Module not seated, wrong catalog number, or bus termination issue Pull and reseat module; check order number Use 6ED1055-1MA00-0BA2 (AM2), not the RTD-only module
"Value out of range" error in Soft Comfort simulation Math block gain or output exceeds 32-bit float only on legacy firmware Check LOGO! firmware version in the project properties Upgrade to LOGO! 8.3 FS5 or later; switch to decimetre units if older firmware persists
LOGO! TD display flickers or shows "---" VM address not connected to display block Inspect Message Text block configuration Reassign the display block to the correct VM word from the Math output
Volume reads correctly but mass is off by exactly ρ × factor Density gain parameter accidentally entered as 10 × ρ Inspect the Math block Gain field Set the Gain to the density value in kg/L, not in kg/m³
Reading is correct at empty and full but wrong at intermediate level Non-linear sensor or k factor wrong Force three AI levels (0, 500, 1000) and plot against known tank fill Recalculate k against the actual liquid density; check sensor linearity spec

14. Edge Cases and Field Notes

  • Aerated liquids (yeast slurry): the head reading can show a 2-5% error due to entrained gas reducing the effective hydrostatic pressure. Either accept the error within tolerance or install a bubble-trap pulse line between the sensor and the tank.
  • Crystallising liquids (saturated salt): salt crystals clog the sensor diaphragm over time and bias the reading high. Pull and clean the diaphragm monthly; flush with warm water before re-insertion.
  • Temperature drift: density varies with temperature. Water at 4 °C is 1.000 kg/L; at 80 °C it drops to 0.972 kg/L. If the process temperature swings by more than 20 °C, add a Pt100 input and a temperature-density lookup table implemented as a sequence of comparator blocks.
  • Tank tilt: the formula assumes a perfect vertical cylinder. A tilted or dented tank introduces a volume error. The hydrostatic method reads the true head regardless of tank geometry, so the result is the volume of the actual liquid in that shape, but it is not necessarily the value shown on a strapping table generated for the as-built vessel.
  • Foam (yeast): foam contributes to hydrostatic head but not to commercial mass. If foam exceeds 5% of total head, fit a foam-suppression nozzle above the sensor or apply an empirical foam-density correction.
  • Sensor warm-up: most hydrostatic transmitters need 30-60 s after power-on to stabilise. The LOGO! startup delay (configurable under File → Properties → Startup) must cover that interval, otherwise the first reading can transiently read zero and the Min block clamps the value to 0 L until the next scan.

15. Alternatives and Migration Paths

For applications where the LOGO! numeric gymnastics are too constrained or where more than six tanks are needed, step up to a Siemens S7-1200 CPU with an SM 1231 AI module (order number 6ES7231-4HF32-0XB0 for 8 AI). The S7-1200 handles 32-bit floating-point natively, offers a higher scan rate, and supports up to 16 AI channels on a single module. The same pressure transmitter and the same formulas apply; only the controller and the math block library change. For purely supervisory volume tracking without local control, an external weighing indicator or load-cell-based level sensor avoids density altogether but requires a structural change at the tank.

For mobile field verification during commissioning or after a recipe change, a hydrostatic tank volume calculator can verify the math outside the LOGO!. Confirm any such tool against a manual calculation using π × r² × h before trusting its readings in a regulated process.

16. Frequently Asked Questions

Why does my LOGO! show 0 L when the tank is clearly full?

Most often the AI raw value is 0 because the 4-20 mA loop is broken. Check loop power (24 V DC) and the polarity at the AM2 terminal. With the loop open, AI raw sits at 0 and V_L stays at 0; with the loop shorted, AI raw pegs at 1000 and V_L reads 402.12 L. Both are wrong; the wiring is the suspect in either case.

Can I keep the calculation in cm³ and just use the Analog Math block?

Yes. LOGO! 8.3 firmware (FS5 and later) supports 32-bit floating-point math via the Analog Math block, so 402 124 cm³ fits without overflow. The decimetre-based approach is recommended only because it stays inside the simpler integer block set and is portable to older LOGO! 6/7 firmware.

What is the correct density for saturated salt solution and 65 °Brix sugar syrup?

Saturated NaCl at 20 °C is 1.200 kg/L. A 65 °Brix sucrose solution at 20 °C is 1.320 kg/L. Recalibrate whenever the concentration or temperature drifts more than 5% from the design point. Yeast cream slurry at 18% dry solids sits around 1.050 kg/L, and rapeseed vegetable oil at 20 °C is 0.920 kg/L.

My vegetable oil tank shows a mass larger than the water tank at the same fill height. Is the sensor wrong?

No. The sensor is calibrated for water, so for oil the displayed hydrostatic head is larger than the actual oil head (oil is less dense). The density correction factor k = ρ_water / ρ_oil = 1.087 then expands the head further. The Min block must clamp the result at 8.00 dm so that V_L never exceeds 402.12 L, regardless of liquid. Below the clamp, mass for the oil is correctly lower than mass for water at the same actual fill height.

How do I export the live values to a SCADA or HMI?

Wire each Math block output to a VM address (for example VW0-VW9). The LOGO! 8.3 base module with Ethernet (RCE or RCEo variant) exposes those VM words over Modbus TCP or S7 communication. A WinCC, HMI panel, or third-party SCADA can poll the VM words at 200 ms to display live volume and mass without disturbing the LOGO! program scan.

Back to blog