Chris Collins

Tools · electrical

Relay and ladder logic simulator

Draw ladder logic between the power rails — contacts, coils, set/reset, TON/TOF/TP/RTO timers, CTU/CTD/CTUD counters, edges, comparisons and branches — and watch the PLC scan it with live power flow, pushbuttons, pilot lights and an animated plant, then see it as a hard-wired relay schematic (ANSI or IEC) or as IEC 61131-3 Structured Text and Instruction List.

Added

Works with

How to use it

Ladder logic is how relay panels were drawn, and how most PLCs are still programmed: two power rails, and between them rungs of contacts that switch coils. This simulator runs a ladder program the way a PLC does — read the inputs, solve the rungs top to bottom, write the outputs, again and again — and shows the power flowing through every contact while you press the buttons.

How to use it

  1. Pick an example from the menu (or keep the DOL starter it opens with). The About this example tab below explains what it shows.

  2. Play the inputs in the I/O panel: hold a pushbutton to press it (on a touch screen you can hold two at once; on a keyboard, hold the number key shown on it), click a selector, limit switch or sensor to change it, and Trip the overload. ✂ breaks the wire to an input. Inputs the plant model drives — the level switches, the door limits, the photo-eye — are marked by the plant.

  3. Watch the scan. Green wires carry power; a green contact is “true” (its condition is met, even if no power reaches it). The pilot lights and the plant show the physical outputs.

  4. Step it. Pause, then Scan runs one whole scan and Step one phase of it: read the inputs, then each rung in turn (highlighted), then write the outputs. Open the image table to see the input image lag the field and the outputs change only at the end of the scan. The scan time is in milliseconds; Speed slows the whole simulation down.

  5. Edit. Tap an instruction to select it, then use the inspector (name, type, preset, move, delete, Branch around, + Parallel path) and the palette (contacts go after the selected contact, outputs after the selected output). Tap a rung’s number to edit the rung: comment, the rung as text, move it up and down, duplicate, delete, or open it As gates in the digital logic simulator. ↶ and ↷ (or ⌘Z / Ctrl+Z) undo and redo. The Text tab edits the whole program as text, the Tags tab sets each tag’s device, colour and description and renames tags everywhere, and the list under the diagram flags likely mistakes (double coils, a reset that arrives a scan late, writing to an input).

  6. Relay schematic redraws the same program as hard-wired relay logic — pushbuttons, limit switches, control relays, timing relays and pilot lights — in ANSI/NEMA style (horizontal rungs between L1 and L2) or IEC 60617 style (vertical current paths between the supply and 0 V).

  7. Export gives the program as IEC 61131-3 Structured Text or Instruction List, as JSON to save and load, or as a Modbus map. The current program is kept in this browser, and Share link puts it in a link.

The examples

  • DOL motor starter — the start/stop circuit with a seal-in (holding) contact, a normally closed stop button and the overload relay’s 95–96 contact. The plant shows the motor running up and its starting current (about 6½ × full-load current, falling as it reaches speed).

  • Forward / reverse — two contactors with electrical and pushbutton interlocks. Delete an interlock and press both buttons to see the short circuit it prevents.

  • Star-delta starter — main, star and delta contactors with an on-delay timer for the star period and a short dead time before delta; the starting current in star is a third of DOL.

  • Traffic light — three cascaded on-delay timers that reset themselves through rung order.

  • Tank fill — a pump between a low and a high level switch: a seal-in makes the two-point (hysteresis) band.

  • Garage door — up and down contactors with limit switches, a safety photo-eye that reverses the door, and an off-delay courtesy light.

  • Conveyor with jam detection — a photo-eye blocked for 3 s latches a jam (set/reset coils), and a counter counts the boxes, once each.

  • Two-hand control — both buttons within 0.5 s, then held; let go of one and both must be released.

  • Car-park counter — an up/down counter (CTUD) with a FULL sign and a comparison block.

  • One-scan pulse and rung order — a one-shot made only by the order of two rungs, a push-on push-off toggle, and the same thing with a rising-edge contact.

Why stop buttons are normally closed

