IMDHMIControls LibraryShop main store

How-to

Latch two level inputs for pump start and stop control

PLC programming Published 7 min read

Short answer

Use one reset-dominant latch: set the pump when the low level probe reads dry and reset it when the high probe reads wet, so the pump holds its state between the probes. A rung that only compares the inputs drops out the moment water covers the low probe; the latch turns the probe spacing into hysteresis.

On this page
  1. Why two level inputs need stored state
  2. Name and filter the probes before writing logic
  3. Build the latched rung step by step
  4. Working the latch through the four input states of one tank cycle
  5. Test it in simulation before hardware
  6. Failure modes this design must cover
  7. The decisions, case by case
  8. Questions asked

Two digital level sensors and one pump output are a correct design for a tank that fills and empties between two heights, provided the logic stores state between the probes. Use one reset-dominant latch: set the pump when the low probe reads dry, reset it when the high probe reads wet. A rung that merely compares the two inputs drops out the moment water covers the low probe, so the pump cycles on the bottom probe instead of filling the tank. This article builds the latched rung step by step, works the logic through all four input states the sensors can produce, and lists the checks to add before the pump runs unattended.

Why two level inputs need stored state #

Trace the signal path once and the need for memory is obvious. While the level sits between the probes, the inputs read low probe wet, high probe dry, the identical combination whether the tank is filling or draining. Rising, the pump must keep running; falling, it must stay off. The same inputs demand different outputs, so the program needs a stored bit, and that bit is the latch. With it, the pump starts when the level falls to the low probe and runs until the level reaches the high probe: the probe spacing becomes the hysteresis band, the same two-threshold hold that a boiler pump hysteresis example holding state between 75 and 80 °C works with in temperature.

Name the design for what it is: a two-point controller, on or off between two thresholds. For a fill-and-empty duty that is the correct and complete architecture, and it does not need to regulate. Holding one specific level while water enters and drains at varying rates is a different job: it needs an analog transmitter, a variable-speed pump and a closed loop, because between two probes the control has only two states and cannot chase a setpoint.

Name and filter the probes before writing logic #

Name each input by what it means, not by its terminal. In this article the names are illustrative: xLowWet is TRUE when water covers the low probe, xHighWet likewise, so the wet or dry meaning travels with the variable instead of hiding in a comment. Mount the low probe below the high one, because that ordering hands the logic its fault check for free: water that covers the high probe must also cover the low one, so high wet while low dry cannot occur in a healthy installation.

Then filter the inputs. Slosh makes a probe flicker as waves cross it, and an on-delay of a few seconds, set from the observed slosh at each probe position, holds the signal steady. Feed the timer outputs to the latch, never the raw probes; the latch must see levels, not waves.

Build the latched rung step by step #

  1. Create the two input variables and one output variable with the wet and dry names above, and bind them to the physical channels in the device I/O mapping; take the real channel addresses from your own I/O module, not from any example.
  2. Put an on-delay timer on each probe input and route the timer outputs, not the raw probes, into the logic.
  3. Write the latch with reset dominance. In ladder, program a set coil on the rung that fires when the low probe is dry and a reset coil on the rung that fires when the high probe is wet, with the reset rung placed after the set rung so a stop wins in the same scan if a start and a stop ever coincide, for example once interlocks are added to the set rung. If your runtime ships a reset-dominant RS block, call that instead: start condition into its set input, stop condition into its reset input, pump command off its Boolean output; a comparison of set-dominant and reset-dominant latch blocks shows why the reset-dominant polarity is the one a pump stop should use.
  4. Add the fault check: high wet while low dry forces the pump command off and raises a latched fault.
  5. Add a maximum-run timer on the pump command, its preset derived as tank volume divided by pump flow plus a margin, both numbers read from the tank and pump datasheets. Latch the fault it raises and clear it only from a physical reset input.
  6. Run the whole program in simulation and step it through the four input states in the worked example below before anything is wired to the starter.
// Illustrative names for this article, not library identifiers
VAR
  xLowWet     : BOOL := FALSE; // TRUE when water covers the low probe
  xHighWet    : BOOL := FALSE; // TRUE when water covers the high probe
  xFaultLevel : BOOL := FALSE; // high wet while low dry: probe or wiring fault
  xRunTimeout : BOOL := FALSE; // output of the maximum-run timer
  xPumpCmd    : BOOL := FALSE; // command to the pump starter contactor
END_VAR

xFaultLevel := xHighWet AND NOT xLowWet;

// Reset branch first, so a stop wins whenever a stop and a start coincide
IF xHighWet OR xFaultLevel OR xRunTimeout THEN
  xPumpCmd := FALSE;
ELSIF NOT xLowWet THEN
  xPumpCmd := TRUE;
END_IF;

The worked example below is the test that proves this rung: step the inputs through it and compare the pump column.

Working the latch through the four input states of one tank cycle #

Inputs: two Booleans from the two digital inputs of the tank build, xLowWet and xHighWet, each TRUE when water covers its probe and FALSE when it does not. Two Booleans produce exactly four combinations, so the evaluation below is exhaustive and assumes nothing beyond the probes being mounted low then high. The latch bit starts FALSE after power-up.

Rule in words: the pump goes TRUE when the set condition fires, and the set condition is the low probe dry; it goes FALSE when the reset condition fires, and the reset condition is the high probe wet; when neither fires it holds its previous value; and a true reset always beats a true set in the same scan.

Arithmetic, one scan per row:

