Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 37 ยท Projects and Practice

PLC Project - Tank Level Control with Pumps and Alarms

Build a tank level controller: analog scaling, hysteresis on/off control, duty/standby pump alternation, dry-run protection, alarms and a PID idea, with runnable C simulation.

Water tanks, chemical vessels, silos: controlling a level is one of the most common automation tasks. This project mixes analog input scaling, on/off control with hysteresis, two pumps that take turns, protection against faults and alarms. You will design the logic, then run a simulated tank in C.

Real PLC hardware is not available on this site, so the design is shown as a plan and read-only text, and the runnable programs are C stand-ins simulating the tank and the controller.

Requirements

A storage tank is filled by an inlet valve and emptied by consumers. Two fill pumps (P1, P2) feed it from a well. A 4-20 mA level transmitter measures 0 to 5 m.

  1. Start a pump when the level falls below 40 percent; stop it at 80 percent (hysteresis).
  2. Two pumps alternate each fill cycle to share wear. If the duty pump fails, the standby takes over.
  3. If the level falls below 20 percent, run both pumps.
  4. High-high level (95 percent) stops all pumps and raises an alarm.
  5. A pump must prove flow or current within 5 s of starting, otherwise it faults.
  6. A wire break on the transmitter (below 3.6 mA) puts the system in a safe manual state with an alarm.

Design

flowchart LR
    T["Level transmitter<br/>4-20 mA"] --> SC["Scale and check<br/>(0-100 %)"]
    SC --> CTL["Level control<br/>with hysteresis"]
    CTL --> ALT["Duty / standby<br/>selection"]
    ALT --> P1["Pump 1"]
    ALT --> P2["Pump 2"]
    SC --> AL["Alarms<br/>L, LL, H, HH"]
    P1 --> FB["Run feedback"]
    P2 --> FB
    FB --> ALT

Scale first, control second, protect last. Each box is a reusable block.

Scaling and control with hysteresis

The simplest controller is a hysteresis (bang-bang) controller: switch on below a low threshold, off above a high one, and keep the previous state between them. Without the gap the pump would rapidly start and stop, which damages motors.

C C stand-in: simulated tank with hysteresis fill control

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

The level oscillates between about 40 and 80 percent, with the pump running only part of the time.

Duty and standby alternation

To spread wear, each new fill cycle starts the pump that ran less recently. The logic uses a rising edge of "start request" to flip a NextPump variable. If the selected pump has a fault, the other takes over automatically.

C C stand-in: alternating pumps with fault takeover

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Protection and alarms

Protection logic always overrides normal control. In order of priority:

  1. Transmitter fault (wire break): stop automatic control, raise an alarm, require operator action. See plausibility checks.
  2. HH level: stop all pumps, alarm, latch until reset.
  3. LL level: start both pumps and alarm (consumers are in danger of running dry).
  4. Pump proof failure: if no current or flow appears 5 s after the start command, fault the pump (a step timeout) and let the standby run.
  5. Dry-run protection: the well level or inlet pressure switch stops the pumps when the source is empty.

Alarm limits should use a deadband and delay so waves in the tank do not make them chatter.

A complete scan in C

The final program puts scaling, alarms, hysteresis and protection together in one controller function and runs a simulation including a transmitter wire break.

C C stand-in: level controller with protection priorities

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

From on/off to PID

Hysteresis control suits a tank where the level may swing widely. When you need a steady level, for example to keep a reaction vessel at 60 percent, use a PID controller driving a variable-speed pump or control valve: the output is proportional to the error, with integral and derivative terms. PLCs provide PID blocks (PID_Compact, PIDE and similar); tuning them is its own craft, but the setup around them (scaling, limits, manual mode, alarms) is exactly what you built here.

Extensions

  • Show a tank graphic with level, pump states and alarms on an HMI screen.
  • Log level and pump run hours; use a retentive timer for run hours.
  • Report values to a SCADA system over Modbus or OPC UA.
  • Add a rate-of-change alarm for leaks (level falling too fast with all consumers off).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does an on/off level controller use two thresholds?

    The gap between start and stop levels (hysteresis) avoids short cycling that wears motors and contactors.
  2. 2. A 4-20 mA transmitter reads 12 mA. What percentage of the range is that?

    (12 - 4) / 16 = 0.5, so 50 percent.
  3. 3. Why should protection logic override normal control?

    A high-high level must stop the pumps even if the control logic still wants to fill.
  4. 4. What should happen if the transmitter signal falls below 3.6 mA?

    A reading below the live zero means a wire break; controlling on a false 0 percent could overflow the tank.

Summary

  • Scale the 4-20 mA signal, check it for faults, then control and protect.
  • Hysteresis prevents short cycling; alternate duty and standby pumps for even wear and redundancy.
  • Protection priorities: sensor fault, HH, LL, pump proof, dry-run.
  • Move to PID when a steady level matters.
  • The C programs are stand-ins simulating the tank and controller.

Next: Project: Conveyor Sorting Line