In Part 1 of our industrial automation series, we discussed the hardware—the sensors, the actuators, and the architecture. But hardware is useless without software. The “brain” that tells the factory floor what to do is the Programmable Logic Controller (PLC).
If you are an electrical engineer, a maintenance technician, or a software developer transitioning to industrial systems, learning PLC programming basics is your most critical next step.
In this guide, we will break down how PLCs work, the different programming languages (with a focus on Ladder Logic), and how to write your first program.
How Does a PLC Work?
Unlike a standard desktop computer that runs multiple applications simultaneously, a PLC runs a single, dedicated program in a continuous loop. This loop is called the **Scan Cycle**.
The Scan Cycle consists of three main steps:
- Input Scan: The PLC reads the status of all input devices (sensors, switches) and stores this data in its memory.
- Program Execution: The PLC runs through your program, rung by rung, using the input data to determine what the outputs should be.
- Output Scan: The PLC updates the status of all output devices (motors, lights, valves) based on the results of the program execution.
This cycle repeats continuously, often taking only a few milliseconds. This makes the PLC incredibly fast and reliable.
The 5 Languages of PLC Programming (IEC 61131-3)
In 1993, the International Electrotechnical Commission (IEC) standardized PLC programming languages. There are five main types:
1. Ladder Logic (LD)
This is the most popular language, especially in North America. It was designed to look like the electrical relay schematics that technicians were already familiar with. We will focus heavily on this below.
2. Function Block Diagram (FBD)
FBD uses blocks connected by lines to represent the flow of signals. It’s great for analog control and process automation.
3. Structured Text (ST)
Similar to Pascal or C, ST is a high-level text-based language. It’s excellent for complex math, data manipulation, and algorithms.
4. Instruction List (IL)
This is a low-level assembly-style language. It’s rarely used in modern programming but is still supported on older systems.
5. Sequential Function Chart (SFC)
SFC is used to break down a complex process into a series of steps. It’s ideal for batch processes where sequence matters.
Deep Dive: Ladder Logic Basics
Why is it called “Ladder” logic? Because the program looks like a ladder, with two vertical rails (left and right) and horizontal rungs connecting them.
- The Left Rail: Represents the power source (High / True).
- The Right Rail: Represents the return path (Low / False).
- The Rungs: Contain the logic—the switches, sensors, and relays.
If the logic on the rung is “True,” the power flows to the output on the right side.
The 4 Fundamental Instructions
1. Examine If Closed (XIC) — Normally Open Contact
This instruction looks like two vertical lines: `| |`. It acts like a standard light switch.
- If the input is True (e.g., a sensor is activated), the instruction allows power to pass.
- If the input is False, power is blocked.
2. Examine If Open (XIO) — Normally Closed Contact
This looks like two diagonal lines or a slash through the contacts: `|/|`. It acts like an inverted switch.
- If the input is False (not activated), power passes.
- If the input is True (activated), power is blocked.
3. Output Energize (OTE) — Coil
This looks like a circle `( )`. It is placed at the end of the rung.
- If power reaches the coil (the logic is True), the physical output turns ON.
- If power does not reach the coil, the output turns OFF.
4. Latching (OTL / OTU)
Sometimes you want an output to stay ON even after the input is released. This is called a “latch.”
- OTL (Output Latch): Turns on the output and keeps it on.
- OTU (Output Unlatch): Turns off the latched output.
Your First Ladder Logic Example: Start/Stop Motor
The “Hello World” of PLC programming is the Start/Stop circuit. Let’s say we want to control a motor with two pushbuttons (Start and Stop) and a seal-in contact.
Rung 1:
- Place an XIC instruction for the “Start” button. (Normally open).
- In parallel with the Start button, place an XIC instruction for the Motor Output. This is the “seal-in” or “latch” circuit.
- In series, place an XIO instruction for the “Stop” button. (Normally closed).
- At the end, place an OTE instruction for the Motor.
|---[ Start ]---+---[ Stop ]---( Motor )---| | | |---[ Motor ]---+
How it works:
1. Press “Start”. Power flows through the Start button, through the closed Stop button, and energizes the Motor.
2. The Motor turns on, which closes the parallel Motor contact.
3. Release “Start”. Power now flows through the Motor contact, keeping the circuit energized.
4. Press “Stop”. This opens the XIO contact, breaking the circuit, and the Motor turns off.
If you’re managing an engineering team building these systems, check out our guide on the best project management software for engineering teams to keep your projects on track.
Timers and Counters
Real-world processes require time delays and counting. PLCs have built-in instructions for this.
Timers (TON / TOF / RTO)
- TON (Timer On Delay): Waits a specific time before turning on. (e.g., Wait 5 seconds before starting the conveyor).
- TOF (Timer Off Delay): Keeps an output on for a specific time after the input is turned off.
- RTO (Retentive Timer): Remembers the accumulated time even if the input is lost.
Counters (CTU / CTD)
- CTU (Count Up): Counts events. (e.g., Count every bottle passing on a conveyor. At 24 bottles, trigger a box packaging arm).
- CTD (Count Down): Counts down from a preset value.
Analog Signals vs. Digital Signals
Ladder Logic is excellent for Digital (On/Off) signals. But what about analog signals, like measuring temperature (0-100 degrees) or pressure?
In the PLC, analog signals come in as raw numbers (e.g., a scale from 0 to 32767). You have to use scaling instructions (like the SCP – Scale with Parameters) to convert those raw numbers into engineering units (like 0-100 Celsius).
Conclusion (Part 2)
Mastering PLC programming basics is the key to unlocking a career in industrial automation. While Ladder Logic might look old-fashioned compared to modern Python or JavaScript, it remains the global standard because it is robust, visual, and safe.
Start by simulating simple circuits (using software like RSLogix, TIA Portal, or LogixPro) before touching a real machine. In Part 3, we will explore Human-Machine Interfaces (HMI) and SCADA systems—the screens operators use to control the factory.
Have you programmed a PLC before? Let us know your favorite brand (Siemens, Allen-Bradley, Mitsubishi) in the comments!
