Ladder Logic Program for Bottle Filling System in PLC
Start and Stop push buttons to control a Filling motor coil, with a Level Sensor input to stop filling when the bottle is full, e.g., Start PB --| |----+----( ) Filling Motor and Level Sensor --|/|----|/|--( ) Stop Filling.Examples
How to Think About It
Algorithm
Code
(* Ladder Logic for Bottle Filling System *) (* Inputs: StartPB, StopPB, LevelSensor *) (* Output: FillingMotor *) (* Start/Stop latch *) |---[ StartPB ]---+---[ ]---( ) FillingMotor | | | +---[ LevelSensor ]---| (* Explanation: *) (* StartPB normally open push button *) (* StopPB normally closed push button *) (* LevelSensor normally closed when bottle not full, opens when full *) (* Ladder logic description: *) (* FillingMotor coil energizes when StartPB pressed, StopPB not pressed, and LevelSensor not full *)
Dry Run
Let's trace the bottle filling system when Start button is pressed and bottle is empty.
Start button pressed
StartPB = ON, StopPB = ON (not pressed), LevelSensor = ON (bottle empty)
Check conditions
StartPB ON, StopPB ON, LevelSensor ON means FillingMotor coil energizes
Filling motor runs
FillingMotor = ON, bottle starts filling
Bottle becomes full
LevelSensor changes to OFF (bottle full)
Motor stops
FillingMotor coil de-energizes because LevelSensor is OFF
| Step | StartPB | StopPB | LevelSensor | FillingMotor |
|---|---|---|---|---|
| 1 | ON | ON | ON | OFF |
| 2 | ON | ON | ON | ON |
| 3 | ON | ON | ON | ON |
| 4 | ON | ON | OFF | ON |
| 5 | ON | ON | OFF | OFF |
Why This Works
Step 1: Start and Stop buttons control motor
The StartPB is a normally open button that when pressed allows current to flow, and StopPB is normally closed to allow current unless pressed to stop.
Step 2: Level sensor stops filling
The LevelSensor input is normally closed when the bottle is not full, opening to stop the motor when full.
Step 3: Motor energizes only when conditions met
The motor coil FillingMotor energizes only if StartPB is pressed, StopPB is not pressed, and LevelSensor shows bottle not full.
Alternative Approaches
(* Use a timer to fill for a fixed time instead of level sensor *)
|---[ StartPB ]---+---[ StopPB ]---( ) FillingMotor
| |
| +---[ TON Timer ]---|
(* Timer runs when motor ON, stops motor after preset time *)(* Use a counter to count bottles filled and stop after target count *) |---[ StartPB ]---+---[ StopPB ]---( ) FillingMotor | | | +---[ Counter ]---| (* Stops motor after counting set number of bottles *)
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 internal bits; no dynamic memory allocation.
Which Approach is Fastest?
All approaches run in constant time; timer or counter methods add complexity but do not affect scan speed significantly.
| Approach | Time | Space | Best For |
|---|---|---|---|
| Level Sensor Control | O(1) | O(1) | Precise filling control |
| Timer Control | O(1) | O(1) | Simple fixed-time filling |
| Counter Control | O(1) | O(1) | Batch filling count |