How to Write Ladder Logic Program: Basics and Example
To write a ladder logic program, use
rungs that connect inputs and outputs with logical operations like AND and OR. Each rung represents a control rule, and the program runs top to bottom, left to right, simulating electrical relay logic.Syntax
A ladder logic program consists of rungs that connect inputs (like switches or sensors) to outputs (like motors or lights) using logical operations.
--[ ]--represents a normally open contact (input).--[/]--represents a normally closed contact.--( )--represents an output coil.- Rungs are read left to right, top to bottom.
Each rung evaluates if the output should be energized based on the input conditions.
plaintext
Rung 1: --[Input1]--[Input2]--(Output1)-- Rung 2: --[Input3]--[/Input4]--(Output2)--
Example
This example turns on Output1 only when both Input1 and Input2 are ON (AND logic). It also turns on Output2 when Input3 is ON and Input4 is OFF (AND with NOT).
plaintext
(* Ladder Logic Example *) // Rung 1: Output1 energizes if Input1 AND Input2 are ON --[Input1]--[Input2]--(Output1)-- // Rung 2: Output2 energizes if Input3 is ON AND Input4 is OFF --[Input3]--[/Input4]--(Output2)--
Output
If Input1=ON and Input2=ON then Output1=ON
If Input3=ON and Input4=OFF then Output2=ON
Common Pitfalls
Common mistakes when writing ladder logic include:
- Forgetting that contacts in series mean AND logic, and contacts in parallel mean OR logic.
- Mixing normally open and normally closed contacts incorrectly.
- Not properly labeling inputs and outputs, causing confusion.
- Ignoring the scan cycle of the PLC, which can affect timing.
plaintext
Wrong: --[Input1]--(Output1)-- --[Input2]--(Output1)-- // This energizes Output1 if Input1 OR Input2 is ON, but looks like AND Right: --[Input1]--[Input2]--(Output1)-- // Correct AND logic in series
Quick Reference
| Symbol | Meaning | Description |
|---|---|---|
| --[ ]-- | Normally Open Contact | Passes power if input is ON |
| --[/]-- | Normally Closed Contact | Passes power if input is OFF |
| --( )-- | Output Coil | Energizes output device |
| Series Contacts | AND Logic | All contacts must be ON |
| Parallel Contacts | OR Logic | Any contact ON passes power |
Key Takeaways
Ladder logic uses rungs connecting inputs and outputs with AND/OR logic.
Normally open contacts pass power when ON; normally closed pass when OFF.
Series contacts mean AND; parallel contacts mean OR.
Label inputs and outputs clearly to avoid confusion.
Test your logic step-by-step to catch mistakes early.