PLC Simulator
Ladder logic basics

What is ladder logic?

Ladder logic is the most common way to program a PLC, the industrial computer that runs a machine. It is drawn like a relay control diagram: each rung checks its input conditions on the left and turns an output on or off on the right.

Written by Paul. The rung below runs in your browser. No account, nothing to install.

Try it: a real start/stop rung

This is the rung that starts and stops most motors. It is live. Change the inputs, run a scan, and watch what the PLC does.

  1. Click Start pushbutton so it shows Pressed, then click Run complete scan. The motor turns on.
  2. Click Start again so it shows Released, then run another scan. The motor stays on. That is the seal-in.
  3. Click Stop circuit so it shows Open, then run a scan. The motor stops.
  4. Set Stop back to Healthy and run a scan. The motor stays off until you press Start again.

Interactive three-wire starter

Change a physical input, then advance one PLC phase at a time. The input image only changes during Read inputs.

Scan0
  1. 1. Read inputs

    The PLC copies the physical input terminals into its input image table.

  2. 2. Solve program

    The ladder is solved from the frozen input image and the previous output image.

  3. 3. Write outputs

    The solved output image is copied to the physical output terminals.

Physical field devices

These can change at any moment.

Input image snapshot

START

Input image

FALSE

STOP_OK

Input image

TRUE

OL_OK

Input image

TRUE

Program solve

Physical output

M

MOTOR OFF

Changes only at Write outputs

Ready

Press Start, then read the physical inputs to begin.

Build your own rung in the free lab

Here you change the inputs. In the guided lab you place the contacts and the coil yourself. No signup.

How to read a rung

If you can read a relay drawing, you can already read most of a ladder program. These six ideas cover the rest.

One ladder logic rung: a normally open contact on the left and an output coil on the right, between the left and right power railsA basic ladder logic rung between two power rails: an examine-if-closed contact (XIC) in series driving an output coil (OTE).L1L2] [StartXIC I:0/0LampOTE O:0/0
One rung: a contact on the left, a coil on the right, two rails at the sides.
  • Rails. The two vertical lines at the sides. Think of the left rail as the supply and the right rail as the return. They are part of the drawing. No real current flows through them.
  • Contacts. The conditions on the left of a rung. Each contact looks at one bit in the PLC memory, such as an input from a pushbutton or a limit switch.
  • Coil. The result on the right of a rung. When a complete path of true contacts reaches the coil, the PLC turns the coil's bit on.
  • Left to right. Read each rung from the left rail to the right rail. Contacts in a row are an AND. Contacts on parallel branches are an OR.
  • Top to bottom. The PLC solves the top rung first and works down. A rung can use a bit that an earlier rung has just changed.
  • Scan cycle. The PLC repeats three steps many times a second: read all the inputs, solve every rung from top to bottom, then update all the outputs. A change at an input is only seen at the next read.

Want to watch the three steps one at a time? Use the first button under the live rung above to step one phase at a time, or open the PLC scan cycle visualizer.

The five building blocks

Most ladder programs are built from these five instructions. Each one is shown with a small example.

Normally open contact -] [-

Passes power when its bit is ON. Use it to ask "is this input on?"

   Start_PB          Lamp
|----] [-------------( )----|

While the Start button is held, the lamp is on. Let go and the lamp goes off.

Normally closed contact -]/[-

Passes power when its bit is OFF. Use it to ask "is this input off?"

   Fill_PB    Tank_Full    Fill_Valve
|----] [-------]/[---------( )----|

The valve opens while Fill is pressed and the tank is not full. When Tank_Full turns on, the rung breaks and the valve closes.

Coil -( )-

The result of the rung. The coil turns its bit ON when power reaches it and OFF when it does not.

   Pump_Request      Pump
|----] [-------------( )----|

Pump follows Pump_Request on every scan. A coil can drive a real output or an internal bit that other rungs read.

Timer TON

An on-delay timer counts time while its rung is true. Its done bit turns on when the time reaches the preset.

   Start_PB      +--TON-----------+
|----] [---------| Delay   5 sec  |----|

   Delay.DN          Motor
|----] [-------------( )----|

Hold Start for five seconds and the motor starts. Release early and the timer resets to zero.

Counter CTU

An up counter adds one each time its rung goes from false to true. Its done bit turns on when the count reaches the preset.

   Box_Sensor    +--CTU-----------+
|----] [---------| Boxes   10     |----|

   Boxes.DN          Full_Lamp
|----] [-------------( )----|

Each box that passes the sensor adds one. On the tenth box the Full lamp turns on, and it stays on until the counter is reset.

Normally open and normally closed describe the contact in the program, not how the switch is wired. The full list, with every symbol and name, is on the ladder logic symbols page.

Worked example: start/stop with a seal-in

This is the same rung as the live one at the top of the page. It replaces the three-wire motor starter circuit that electricians already know.

   STOP_OK    OL_OK         START          MOTOR
|----] [-------] [----+-----] [-----+------( )----|
                      |    MOTOR    |
                      +-----] [-----+
  1. Ready to run. STOP_OK and OL_OK are on while the stop circuit is intact and the overload has not tripped. Both contacts pass power.
  2. Press Start. The START contact closes and the path to the coil is complete. MOTOR turns on.
  3. Release Start. The START contact opens, but the MOTOR contact under it is now closed. Power goes around START through that branch. The motor holds itself in. This is the seal-in.
  4. Press Stop. STOP_OK goes off and breaks the rung. MOTOR turns off, so the seal-in branch opens too.
  5. Release Stop. The motor does not restart. It needs a new press of Start.

Why is Stop drawn as a normally open contact?

The stop button is wired normally closed, so its input is on while nobody is pressing it. The program checks "is the stop circuit healthy?" with a normally open contact. If a wire breaks or comes loose, the input goes off and the motor stops. Wiring the stop button normally open and using a normally closed contact would also work on paper, but a broken wire would then leave you with a stop button that does nothing.

This example shows how the logic works. A PLC rung is not a safety function. Emergency stops and guards on real machines need their own safety-rated circuits.

Allen-Bradley vs Siemens and IEC names

The shapes on the screen are nearly the same on every brand. The names are not. Allen-Bradley software uses its own short instruction names. Siemens and most other brands follow the IEC 61131-3 naming more closely.

Ladder logic names in Allen-Bradley software compared with Siemens and IEC 61131-3
What it isAllen-BradleySiemens and IEC 61131-3
Name of the languageLadder logic, Ladder DiagramLadder Diagram (LD) in IEC 61131-3. Siemens calls it LAD.
Normally open contactXIC (Examine If Closed)Normally open contact
Normally closed contactXIO (Examine If Open)Normally closed contact
Output coilOTE (Output Energize)Coil. Siemens calls it an assignment.
Latch and unlatchOTL and OTUSet coil (S) and reset coil (R)
On-delay timerTON with .PRE, .ACC and .DNTON with PT, ET and Q
Up counterCTU with .PRE, .ACC and .DNCTU with PV, CV and Q
AddressesTag names such as Start_PB. Older SLC 500 and MicroLogix use I:1/0 and O:2/0.Named variables. Siemens also shows %I0.0 and %Q0.0.

Our simulator teaches these naming styles as learning dialects. It is not Rockwell or Siemens software, it does not emulate controller firmware, and it does not open or export vendor project files.

Questions

Ladder logic: common questions.

Ladder logic is a graphical programming language for PLCs, the industrial computers that run machines. A program is drawn as rungs between two vertical rails. Each rung has conditions on the left, called contacts, and a result on the right, called a coil. If the conditions make a complete path, the result turns on.