No history yet

PLC programming

Welcome! I am excited to help you dive into the world of industrial automation. Before we map out our learning journey and start looking at how these industrial computers control massive factories, I would love to learn a little more about what brings you here.

To tailor this guide to you, could you tell me a bit about your background? Are you a student, a hobbyist, or working in a technical field already? Also, do you have a specific goal in mind for learning PLC programming?

I already work in a technical field and need this for my job.

It's great to have you here! Since you are working in a technical field and need this for your job, we will focus on building practical, industry-relevant skills. Let's start by laying out our game plan. Here is the path we will take to get you programming PLCs:

Your path
Hands-on Setup and Simulation

What is a PLC?

Let's start at the very beginning of our first subtopic. At its core, a (Programmable Logic Controller) is just a ruggedized, industrial computer. Unlike the computer or phone you are using right now, which is designed to run web browsers, video players, and spreadsheets, a PLC has one specific job: to monitor industrial inputs (like buttons, sensors, and switches) and control outputs (like motors, valves, and warning lights) based on a custom program you write.

Think of it like the brain of an automated factory machine: it feels what is happening in the physical environment through its "senses" (inputs) and reacts by moving its "muscles" (outputs). Where in your current workplace do you think you might find a PLC in action?

In our assembly line's conveyor belt system

A conveyor belt system is a perfect, classic example! You have sensors detecting package locations (inputs) and motors driving the physical belt (outputs) all coordinated by a central controller.

The Architecture of a PLC

To understand how the PLC manages that conveyor belt, we need to look under the hood. While they come in different shapes and sizes, almost every consists of three core physical sections connected together: the CPU (the brain), the I/O Modules (the sensory system), and the Memory (the storage).

A block diagram of PLC architecture showing Input Modules, CPU & Memory, and Output Modules, with Power Supply connections to all three.

Let's break down these three components of the hardware:
  1. The CPU (Central Processing Unit): This is the microprocessor that executes your program's logic. It reads the incoming electrical signals, solves your mathematical or logical equations, and decides what actions need to be taken.
  2. The Memory: This is where the PLC stores its operating system, your custom control program, and temporary data (like timer values or package counts). It uses robust, non-volatile storage so that if the factory suddenly loses power, the conveyor program isn't wiped out.
  3. The I/O Modules (Inputs/Outputs): This is the physical interface to the real world.
    • Inputs convert high-voltage electrical signals (like a 24V DC signal from a limit switch) into safe, digital data the CPU can read.
    • Outputs take low-voltage command signals from the CPU and boost them to actuate physical equipment (like sending 120V AC to start a heavy conveyor motor).

Continue to the PLC Scan Cycle

Let's dive into exactly how the CPU makes decisions in real time using the (Scan Cycle).

The four sequential phases of a Programmable Logic Controller (PLC) scan cycle arranged in a continuous clockwise loop.

This continuous process runs in four distinct phases:
  1. Input Scan: The PLC looks at the physical input terminals (like limit switches on your conveyor belt) and copies their On/Off status into its internal input image memory table.
  2. Program Execution: The CPU runs your custom program logic from top to bottom, line by line. It uses the copied states from the input table to calculate what should happen, storing the resulting decisions in an output memory table.
  3. Output Scan: The PLC takes those calculated values from its memory table and writes them directly to the physical output hardware terminals, turning on your conveyor motor or warning lights.
  4. Housekeeping: The PLC performs internal self-checks, safety diagnostics, and communicates with any connected programming laptops or screens to make sure everything is running smoothly before looping back to step 1.

Continue to how PLCs contrast with standard PCs

It's easy to look at a PLC and think, "Why not just use a regular computer?" After all, standard PCs are incredibly powerful, dirt cheap, and can run complex software.

PLC vs. Standard PC

