Tank level control with an analog input

Most real processes are measured with analog sensors: level, pressure, temperature, flow. This tutorial reads a 0–10 V level transmitter on the analog input of a Siemens S7-1200, converts the raw value to a percentage with SCALE, and controls a filling pump with hysteresis and a high-level alarm. You will build it in Virtuino Circuits and change the level with a slider during simulation.

Open the ready-made circuit in the simulator

The task

  • The pump fills the tank. It starts when the level drops below 20 % and stops when the level reaches 80 %.
  • Between 20 % and 80 % the pump keeps its last state. This is the hysteresis: without it the pump would switch on and off continuously around a single set-point.
  • Above 95 % an alarm lamp lights.
  • A selector switch enables automatic operation.

From volts to percent

The S7-1200 converts 0–10 V on its analog input into a raw number from 0 to 27648, at address %IW64 (first channel). 5 V is 13824. Other PLCs use other ranges: S7-200 0–32000, LOGO! and M221 0–1000. The SCALE instruction converts the raw value into an engineering value:

LEVEL = MIN + IN / RAW_MAX × (MAX − MIN), here LEVEL = 0 + %IW64 / 27648 × 100.

In the simulator, SCALE gives the result a name (for example LEVEL) that comparison contacts can use directly.

Wiring

  1. Place the PLC and choose S7-1200 CPU 1214C. Supply it from L1/N.
  2. From Analog place a transmitter 0–10 V. In its properties choose level and the range 0–100 %. It has three terminals: L+, U (signal) and M.
  3. Supply the transmitter from 24 V DC (L+ and M). Connect U to the first analog input of the PLC and M to the analog common. Analog wires are drawn in orange.
  4. Digital input .0: selector switch S1 "Auto" from L+.
  5. Outputs: .0 → coil K1 of the pump contactor (and a pump in the power circuit if you like); .1 → red alarm lamp H1.

Ladder program

 Rung 1 – Scale the level
                     SCALE  IN = %IW64   0…27648 → 0…100   OUT = LEVEL
 |-------------------[                                          ]----|

 Rung 2 – Start the pump below 20 %
      %I0.0    [ LEVEL < 20 ]                               %Q0.0
 |-----| |-------[          ]-----------------------------------(S)--|

 Rung 3 – Stop the pump at 80 % or when Auto is off
      [ LEVEL >= 80 ]                                       %Q0.0
 |-----[            ]---+---------------------------------------(R)--|
      %I0.0             |
 |-----|/|--------------+

 Rung 4 – High level alarm
      [ LEVEL > 95 ]                                        %Q0.1
 |-----[           ]--------------------------------------------( )--|
  1. From the analog group place SCALE. Set the input to %IW64, the range to 0–100, and the name to LEVEL.
  2. From the comparisons group place a < contact with LEVEL and 20, in series with the Auto input, and end the rung with a Set coil %Q0.0.
  3. Place a >= contact with LEVEL and 80, in parallel with a NC contact %I0.0, and end the rung with a Reset coil %Q0.0. The Reset rung is last, so stopping always wins.
  4. Add the alarm rung with a > 95 comparison and a normal coil %Q0.1.

Simulate

  1. Press F5, switch S1 to Auto and open the Ladder window.
  2. Click the transmitter: a large slider opens. Set the level to 50 %. The raw value next to the analog input shows about 13824, and LEVEL shows 50. The pump stays off.
  3. Move the level down to 15 %: the pump starts. Move it up to 60 %: the pump keeps running, because of the hysteresis. At 80 % it stops.
  4. Move the slider above 95 %: the alarm lamp lights.
On a real installation, also add a separate float switch for the high level, wired directly in the contactor circuit. Safety functions should not depend only on an analog measurement and a PLC program.

Next steps

  • Use UNSCALE and a frequency inverter to run the pump at variable speed proportional to the level error. See Analog signals.
  • Count the filling cycles with a counter, as in the conveyor tutorial.

Open this circuit in the simulator