Every stop button, overload contact, safety beam and guard switch in these examples is wired so that its input is on when things are safe, and the program examines it with a normally open (“examine if on”) instruction. Then every failure of the wiring — a broken wire, a loose terminal, a contact block that has fallen off its button, a dead photo-eye — reads as stop. Wire a stop button normally open and the same broken wire leaves you a motor you cannot stop, and you only find out when you need it. That is why the ladder shows the stop button as a normally open contact, while the relay schematic shows the physical NC pushbutton: in a hard-wired circuit the NC contact is in series with the coil itself. Try the ✂ on the DOL starter’s Stop.

Emergency stops and two-hand controls go further: IEC 60204-1, ISO 13850 and ISO 13851 want them built from safety-rated parts (safety relays or a safety PLC with monitored, redundant channels), not from a standard PLC program like these.

How the simulation works

The scan. Each scan copies every input terminal into the input image, solves the rungs from top to bottom, then copies the output image to the output terminals. A rung reads the image as it is at that moment, so a coil written in rung 1 is seen by rung 2 in the same scan, but rung 1 sees rung 2’s coil only on the next scan — the cause of every “rung order” effect, including the one-scan pulse. Inside a rung, every contact is evaluated (left to right, each branch in turn) and then all its outputs get the same rung power, top to bottom. If two rungs write the same coil, the last one wins at the end of the scan (the double-coil warning).

Timers and counters are the IEC 61131-3 function blocks, called when their rung is solved, with the scan’s start time as the clock (so a timer’s resolution is the scan time):

  • TON: Q comes on PT after IN comes on; ET counts up and both reset as soon as IN goes off.

  • TOF: Q is on while IN is on and for PT after it goes off.

  • TP: a pulse of exactly PT on a rising IN, which ignores IN while it runs.

  • RTO (retentive on-delay, not an IEC block but in most PLCs): like TON but ET holds when IN goes off; only RES clears it.

  • CTU counts rising edges of its rung (so a held input counts once) and Q = CV ≥ PV; CTD counts down and Q = CV ≤ 0; CTUD counts up from its rung and down from a CD instruction, with QU = CV ≥ PV and QD = CV ≤ 0. CV stays within −32768…32767, the INT range.

  • RES drives the block’s reset input — R for CTU, CTUD and RTO, LD (load the preset) for CTD. Like any input it acts when the block is next called, so a RES in a rung below its counter arrives one scan late (the simulator says so). IEC TON, TOF and TP have no reset input: they reset when IN goes off.

  • Edge contacts |P| and |N| are R_TRIG and F_TRIG: true for one scan when their tag rises or falls since this contact last looked. Every edge contact has its own memory.

The relay view shows each instruction as the hard-wired part that would do its job: an instruction on an input becomes the button’s, switch’s or sensor’s own NO or NC contact (examining an NC stop button with an NO instruction is the button’s NC contact); one on a coil becomes a contact of that relay or contactor; TON and TOF done bits become on-delay and off-delay timing-relay contacts. Edges, comparisons, counters, TP and RTO have no simple relay equivalent and are drawn as dashed “PLC only” boxes.

The plants are simple: the motor speed follows a first-order lag (0.9 s direct-on-line, slower in star at reduced torque), with a line current of (1 + 5.5 × slip) × full-load current, a third of that in star; the tank fills at 6 % and drains at 3.5 % of its height a second with switches at 20 % and 85 %; the door takes 8 s end to end; boxes move at 0.12 belt-lengths a second and take about 0.6 s to pass the eye.

The exports. Structured Text gives one statement (or a short group) per rung, with the AT addresses of a PLC’s I/O (%IX0.0, %QX0.0 …), function-block instances for timers, counters and edges, and a BOOL variable for each RES and CD; a rung with several outputs stores its power in P first. Instruction List uses LD, AND, OR with the N modifier and parentheses for branches, and CAL for the blocks; IL was deprecated in the 2013 edition of IEC 61131-3, but many PLCs still accept it. The Modbus map uses the usual layout — inputs as discrete inputs, outputs and internal relays as coils, counts and elapsed times as input registers, presets as holding registers — but every PLC maps its own way, so check its manual.

Sources: IEC 61131-3:2013 (programming languages: LD, ST, IL and the standard function blocks), IEC 60617 and IEEE 315 / NEMA ICS 19 (graphical symbols), IEC 60204-1 (electrical equipment of machines), ISO 13850 (emergency stop) and ISO 13851 (two-hand control devices), and the classic motor-control texts for the starter circuits.

Runs entirely in your browser; nothing you type leaves this page.