While a PC is great for writing emails or running office software, it would fail miserably on a factory floor. The difference comes down to three critical factors: physical ruggedization, reliability, and .
FeatureStandard PCPLC (Industrial Controller)
Operating SystemGeneral purpose (Windows/macOS) with background updatesDedicated, lightweight Real-Time Operating System (RTOS)
EnvironmentClean, temperature-controlled officesHot, dusty, vibrating factory floors with high electrical noise
I/O HandlingDone via slow, standard ports (USB, ethernet)Hardwired, high-speed modular physical terminals
Execution StyleMultitasking (switches between many running apps)Sequential loop (runs one single control program infinitely)
If your office PC freezes for five seconds because of an antivirus scan, it's a minor annoyance. If the computer controlling your conveyor belt freezes for five seconds, boxes pile up, motors burn out, and physical damage occurs. Because a PLC runs a bare-bones operating system with no bloatware, it is designed to run for years on end without a single crash or reboot.

Continue to Ladder Logic Basics

Welcome to Ladder Logic

Now that you have a firm grasp on the physical hardware and how the system sweeps through its scan cycle, we can transition to the actual language used to bring that hardware to life. We are starting our next major subtopic: (Ladder Diagram), the most widely used programming language in industrial automation.
To understand why it is called "Ladder" logic, you have to look at how it is visually structured. The program consists of two vertical rails and several horizontal rungs stretching between them.
  • The Rails: Think of the left vertical rail as the "hot" power rail (24V DC24\text{V DC} or 120V AC120\text{V AC}) and the right vertical rail as the neutral or ground rail.
  • The Rungs: These are the individual horizontal lines of code. Power flows from the left rail, through your conditions (like switches or sensors), and over to the right rail to power an output device (like a motor coil).

A single-rung ladder logic circuit with labeled vertical rails, an open input contact, and an output coil.

This layout means that reading a PLC program is exactly like tracing a path for electrical current. If there is a closed, unbroken path of "true" conditions from the left rail to the right rail, virtual power flows down the rung, and the output device turns on. If any condition on the left is open or "false", the power is blocked, and the output remains off.

Continue to standard instructions (NO, NC, coils) to see how this works in code

Let's zoom in on the fundamental building blocks of Ladder Logic. Every program you write is constructed using three basic types of instructions that mimic physical electrical components: Normally Open contacts, Normally Closed contacts, and Output Coils.

The Three Essential Instructions

When you write Ladder Logic, you aren't typing out lines of text. Instead, you place visual symbols onto your rungs.
  1. Normally Open Contact (NO): Represented by the symbol [{<-| |--|}]. This acts like a standard light switch that is currently turned off. In a digital PLC, this instruction tells the CPU to examine a specific memory bit. If that bit is 0 (False/Off), the contact remains open and blocks the virtual power. If the bit becomes 1 (True/On), the contact closes, allowing power to flow past it.
  2. Normally Closed Contact (NC): Represented by the symbol [{<-|/|--|}]. This is the exact opposite of the Normally Open contact. It acts like a switch that is naturally closed (passing power) until someone presses it to open it. If the monitored memory bit is 0, the contact remains closed and lets virtual power flow through. If the bit turns to 1, the contact opens up and blocks the power.
  3. Output Coil (OTE): Represented by the symbol [{<-( )->}]. This represents the actuator or device you want to control. When virtual power successfully flows through all the contacts on the left side of the rung and reaches this coil, the PLC sets its corresponding output bit to 1 (turning on the real-world device, like your conveyor motor). If the power path is blocked, the coil is de-energized, and the output bit drops to 0.

To tie this together, think of your conveyor belt: we could use a Normally Open contact representing a "Start" push button connected directly to an Output Coil representing the conveyor motor. When a worker pushes the physical button, the -| |-- contact closes, virtual power flows across the rung, and the -( )- coil turns on the motor.

Now, how do you think we would handle a safety "Stop" button? Would we want to use a Normally Open or a Normally Closed contact so that pressing it immediately cuts power to our motor?

I think we would use a Normally Closed contact

Ladder Logic
LV 1
Skills

Spot on! You nailed it. We absolutely want a Normally Closed (NC) contact for the safety stop button.

Why Normally Closed for Safety?

Using a Normally Closed contact [{<-|/|--|}] means virtual power flows through the contact by default when the safety button is NOT pressed. When a worker hits the physical emergency stop button, it breaks the circuit, opening the contact, cutting off the power, and instantly de-energizing our output coil to stop the conveyor.