Scan Level xLowWet xHighWet SET = NOT xLowWet RESET = xHighWet Latch action Pump
1 empty FALSE FALSE NOT FALSE = TRUE FALSE set fires ON
2 rising, between probes TRUE FALSE NOT TRUE = FALSE FALSE neither fires, holds ON
3 full TRUE TRUE FALSE TRUE reset fires, output off OFF
4 falling, between probes TRUE FALSE FALSE FALSE neither fires, holds OFF
5 empty again FALSE FALSE NOT FALSE = TRUE FALSE set fires ON

Result: over the cycle the pump reads ON, ON, OFF, OFF, ON. Scans 2 and 4 have identical inputs and different outputs, and that difference, held in the latch bit, is the entire hysteresis. The combination the table omits is xLowWet FALSE with xHighWet TRUE, which cannot occur with the probes in order; the fault check forces the pump off and raises the fault if it ever appears. Read scan 2 through a bare comparison instead and the arithmetic fails: pump = NOT xLowWet = NOT TRUE = FALSE, so the pump stops the moment the water covers the low probe.

Decision: read one value off your own program, the pump output in scan 2. FALSE there means the rung is a bare comparison and the pump will stop at the low probe on every cycle, so replace the rung with the reset-dominant latch. TRUE in scan 2 together with FALSE in scan 4 means the latch is correct.

Test it in simulation before hardware #

Run the project in the runtime's simulation mode and write TRUE and FALSE to xLowWet and xHighWet by hand in the watch or online view; no controller and no HMI are needed. Step the inputs through scans 1 to 5 and check the pump against the table column. Then run the three fault tests: hold the pump on past the maximum-run preset and confirm the timeout trips and stays until reset; write the impossible combination and confirm the forced off and the fault; and restart the simulation with the tank partly filled to see which state the latch wakes up in.

Failure modes this design must cover #

  • Probe order reversed in the wiring or the program: the pump then fills on the high signal and the fault check trips at once. Check each input online against a wet probe before enabling the output.
  • Low-probe wire break reading dry: the pump starts on the false dry and fills past the low probe; the fault check stops it at the high probe and latches the fault.
  • High-probe wire break reading dry: no software input can stop the pump. A software latch cannot protect the tank from its own sensor failing, so an independent high-level cutout float wired directly into the pump starter control circuit, not through the PLC, is the overflow protection.
  • Dry running: the maximum-run timer catches a stuck probe, not an empty supply; if the source itself can run out, the protection belongs on the suction side.
  • Starter chatter on a tank with short probe spacing: add a minimum off-time between starts so the contactor is not cycled wave by wave.

The decisions, case by case #

Case Decision
Tank fills and empties between two heights Two digital probes with a reset-dominant latch; correct and complete, no regulation needed
Pump output FALSE with the level rising between the probes The rung is a bare comparison; replace it with the latch
Pump runs unattended Independent high-level cutout in the starter circuit, software faults latched until a physical reset
Supply can run out Dry-run protection on the suction side; the run timer does not cover it
Probe spacing short, starter cycling fast Minimum off-time between starts

Those five rows settle a two-sensor tank build: the scheme is right for the duty, and the one thing it cannot do without is the latch.

Questions asked

What happens to the pump command after a power cycle?

A plain Boolean latch initializes to FALSE, so the pump starts only when a scan evaluates the set condition again. If the tank is partly filled above the low probe, the pump stays off until the level drains below it. Decide deliberately whether the latch is retentive or re-evaluated on power-up, then test both a dry and a partly filled tank in simulation.

Why does the reset rung go after the set rung in ladder?

Ladder coils evaluate from top to bottom, so when the set and reset conditions are both true in the same scan, the coil programmed last decides the output. Placing the reset coil last makes the stop dominant. A reset-dominant RS block produces the same result inside the block, which is why either form is safe for a pump stop.

When are two level switches no longer enough?

When the process must hold one specific level while water enters and drains at varying rates. Between two probes the control is on or off only. That duty needs an analog level transmitter feeding a closed-loop controller and a variable-speed pump, and the program grows to include scaling, limits, anti-windup and tuning.

How long should the debounce time on the level probes be?

Set it from observed slosh at each probe position. Run the pump once, watch the input flicker as waves cross the probe, and set the on-delay just longer than the longest flicker. Too long a delay postpones the pump start on an emptying tank and slows the stop on a filling one.

Keep reading

  • Explainer

    What STEP 7 is in a PLC project, and which one you need

    STEP 7 is the engineering software you use to program, configure, diagnose and download to SIMATIC PLCs — a workstation tool, not a part of the PLC itself. SIMATIC Manager, also called STEP 7 Classic, configures S7-300 and S7-400 CPUs; STEP 7 inside TIA Portal configures S7-1200 and S7-1500. Read the CPU family from the module label or the existing project, open the matching environment, and confirm the project's hardware configuration matches the installed CPU before you edit or download.

    PLC programming

  • How-to

    How to build ladder logic practice projects in STEP 7

    Get STEP 7 ladder practice projects from the vendor's own support portal and from the samples the installer already placed on your PC, not from a copy of a book's bundled disk. Then rebuild three circuits yourself: a start/stop latch with overload interlock, an on-delay timer sequence, and an up/down counter.

    PLC programming

  • Troubleshooting

    Why Modbus cannot transfer a PLC ladder program over TCP

    No Modbus address reaches ladder memory: the application protocol defines four data tables — coils, discrete inputs, input registers, holding registers — and program storage is not in any of them. Swapping RTU for TCP changes transport, not protocol. On DirectLogic PLCs the program moves only over K-Sequence or DirectNET through the vendor's programming tools; Modbus stays for mapped user data.

    PLC programming