Engineers - Reinvent Your Career with Robotics in the Next 90 Days
Consult with Experts in our Career Advancement Program for the Experienced Engineer & Tech Professional. Gain clarity & community. Apply Now!

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest

PLC Programming Basics using Ladder Logic

Disclosure: Some of the links below are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalize a purchase. Learn Robotics is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a way for websites to earn advertising revenues by advertising and linking to Amazon.com.

Liz Miller Learn Robotics

Attention: Engineer Looking for a New Career in Robotics

Liz here 👋, Engineer,  Robotics Expert & founder of this website.

If I offered to help you advance your 6-Figure+ Robotics, Automation, or AI Career with a $10,000 sign-on bonus in the next 90 days or less…

…without wasting time on unnecessary certifications…
…without studying another coding language or tactic…
…without needing to get another degree and wasting years…

…would you take me up on that offer?

LIMITED SPACE: I have 6 more client spots open this week!

Want a spot? Click the button to access my 12-min training below and then apply if it makes sense.

You probably landed on this page because you’re interested in programming a PLC (programmable logic controller), but have no clue where to begin. Welcome! This article is designed to give you a primer in PLC Programming Basics for Industrial applications.

At the end of this article, you will have familiarity with reading Ladder Logic (also known as Ladder Diagrams) so that you can work on projects using PLCs. In future tutorials, I will show you how to practice writing Ladder Logic for common Industrial Control Systems.

One thing to note, is there are four additional industrial programming languages you can learn. In my experience, Ladder Logic is the most popular followed by Structured Text and Function Block. You can read more about the IEC61131-3 languages here.

So, without further ado, here’s my spin on PLC Programming Basics using Ladder Logic.

How PLC Programs are Executed

Before we can dive into the programming aspect of PLCs, it’s important to understand how the PLC works. When a PLC executes a program, it must know, in real-time, when external devices controlling a process are changing. During the Program Scan Cycle, the PLC reads the inputs, solves the Ladder Logic, and energizes (or de-energizes) outputs. Because inputs can change at any time, this process repeats over and over again while the PLC is in RUN mode. The diagram below shows a model of the PLC Program Scan Cycle.PLC Program Basics

Scan times can vary from 1 millisecond to 20 milliseconds. This is important because if the controller has to react to an input event faster than the scan time, it may never detect the change. Scan time is influenced by a few factors including the processor module speed, length of the ladder program, type of instructions executed, and the actual true/false conditions.

I also want to point out that the ladder programs we’ll be looking at are very simplistic. Therefore, we don’t have to worry so much about scan times. It’s just something to be aware of if you’re working with larger-scale systems.

Now that we have a general overview of how the PLC executes the program scan cycle, we can talk about ladder logic fundamentals.

Ladder Logic Fundamentals (How to read and write Ladder Diagrams)

Programs in Ladder Logic are written differently than embedded or flow-chart programming. Ladder Logic is a rule-based language, meaning the conditions must be met for the output to be energized. When I was first learning ladder logic, I had a hard time wrapping my brain around the symbology. Ladder Logic is very easy to understand once you get the hang of a few basic principles.

1. Rungs are Read Left to Right and Top to Bottom

There are two rails (left and right) and they are connected by rungs. This builds out a program that looks like a ladder. Ladder rungs are read starting from the left to the right and then sequentially, top to bottom.

PLC Ladder Logic example

2. Inputs or CONTACTS are on the left. Outputs or COILS are on the right.

You’ll notice a few basic symbols in the ladder program, above. Common symbols are called “Normally Open”, “Normally Closed” and “Output.” Check out the chart below. I learned on Allen Bradley PLCs, so I’ll refer to the XIC / XIO / OTE combination. Just know that these names are interchangeable and synonymous.

PLC Symbol Chart

3. Combine symbols to create a logical flow.

Ladder logic is based on principles from digital logic gates. There are three basic types of digital logic gates: the AND Gate, the OR Gate, and the NOT Gate. View the Truth Tables, below.

digital logic gates chart PLC

Logical AND condition

When you combine inputs and a bit of digital logic, you can create the status for your output. Here’s an example of the AND condition written in Ladder Logic.

Example Rung Ladder Logic

There are two inputs: XIC, XIO, and an OTE. This rung is read: If XIC and XIO then OTE. Both the XIC and the XIO must be active for the OTE to be energized. You can substitute “if-statements” into the rung to understand the condition. Most PLCs make it easy to figure out what is ON by highlighting the active elements.

Demonstrating the OR condition

We can create the OR condition by using a branch. You’ll see in the video below, the Start Button and the Motor are on separate branches. This is a common pattern for motor starters.

First, the program will check to see if the Start button or the motor is ON and the stop button is OFF, energize the motor. Here’s a demonstration.