There is also a massive hardware safety advantage here. If a physical wire accidentally breaks or gets cut on the factory floor, the electrical circuit is broken. Because the PLC is looking for a closed path to keep running, that broken wire acts exactly like someone pressing the stop button, safely shutting down the machine. If we had used a Normally Open contact, a broken wire would mean the machine could never be stopped in an emergency. This design methodology is a cornerstone of [{}] in industrial settings.

Now that we have covered Normally Open contacts, Normally Closed contacts, and output coils, we are ready to combine them into simple control circuits. The next step in our learning path is understanding basic boolean logic (AND, OR, NOT) using these symbols. Are you ready to continue to boolean logic?

Continue to boolean logic (AND, OR, NOT)

Now we are going to see where the real magic happens. By arranging our Normally Open and Normally Closed contacts in different configurations, we can build the fundamental building blocks of decision-making: (logic gate).

The AND, OR, and NOT Gates

Just like in standard computer science, we use three basic operations to build our control schemes:
  1. AND Logic (Series Circuit): To create an AND condition, we place two or more Normally Open contacts side-by-side on the same rung. Virtual power has to flow through the first contact AND the second contact to energize the output coil. If either switch is open, the path is broken.
  2. OR Logic (Parallel Circuit): To create an OR condition, we place contacts on parallel branches (often called a "branch" or "nested rung"). Virtual power can flow through the top path OR the bottom path. If either contact closes, the output coil energizes.
  3. NOT Logic (Inversion): This is simply a Normally Closed contact. If the memory bit is NOT active, power flows. If the bit becomes active, power is cut.
Logic GateLadder RepresentationReal-World Example
ANDContacts in series: -| |-| |-Conveyor runs only if Guard Gate is Closed AND Start Button is Pressed
ORContacts on parallel branchesConveyor can be started from Operator Panel A OR Operator Panel B
NOTSingle Normally Closed contact: -|/|-Lubrication pump runs only if High Temp Limit is NOT Reached

Let's put this into practice on your conveyor belt system.

We want the conveyor motor to run, but only if two conditions are met: the operator must press the Start button, and the safety guard gate must be fully closed (which keeps a safety limit switch activated). If someone opens the guard gate while the machine is running, it must instantly shut down.

To build this safety interlock, would we place our Start button contact and our Safety Gate contact in series (an AND gate) or in parallel (an OR gate)?

We should place them in series (AND gate)

Exactly! Placing them in series is correct because it creates an AND gate.

The AND Gate in Action

By placing the Normally Open [{<-| |--|}] contact for the Start button and the Normally Closed [{<-|/|--|}] contact for the Safety Gate in series on the same rung, we ensure that virtual power can only reach our conveyor motor coil if the first contact is closed AND the second contact remains closed. If the guard gate is lifted, the safety switch opens, instantly breaking the chain and shutting down the motor.

We have covered how hardware communicates, how the internal scan cycle functions, and how to build basic logical gates like AND, OR, and NOT. This completes the core fundamentals of Ladder Logic!

Next, we need to transition to our third major subtopic: Advanced PLC Programming Concepts, where we will look at how PLCs keep track of time and count events on the factory floor. Are you ready to see how timers work?

Continue to Advanced PLC Programming Concepts

Introduction to PLC Timers

Welcome to our third major milestone! Now that you have mastered basic contact and coil logic, we are stepping into Advanced PLC Programming Concepts. In a real factory, processes do not just happen instantly based on On/Off switches; they rely heavily on physical duration. This is where come into play.

Think of a timer as an electronic stopwatch built into the PLC's software. There are three main types of timers you will use to control your factory equipment:
  1. Timer On-Delay (TON): This is the most common timer in industrial automation. When the rung conditions leading into a TON instruction become true, the timer starts counting. It waits for a specific preset duration to pass before it finally turns on its output bit.
  2. Timer Off-Delay (TOF): This does the opposite. When the rung conditions leading into a TOF instruction turn off, the timer's output bit remains on for a set duration before finally turning off.
  3. Pulse Timer (TP): This timer generates an output pulse of a precise, fixed duration. When the rung input transitions from Off to On, the timer instantly turns on its output and keeps it on for exactly the set duration, regardless of whether the input switch remains held down or is released.
