BlogExplainer

PLCs explained for AI engineers

A PLC is the small industrial computer that runs a machine. If your AI changes anything in a factory, it ends by writing a value to one. How PLCs work, in software terms.

A PLC, or programmable logic controller, is a small, rugged computer that runs one machine or one part of a plant. It reads switches and sensors, runs a program that decides what should happen, and switches motors, valves and heaters. It repeats that loop many times a second, for years, without a restart.

If you build AI for factories, buildings or utilities, this is the computer your model ends up talking to. An "action" in the physical world is, most of the time, a value written to a PLC. This article explains how one works, in terms a software or machine-learning engineer already knows.

Why it exists

Before the PLC, machine logic was built from relays wired together in cabinets. The wiring was the program. Changing what the machine did meant rewiring the cabinet.

In 1968 the Hydra-Matic division of General Motors asked for an electronic replacement. Dick Morley and his colleagues at Bedford Associates answered with the design that became the Modicon 084, first delivered in 1969. In 1979 Modicon published Modbus, a simple protocol for talking to its controllers. Modbus is still in wide use.

The new device was programmed with diagrams that look like relay wiring drawings, so that electricians could read them. That choice still shapes the field.

The mental model: one loop, forever

A PLC does not wait for events the way a web server does. In the classic model it runs the same loop without end:

  1. Read all inputs and copy them into memory.
  2. Run the program from top to bottom, using that copy.
  3. Write the results to all outputs.
  4. Do housekeeping: communication and self-checks.

One pass is called a scan. A scan typically takes from about a millisecond to a few tens of milliseconds.

Two things follow from this.

  • The reaction time is predictable. A change on an input is read within one scan, and the outputs react within about two. This property is called determinism, and it is the main reason machines are run by PLCs and not by ordinary computers.
  • Your write is not alone. A value you send over the network lands in the controller's memory, and the program reads it on its next pass. If the program also writes that value, the program wins.

Tags, setpoints and I/O

Signals come in two kinds. Digital signals are on or off: a button is pressed or it is not. Analog signals are a value on a scale, such as a temperature or a pressure, often carried as a current of 4 to 20 mA.

Inside the program, values have names called tags, for example Start_Button, Tank_Level or Motor_Run. The target value of a control loop is called the setpoint. If an oven should hold 180 °C, then 180 is the setpoint, and the PLC switches the heaters to keep the measured temperature there.

For an AI engineer the setpoint is the important word. When people say an AI "optimises" a plant, they almost always mean it changes setpoints. Changing a setpoint from outside is one of the most common remote writes to a PLC.

How it is programmed

An engineer writes the program on a laptop in the vendor's engineering software, downloads it to the PLC, and watches it run live. The languages are defined by the standard IEC 61131-3.

The classic one is ladder diagram. This rung starts a motor when Start is pressed, keeps it running, and stops it when Stop is pressed:

|---[ Start ]---+---[/ Stop ]---( Motor )---|
|               |
|---[ Motor ]---+

[ ] is a contact that passes power when the tag is on. [/] passes power when the tag is off. ( ) is the output. The same logic in Structured Text, the text language of the standard, is one line:

Motor := (Start OR Motor) AND NOT Stop;

Structured Text is gaining ground. It also fits version control and AI code generation, because it is plain text. The other languages in the standard are function block diagram and sequential function chart, both graphical.

One caution. The languages are standardised on paper, but each vendor has its own dialect and its own project file format. Moving a program from a Siemens controller to a Rockwell controller is real work.

Where it sits in a plant

Level System What it does Time scale
4 ERP Orders, stock, purchasing. Decides what to make. Days
3 MES Turns orders into a plan for the shop floor and records what was made. Hours
2 SCADA and HMI Control-room software and machine screens. Operators watch values and send commands. Seconds
1 PLC Runs the machine. Milliseconds
0 Sensors and actuators Measure and act. Continuous

This picture is called the automation pyramid. Each level takes orders from the one above. AI agents, vendor clouds and remote engineers do not follow it. They come in from the top or from the side, and end up writing values at level 1.

