Ladder logic basics

Ladder logic is the most widely used PLC programming language. It resembles electrical relay diagrams: power flows from the left rail through contacts to a coil on the right.

Contacts

A contact represents an input condition. A normally-open (NO) contact passes power when its variable is true (e.g. a button pressed). Anormally-closed (NC) contact passes power when its variable is false (a check that the named bit is zero). A physical NC Stop button is a different concept: StopOK is true while released, so our motor example uses a NO contact to check StopOK.

Series and parallel

Contacts in series are AND: every contact must be closed for power to reach the coil. Contacts in parallel branches are OR: power reaches the coil if any branch is closed.

Try Lamp Follow for a single contact, then compare Two-Button AND with Either-Button OR.

Coils

A coil represents an output or internal bit. When power reaches the coil, its target variable becomes true. In this product each coil target may be written by only one rung (v1 rule) to keep behavior easy to explain.

Timers (TON) and counters (CTU)

TON (on-delay timer): when its input is true, elapsed time (ET) grows each 20 ms scan until it reaches the preset (PT); then Q turns on. If the input turns off, ET resets to zero.
CTU (up counter): counts only rising edges of its input (false โ†’ true). Holding the input true does not count repeatedly. When the count reaches the preset (PV), Q turns on. A reset input clears the count and has priority.

Practice timing with Delayed Start and rising edges with Batch Counter.

Scan cycle

The engine runs in fixed 20 ms scans: snapshot inputs, evaluate rungs top to bottom, write outputs, then update the device. Writes are visible to later rungs in the same scan, which is how self-latching (motor start/stop) works.

Explore feedback in Motor Start/Stop, state transitions in Traffic Light, and hysteresis in Tank Level Control.

Try it

Open the exercises and work through Lamp Follow, Two-Button AND, and Motor Start/Stop first.