To make these work, every timer block requires you to define a few internal parameters:
  • Preset Value (PRE): This is the target duration you want the timer to track (for example, 5000 ms5000\text{ ms} for a 5-second5\text{-second} delay).
  • Accumulated Value (ACC): This is the live stopwatch value, showing exactly how many milliseconds have elapsed since the timer started counting (0 ms0\text{ ms} up to your PRE value).
  • Done Bit (DN): This is the digital output bit. For a TON timer, this bit turns from 0 to 1 the moment the ACC value reaches the PRE value.

Let's put this straight into your conveyor belt system.

When a box passes by a physical sensor, we want to trigger a spray nozzle to apply a label, but we want to wait exactly 2 seconds2\text{ seconds} after the sensor detects the box before we turn the spray nozzle on.

To create this delay, which of our three timer types would we use?

We should use a Timer On-Delay (TON)

You are absolutely correct! A Timer On-Delay (TON) is precisely what you need here.

How the TON Timer Solves the Box Detection Problem

When the physical photoelectric sensor detects a box on your conveyor, its Normally Open contact [{<-| |--|}] closes. This starts the TON timer block. Because we set the Preset Value (PRE) to 2000 ms2000\text{ ms}, the timer's Accumulated Value (ACC) begins counting up from 0 ms0\text{ ms}. During those first two seconds, the Done Bit (DN) remains at 0, keeping the spray nozzle off. As soon as the ACC reaches 2000 ms2000\text{ ms}, the DN bit instantly flips to 1. We use this DN bit to trigger the Output Coil [{<-( )->}] for the spray nozzle, perfectly applying the label exactly two seconds after detection.

Now that you have got timers completely figured out, we can transition to the next critical concept in advanced automation: Counter instructions (CTU, CTD), which let us track and limit discrete physical events on the line.

Continue to Counter instructions (CTU, CTD)

Let's pivot seamlessly from tracking time to counting physical items on your assembly line.

In PLC programming, we handle this using to monitor discrete physical events, like boxes passing by on a conveyor belt.

The Up and Down Counters

Just like timers, counters are pre-built software blocks inside the PLC. They monitor an input rung and look for a specific transition: the exact moment a contact flips from Off to On (a false-to-true transition). There are two primary types of counters:
  1. Count-Up (CTU): Every time the rung transitions from false to true, the counter increases its current tally by 1.
  2. Count-Down (CTD): Every time the rung transitions from false to true, the counter decreases its current tally by 1.
To manage a counter, you configure three essential parameters:
  • Preset Value (PV): The target number of events you want to count (e.g., 10 boxes for a full case).
  • Accumulated Value (CV): The live, ongoing tally of counts stored in the PLC's memory registers.
  • Done Bit (DN): The digital status bit. For a CTU, this bit flips to 1 the instant your Accumulated Value (CV) becomes equal to or greater than your Preset Value (PV).

Let's apply this directly to your conveyor system.

We want to pack boxes into shipping cases. A sensor counts each box as it slides off the conveyor. When exactly 6 boxes have passed by, we want to temporarily stop the conveyor belt so an operator can seal the case.

To implement this logic, we will feed the box sensor's Normally Open contact [{<-| |--|}] into a CTU block with a PV of 6.

How do you think we should use the counter's Done Bit (DN) to control the conveyor belt motor? Would we use a Normally Open contact or a Normally Closed contact in series with the motor coil to stop it?

Use a Normally Closed contact of the DN bit

Ladder Logic
LV 1
PLC Programming
LV 1
Skills

Spot on again! You are flying through these logical concepts. Using a Normally Closed (NC) contact of the counter's Done Bit (DNDN) in series with the motor coil is the perfect way to pause the system.

The Counter-Based Stop in Action

