Learn › Getting started
What is ladder logic?
Ladder logic is the graphical programming language most PLCs use. It looks like an electrical wiring diagram because it was designed to replace one, and once you can read a single rung you can read almost any program.
Where ladder logic came from
Before programmable logic controllers (PLCs), machines were controlled by panels full of relays. A relay is a switch worked by an electromagnet: power its coil and its contacts open or close. Electricians wired relays together so that pressing a start button energized a motor contactor, a limit switch stopped a cylinder, and so on. The drawings for those panels were called ladder diagrams, because the two power wires ran down each side of the page like the rails of a ladder, and each circuit ran across between them like a rung.
When the first PLCs arrived in the late 1960s, the engineers who designed them wanted the electricians and maintenance staff who already understood relay diagrams to be able to program them. So the programming language copied the drawings. Contacts, coils and rungs stayed; the wiring moved into software. That decision is why ladder logic is still the most common PLC language in factories today, even though modern controllers also support structured text, function blocks and other languages.
Rails and rungs
A ladder program has a left rail and a right rail. Think of the left rail as the live wire: it always has power. The right rail is the return. Between them are rungs, and each rung is one small piece of logic.
On each rung, conditions go on the left and outputs go on the right. If the conditions let "power" flow from the left rail all the way across, the rung is true and its outputs act. If something along the way blocks the flow, the rung is false.
| Light_Switch Lamp |
|------] [--------------------------------( )----|
Light_Switch is on, Lamp turns on.Of course, no electricity really flows through a PLC program. "Power flow" is a way of picturing the logic. The PLC is really evaluating true and false values, but thinking of it as current makes ladder diagrams very easy to follow, and the Playground draws the rungs that are passing power in color while your program runs so you can watch it happen.
Contacts and coils
The two building blocks you will use most are contacts and coils.
- Contacts are conditions. Each one looks at a bit (an on/off value, usually called a tag) and either passes power or blocks it.
XIC, drawn] [, passes power when its bit is on.XIO, drawn]/[, passes power when its bit is off. See XIC and XIO for the details. - Coils are outputs.
OTE, drawn( ), turns its bit on while the rung is true and off while it is false. There are also latching coils,OTLandOTU, which you can read about in Latch and Unlatch.
Beyond those, ladder logic has box instructions for things relays couldn't easily do: timers, counters, comparisons and math. They still sit on a rung and still respond to whether the rung is true; they just do more work when it is.
Series and parallel
Put two contacts one after the other (in series) and both must pass power for the rung to be true. That's AND logic. Put them on parallel branches and either one can pass power. That's OR logic. With those two shapes plus XIO for NOT, you can build any on/off decision. The lesson on AND, OR and NOT walks through each with truth tables.
| Guard_Closed Start Motor |
|------] [----------] [--------------------( )----|
How a PLC runs the program
A PLC doesn't run a ladder program once and stop. It runs it over and over in a loop called the scan: read the inputs, solve every rung from top to bottom, update the outputs, then start again. On real hardware a scan typically takes a few milliseconds. In the Playground the program scans once per screen refresh, usually about 60 times a second, which is fast enough that buttons and sensors feel instant. The order of rungs matters in some situations, and the scan cycle lesson explains why.
Inputs, outputs and tags
On a real machine, inputs are things like push buttons, limit switches and photo eyes, wired to input terminals on the PLC. Outputs are motor starters, solenoid valves and lights, wired to output terminals. Inside the program, each of those is a named tag. A tag can also be purely internal memory, such as a "machine running" bit that never leaves the PLC.
The Playground works the same way. The simulator's push buttons, photo eyes and vehicle sensors write to input tags; conveyors, transfers and traffic lights read output tags. Your ladder logic sits in between. Tags and their types are covered in Tags and data types.
Try it in the Playground
- Open the Playground with the conveyor scene. It starts with a working start/stop circuit for the conveyor motor.
- Press Run. Click and hold the green Start button in the simulator and watch the rung light up and the conveyor move.
- Press the red Stop button. The rung goes false and the conveyor stops.
- Stop the program, select the
XIO Stopcontact and look at how the rung is put together. You'll build this exact circuit yourself in the seal-in tutorial.
Key points
- Ladder logic copies relay wiring diagrams: a live left rail, a right rail, and rungs between them.
- Conditions (contacts, compares) go on the left of a rung; outputs (coils, timers, counters, math) go on the right.
- A rung is true when its conditions give power a path from left to right.
- Series means AND, parallel branches mean OR, and XIO gives you NOT.
- The PLC solves the whole program again and again, many times a second.