No history yet

Ladder logic

Welcome! I am excited to help you master Ladder Logic. Before we dive into the rungs and rails, I would love to learn a bit about your background so we can tailor this to your needs.

Are you an engineering student, an electrician, or looking to get into industrial automation?

I want to get into industrial automation

It is great to have you here! Industrial automation is an incredibly rewarding field, and mastering ladder logic is the perfect gateway to program the controllers that run modern factories.

Your path
Core Components: Inputs and Outputs
Basic Logic Operations
Putting it Together: Practical PLC Examples

What is Ladder Logic?

At its core, Ladder Logic is a graphical programming language used to program (PLCs)—the industrial computers that control assembly lines, robotic arms, and packaging machines. Instead of writing lines of text like you would in Python or C++, you actually "draw" your program using visual symbols. This makes it highly intuitive to read and troubleshoot on a busy factory floor. It is called "Ladder" logic because the finished program looks exactly like a ladder, with two vertical rails on the sides and horizontal rungs stretching between them.

A basic empty ladder logic diagram with two vertical power rails and two horizontal rungs.

I've started generating a visual layout of this basic structure above. Notice how the vertical side rails represent your power source, while the horizontal rungs will eventually hold your control logic. Before we start adding switches and motors to these rungs, let's explore where this design came from. Would you like to see how this relates to physical electrical circuits?

Continue to the electrical relay analogy

From Hardware to Software

To understand why ladder logic looks the way it does, we have to look back at how factories were controlled before computers existed. In those days, automation was entirely physical. Control rooms were lined with massive, floor-to-ceiling metal cabinets packed with thousands of electromechanical , physical switches, timers, and hardwired connections. If you wanted a simple behavior—like preventing a giant hydraulic press from crushing a part unless a safety gate was fully closed—you had to run physical copper wires from the safety gate switch, through a relay coil, and then to the press motor. When a factory needed to change its manufacturing line to make a different product, engineers couldn't just upload a new program. They had to shut down the plant for days or weeks. Teams of electricians had to manually disconnect, reroute, and screw down thousands of physical wires. It was an incredibly expensive, slow, and error-prone process.
Ladder logic was deliberately designed to mimic those old physical wiring schematics so that the electricians and factory engineers of the late 1960s wouldn't have to learn a complex computer programming language. Instead of running physical copper wire between real relays, they could just "draw" virtual wires and virtual relays on a screen. This transition from hardware to software was revolutionary. Suddenly, modifying an entire assembly line's behavior went from taking days of manual labor with screwdrivers and wire cutters to taking just seconds with a few keystrokes on a computer terminal.

Explain how a physical relay behaves inside the PLC program

It is a brilliant transition. When you move a physical relay into the digital world of a PLC, you are essentially replacing physical copper and moving parts with virtual memory bits. Instead of a physical electromagnet pulling a metal arm, the PLC CPU looks at a single, dedicated slot in its digital memory (a 1 or a 0) to determine if a contact should let virtual "power" flow through the rung.

The Virtual Relay

In a real physical cabinet, if you bought a relay, it might only have two or three physical sets of (switches) on it. If you needed to trigger ten different things when that relay energized, you had to buy more physical relays and wire them together in parallel, bulk-buying hardware just to get more contact points. Inside a PLC, however, a relay is just a bit in memory. Because it is digital software, you can reference that single virtual relay's status as many times as you want throughout your program. You can have hundreds of virtual contacts all reacting to that one virtual coil, completely free of charge and without a single physical wire. This is why we use different symbols for inputs (which read whether a switch is active) and outputs (the "coils" that represent the devices we want to turn on).

Let's look at how the PLC actually runs this program. Would you like to see how the PLC's internal CPU processes these inputs, solves your code, and updates the outputs in a continuous loop?

Continue to the PLC CPU scan cycle

The Scan Cycle: How the PLC Thinks

To understand how a PLC executes your ladder diagram, you have to realize that it does not read the program quite like a human does. While we might stare at a screen and troubleshoot a single rung, the PLC's is running a lightning-fast, highly disciplined three-step loop called the scan cycle.

A three-stage circular PLC scan cycle.

I've sketched out the cycle above. Rather than reacting to changes in real-time as they happen, the CPU freezes time for a split second to perform these three distinct steps in order:
  1. Read Inputs: The PLC looks at the physical terminal strip where your real-world pushbuttons, sensors, and limit switches are wired. It copies their ON or OFF statuses into a dedicated digital memory table.
  2. Execute Program: The CPU runs through your ladder logic program from left-to-right, rung-by-rung, starting at the very top. It uses the input statuses it just copied in step 1 to solve the math and logic, figuring out which virtual "coils" should turn on or off. However, it doesn't turn the physical devices on yet; it just updates their desired status in its memory.
  3. Update Outputs: Finally, the PLC writes those updated status values from its memory out to the physical terminals where your real-world motors, valves, and indicator lights are wired, physically turning them on or off.
Once it completes step 3, it instantly loops back to step 1 and starts all over again. This entire process typically happens in just a few milliseconds (1 ms=0.001 s1\text{ ms} = 0.001\text{ s}), which is so fast that to a human observer, the machines seem to react instantly.

Now that you know how the PLC executes the program in the background, we're ready to look at the actual symbols you'll use to build these rungs. Shall we move on to exploring normally open and normally closed contacts?