Because a Normally Closed contact is closed by default, virtual power flows straight through it to keep your conveyor motor running during normal operation. As boxes pass by, our Count-Up (CTUCTU) instruction tracks them. The moment the sixth box is counted, the Accumulated Value (CVCV) reaches the Preset Value (PV=6PV = 6), and the DNDN bit instantly flips to 1. This transitions our Normally Closed contact from closed to open, immediately breaking the electrical path, de-energizing the motor coil, and stopping the conveyor. Once the operator finishes sealing the box and presses a physical Reset button, the PLC program executes a (Reset coil) (RES) to clear the accumulated value back to 0. This drops the DNDN bit back to 0, re-closes our Normally Closed contact, and allows the conveyor to start running again.

Introduction to PLC Data Registers

Now that you have counters down, we are ready for the final step under our Advanced Programming milestone: understanding how the PLC stores and manipulates actual numbers, like tracking inventory levels or processing analog sensor temperatures. To do this, we step away from single-bit, On/Off binary logic and look at (word register).
Instead of just asking "Is this switch on or off?", advanced automation tasks require us to store actual numeric values. For example, if you want to display the total number of boxes processed today on an operator's screen, or adjust conveyor speed based on an analog speed dial, you have to move those values into a data register. We manipulate this numeric data using specialized instructions on our rungs, such as Move (MOV), which copies a value from one register to another, or basic math blocks like Add (ADD) and Subtract (SUB). Imagine you want to calculate your conveyor's total daily throughput. You have two shift counters tracking production. To find the total, you would use an ADD instruction that takes the accumulated value of Shift Register A, adds it to the value of Shift Register B, and writes the final total to a third Destination Register. Would you like to explore how these mathematical registers work with an example, or are you ready to jump to the final section of our outline and set up a simulator?

Show me a mathematical register example

Let's dive straight into a worked example of how a mathematical register works in practice. This is where we bridge the gap between simple On/Off states and actual numerical calculations.

The Total Throughput Calculator

Let's assume your factory operates with two shifts, and each shift has its own physical conveyor sensor. When boxes pass by, they trigger Shift A and Shift B count-up instructions, storing their tallies in two distinct data registers: MW10 (Shift A Count\text{Shift A Count}) and MW12 (Shift B Count\text{Shift B Count}). To find the overall daily production, we write a rung of logic containing an ADD block. This instruction takes two source values, performs addition, and writes the output to a third destination register, which we will call MW14 (Total Daily Throughput\text{Total Daily Throughput}).
MW14=MW10+MW12\text{MW14} = \text{MW10} + \text{MW12}
Every time the PLC runs its , it reads the numerical values inside MW10 and MW12, calculates the sum, and immediately updates MW14. This completes our coverage of Advanced PLC Programming Concepts! We have successfully covered hardware, scan cycles, basic contacts, logic gates, timers, counters, and math registers. We are now ready to transition to our final subtopic: Hands-on Setup and Simulation, where we will look at how you can download free software to practice programming right on your laptop without needing physical hardware.

Continue to Hands-on Setup and Simulation

Simulating PLCs on Your PC

It is amazing how far you can get in industrial automation without spending a single cent on physical hardware. Since physical PLCs and I/O cards can cost hundreds or thousands of dollars, the modern industry relies heavily on to test code before deploying it to real factory equipment.
To start practicing on your laptop, you have two major, highly accessible routes depending on which ecosystem you want to explore:
  1. The Siemens Ecosystem: Siemens offers a programming suite called TIA Portal (Totally Integrated Automation). You can download a free, fully functional 21-day trial of this industrial software. When paired with PLCSIM (Siemens' virtual controller software), it lets you write actual ladder logic, download it to a simulated S7-1200 controller, and watch the registers and bits execute on your screen.
  2. The Codesys Platform: Codesys is the hidden gem of industrial automation. It is a completely free, manufacturer-independent software suite that adheres strictly to global programming standards. Codesys has a powerful built-in software simulator. With a single click, you can turn your personal laptop into a running PLC, complete with interactive visualization screens you can design yourself.

Which path appeals more to you? We can walk through downloading Codesys to get you programming immediately, or we can look at setting up the industrial Siemens trial.