How it talks

Protocol Where you meet it Notes
Modbus TCP and RTU Everywhere, especially older and simpler equipment Open and simple. No authentication, no encryption.
EtherNet/IP Rockwell controllers, common in North America Runs on standard Ethernet.
PROFINET Siemens controllers, common in Europe Real-time industrial Ethernet.
EtherCAT Motion control Very fast.
OPC UA Between controllers and SCADA, MES and cloud Vendor-neutral, with security built in.
MQTT Publishing data to dashboards and cloud Lightweight publish and subscribe. Built in 1999 for pipeline telemetry.

In Modbus, the memory of a PLC is exposed as numbered coils, which are bits, and registers, which are 16-bit numbers. A client changes a value with a write request:

Unit 01 | Function 06 (write single register) | Address 000A | Value 0055

This writes the value 85 to the register at address 10. If that register holds a temperature setpoint, the machine now aims for a new temperature. Modbus has no way to ask who is sending the request. Any device that can reach the PLC on TCP port 502 can read and write.

How AI reaches a PLC today

There are three routes.

At engineering time. AI assistants write PLC code for an engineer to review. Siemens' assistant for its TIA Portal engineering tool, launched in 2024 as the Industrial Copilot and now sold as the Eigen Engineering Agent, generates PLC code. Research systems pair a language model with external checks, because unchecked output is not good enough. In one study, LLM4PLC, a pipeline that adds fine-tuning and automated checks (a syntax checker, a compiler and a model checker) raised the generation success rate from 47 to 72 percent. Success there means the code compiles, not that it is proven correct.

Through tool servers. The Model Context Protocol (MCP), published by Anthropic in November 2024, is the common way to give an AI agent tools. HighByte and Litmus ship MCP servers that expose plant data to an agent, and Inductive Automation has one in beta for its Ignition platform. Open-source servers exist for OPC UA and Modbus, and some of them can write as well as read.

In a closed loop. The AI writes setpoints to a running process by itself. Data-centre cooling and a few process plants work this way today. It is the rare case, and the one the field is heading toward.

What a PLC will not do for you

A PLC does what a valid request tells it to do. It does not judge whether the new value makes sense. If the request is well formed and the tag is writable, the value is accepted, whether it came from an operator, a script, or a model that misread its inputs.

A few things to keep in mind before your model writes anything.

  • Start read-only. Reading tags is harmless. Writing is a different class of action and deserves its own review.
  • Know the range. Every setpoint has a range the machine was built for. Find out who owns that number.
  • Leave safety alone. Emergency stops and guards run on separate safety controllers and hard wiring. They are meant to work whatever the control program, or your model, does.
  • Expect old equipment. PLCs often stay in service for 15 to 30 years, and their programs rarely change. The controller you connect to may be older than the protocol you hoped to use.
  • Ask what happens when you are wrong. PLCs were designed for closed networks where everyone on the wire was trusted. Stuxnet showed in 2010 that a changed PLC program can damage equipment while the screens show normal values. In November 2023 attackers took over a PLC at a water authority in Aliquippa, Pennsylvania. According to CISA, the devices hit in that campaign were reachable from the internet and used a default password or none.

Common questions

What does PLC stand for?

Programmable logic controller. It is the industrial computer that directly runs a machine: it reads sensors, runs a control program in a fixed loop, and switches motors, valves and heaters.

Can an AI model control a PLC directly?

Yes, technically. Anything that can reach a PLC over its network protocol can write to it, and tool servers now make that easy for AI agents. Whether it should is a separate question, decided per machine and per value.

Can a language model write PLC code?

Yes, with review. Vendors ship assistants that draft ladder logic and Structured Text, and studies find the output needs checking before it runs a machine.

Is Modbus secure?

No. Classic Modbus has no authentication and no encryption. A secure variant that uses TLS was specified in 2018, but support in devices is limited.

What is the difference between a PLC and SCADA?

A PLC runs one machine, in milliseconds. SCADA is the control-room software above it, which collects data from many PLCs and lets operators send commands.

Sources