Ladder Logic Program for Water Tank Level Control in PLC
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
How to Think About It
Algorithm
Code
(* 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. *)
Dry Run
Let's trace the ladder logic with Low Level ON, High Level OFF, and Stop Button OFF.
Check Low Level Sensor
Low Level Sensor I0.0 = ON (true)
Check High Level Sensor
High Level Sensor I0.1 = OFF (false), so normally closed contact is true
Check Stop Button
Stop Button I0.2 = OFF (false), so normally closed contact is true
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) |
|---|---|---|---|
| ON | OFF | OFF | ON |
| OFF | ON | OFF | OFF |
| ON | OFF | ON | OFF |
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
(* 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 *)
(* 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 *)
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.
| Approach | Time | Space | Best For |
|---|---|---|---|
| Simple Contact Logic | O(1) | O(1) | Basic level control, easy to understand |
| Set/Reset Latch | O(1) | O(1) | Maintaining pump state across cycles |
| Timer Delay | O(1) | O(1) | Preventing pump rapid cycling |