0
0
FreertosProgramBeginner · 2 min read

Ladder Logic Program for Water Tank Level Control in PLC

A simple ladder logic program for water tank level control uses two level sensors (Low and High) and a pump output coil, with rung logic: Start Pump if Low Level is ON and High Level is OFF; Stop Pump if High Level is ON or Stop Button is pressed.
📋

Examples

InputLow Level Sensor = ON, High Level Sensor = OFF, Stop Button = OFF
OutputPump is ON
InputLow Level Sensor = OFF, High Level Sensor = ON, Stop Button = OFF
OutputPump is OFF
InputLow Level Sensor = ON, High Level Sensor = OFF, Stop Button = ON
OutputPump is OFF
🧠

How to Think About It

To control the water tank level, use two sensors: one detects when water is low, the other when water is high. The pump should turn ON when water is low and turn OFF when water reaches the high level or when a stop button is pressed. Use ladder logic contacts to check sensor states and control the pump coil accordingly.
📐

Algorithm

1
Read the Low Level Sensor input.
2
Read the High Level Sensor input.
3
Check if the Stop Button is pressed.
4
If Low Level Sensor is ON and High Level Sensor is OFF and Stop Button is NOT pressed, turn ON the Pump.
5
If High Level Sensor is ON or Stop Button is pressed, turn OFF the Pump.
💻

Code

plc_programming
(* Ladder Logic for Water Tank Level Control *)
(* Inputs: I0.0 = Low Level Sensor, I0.1 = High Level Sensor, I0.2 = Stop Button *)
(* Output: Q0.0 = Pump Motor *)

(* Rung 1: Pump ON condition *)
|---[ ]---[/]---[/]---( )---|
|  I0.0  I0.1  I0.2  Q0.0   |

(* Explanation: Pump Q0.0 turns ON if Low Level I0.0 is ON, High Level I0.1 is OFF, and Stop Button I0.2 is NOT pressed. *)
Output
Pump ON when Low Level sensor is ON and High Level sensor is OFF and Stop Button is NOT pressed; otherwise Pump OFF.
🔍

Dry Run

Let's trace the ladder logic with Low Level ON, High Level OFF, and Stop Button OFF.

1

Check Low Level Sensor

Low Level Sensor I0.0 = ON (true)

2

Check High Level Sensor

High Level Sensor I0.1 = OFF (false), so normally closed contact is true

3

Check Stop Button

Stop Button I0.2 = OFF (false), so normally closed contact is true

4

Evaluate Pump Coil

All conditions true, Pump Q0.0 energizes (ON)

Low Level (I0.0)High Level (I0.1)Stop Button (I0.2)Pump Output (Q0.0)
ONOFFOFFON
OFFONOFFOFF
ONOFFONOFF
💡

Why This Works

Step 1: Low Level Sensor Contact

The Low Level Sensor contact is normally open and closes when water is low, allowing current to flow to start the pump.

Step 2: High Level Sensor Contact

The High Level Sensor contact is normally closed and opens when water is high, stopping the pump to prevent overflow.

Step 3: Stop Button Contact

The Stop Button is normally closed and opens when pressed, immediately stopping the pump for safety.

Step 4: Pump Coil Control

The pump coil energizes only when low level is detected, high level is not reached, and stop button is not pressed, ensuring proper water level control.

🔄

Alternative Approaches

Using Set/Reset (Latch) Instructions
plc_programming
(* Set pump ON when Low Level is ON and Reset when High Level is ON or Stop pressed *)
|---[ ]---(S)---|
|  I0.0  Q0.0   |

|---[ ]---+---(R)---|
|  I0.1  |
|  I0.2  |
|        Q0.0 |

(* Pump stays ON after Low Level triggers until High Level or Stop resets it *)
This method latches the pump ON, which can be useful for maintaining state but requires careful reset logic.
Using Timer to Delay Pump Stop
plc_programming
(* Pump ON when Low Level ON, stop delayed after High Level ON using timer T1 *)
|---[ ]---[/]---( )---|
|  I0.0  I0.1  Q0.0 |

|---[ ]---(TON)---|
|  I0.1  T1       |

|---[ ]---[/]---|
|  T1.Q  Q0.0   |

(* Pump stops after delay when High Level sensor triggers *)
Adds delay to pump stop to avoid rapid cycling but increases complexity.

Complexity: O(1) time, O(1) space

Time Complexity

The ladder logic runs in constant time per scan cycle, checking inputs and setting outputs without loops.

Space Complexity

Uses fixed memory for inputs, outputs, and coil states; no dynamic memory allocation.

Which Approach is Fastest?

All approaches run in constant time; using simple contacts is fastest and easiest to maintain, while timers add complexity but improve control.

ApproachTimeSpaceBest For
Simple Contact LogicO(1)O(1)Basic level control, easy to understand
Set/Reset LatchO(1)O(1)Maintaining pump state across cycles
Timer DelayO(1)O(1)Preventing pump rapid cycling
💡
Use normally open contacts for sensors that activate the pump and normally closed contacts for sensors that stop it to simplify logic.
⚠️
Forgetting to include the stop button logic can cause the pump to run uncontrollably.