PLC programming: what it is, what the code looks like and how to start
PLC programming explained: what the code looks like, the languages, the scan, a first example in Siemens and Rockwell, and a realistic way to start.

In this guide
PLC programming is writing the rules that run an industrial machine. When this sensor sees a bottle, stop the conveyor. When the tank is full, shut the valve. You write those rules on a laptop, download them into a tough little computer called a programmable logic controller, and it follows them over and over, usually many times a second.
This page is the map of it: what the code looks like, the languages, how it runs, a first real example in Siemens and Rockwell, what you need and a realistic way to learn.
It keeps to what the makers say in their own manuals, linked at the bottom. For the device itself and what the parts do, read the guide to what a PLC is. This one is about the code.
What makes PLC programming different from normal coding
At heart it's the same as any other coding. You break a job into rules a computer can follow. It's the day to day work behind a lot of industrial automation, and you'll hear it called PLC coding, PLC logic or just programming the PLC. Two things make it feel different.
- It moves real things. A bug can leave a valve open or a pump running, which is why nobody sensible tries new code on a live machine first.
- The program never finishes. It runs from top to bottom, then starts again, until someone stops it.
What writing PLC code looks like
You don't open a blank file and start typing. Siemens' Getting Started manual for the S7-1200 walks through a first program in six steps, and it's a fair picture of the job.
- Create a project in the maker's software.
- Add your logic.
- Tie it to the real inputs and outputs.
- Configure the controller.
- Download the program.
- Test it, and watch the values change live.
Only step 2 is what most people would call coding.

What a PLC program is made of
Everything in a PLC program has a name, called a tag: Start, TankFull, PumpOn. The logic sits in blocks that read some tags and write others, and the two big makers organise them differently.
| Siemens (TIA Portal) | Rockwell (Studio 5000) | |
|---|---|---|
| What keeps it running | The "Main" organisation block, called in an endless loop | A task. New projects start with a continuous one, which restarts at once |
| Where the code sits | Function blocks and functions, called from Main | Routines inside a program. The main routine runs first and calls the others |
The PLC languages
There isn't one PLC language. The international standard IEC 61131-3 sets out a family of them. Rockwell uses the standard's own names, and Siemens has its own.
| In the standard | Siemens | What it looks like | Rockwell suggests it for |
|---|---|---|---|
| Ladder Diagram (LD) | LAD | Rungs of contacts and coils | On and off logic, interlocks, anything maintenance may need to read |
| Function Block Diagram (FBD) | FBD | Boxes joined by wires | Loop control, drives, continuous processes |
| Structured Text (ST) | SCL | Typed lines of code | Hard maths, working through arrays, text handling |
| Sequential Function Chart (SFC) | GRAPH | Steps, like a flowchart | Batches, repeating sequences, state machines |
You can mix them in one project, but not every controller has every language. Siemens' 2018 programming guideline lists GRAPH for the S7-1500 and not the S7-1200, for example.
So which one first? A sensible start is ladder logic, because you're likely to have to read it whatever else you learn, then Structured Text, the closest to other kinds of coding. Pick up FBD and sequential function charts when a job calls for them.
How the code runs: the scan
A PLC doesn't run your code once. It runs it in a repeating loop called the scan. Siemens lists each S7-1200 cycle as writing the outputs, reading the inputs, running your program, then doing its own checks. Most people call that read, run, write. It's the same loop.
The inputs get copied into a snapshot Siemens calls the process image. Your code works from top to bottom using that snapshot, and whatever's left in the output image at the end reaches the real outputs. Three habits come from this.
- Your code can't wait. There's no "pause for five seconds" line. A timer keeps counting across many scans, and you check it each time round.
- Order matters. If two lines write the same output, the last one wins.
- A scan has a time limit. Go over it and the controller treats that as an error. On Rockwell it's a watchdog, 500 milliseconds by default, and a major fault that can shut the controller down.
There's one wrinkle beginner guides tend to skip. That tidy snapshot is the Siemens default, but on Rockwell's Logix controllers the inputs and outputs update on their own timer, separately from the logic, so an input can change part way through a scan. Rockwell's answer is to copy the input to another tag and use the copy. Know that before you work on a real Logix job.
PLC Gym's simulator uses the tidy version, one read, run and write every 20 milliseconds. It isn't a copy of any maker's timing.
A first PLC code example: start and stop a pump
If you go looking for sample PLC programs, this is the one you'll keep meeting. It's also the first exercise in Siemens' S7-1200 manual, where it's called a latching circuit. Press Start and the pump runs. Let go and it keeps running. Press Stop and it stops. This version adds Permit, a permissive, which is a condition that has to stay on for the pump to run.
Here it is in ladder, which both makers draw the same way. Rockwell calls these symbols XIC, XIO and OTE.
Start Stop Permit PumpOn
----| |-----+------|/|--------| |-----------( )----
|
PumpOn |
----| |-----+And here's the same rule in Siemens SCL, then Rockwell Structured Text.
#PumpOn := (#Start OR #PumpOn) AND NOT #Stop AND #Permit;PumpOn := (Start OR PumpOn) AND NOT Stop AND Permit;The # is how Siemens marks a tag that belongs to the block. On a Siemens controller this line would sit in a function block, so PumpOn keeps its value between scans.
The clever bit is PumpOn reading itself. That's a seal in, and it's how the code remembers. Here's what happens, with Permit on throughout.
| What happens | Start | Stop | PumpOn last scan | PumpOn this scan |
|---|---|---|---|---|
| Start pressed | 1 | 0 | 0 | 1 |
| Start released | 0 | 0 | 1 | 1 |
| Stop pressed | 0 | 1 | 1 | 0 |
| Both pressed | 1 | 1 | 0 | 0 |
You can write this yourself in the free Make it stay running mission.
Siemens' manual adds an on delay timer next, so let's do the same. Now Start has to be held for five seconds before the pump runs.
#StartDelay(IN := #Start, PT := T#5s);
#PumpOn := #StartDelay.Q;StartDelay.PRE := 5000;
StartDelay.TimerEnable := Start;
TONR(StartDelay);
PumpOn := StartDelay.DN;Neither one waits. Both call the timer on every scan and ask whether it's done yet. Each needs a timer tag of its own, a TON_TIME instance in Siemens and an FBD_TIMER in Rockwell, whose preset is in milliseconds. You can try it in the on delay mission.
What you need to start
These were checked in November 2026, but they change, so look at the maker's own page before you decide.
- To learn the logic: a web browser. PLC Gym has nothing to install, and the first guided lab and the first few missions are free with a free account. The rest is on Pro.
- For Siemens: STEP 7 in TIA Portal. Siemens' V21 installation notes list 64 bit Windows and a licence key, with a one time trial licence that runs out after 21 days. Siemens also offers TIA Portal Cloud, which it says works without installation.
- For Rockwell: Studio 5000 Logix Designer, also on 64 bit Windows. It comes in editions, so check yours has the languages you want. Smaller Micro800 controllers use Connected Components Workbench, which has a free Standard edition.
- For Beckhoff: TwinCAT 3. Beckhoff says the core PLC programming tool is free of licence costs, and its 7 day trial licences can be renewed as often as you like.
- A real PLC: not at first, but eventually. The PLC training kit guide covers what to buy.
You'll need the real software sooner or later. PLC Gym isn't a real controller, doesn't connect to real inputs and outputs, and isn't made by or affiliated with Siemens, Rockwell or Beckhoff. It doesn't do hardware configuration, networks or maker library blocks, and it has no editor for RSLogix 500, MicroLogix, SLC 500, Omron or Mitsubishi. The guides to PLC programming software and PLC emulators cover the real tools.
A realistic way to learn it
There's no honest number of weeks, because it depends on your background and how often you practise. What this guide can give you is the order.
- Get the ideas first. Inputs, outputs and the scan. Try some basic PLC programming on a working pump in your browser, or read PLC Gym's short basics chapters.
- Write small things that work. Your first command is one line of code. Then the seal in and the timer above, then counting bottles. When a test fails, you can replay it scan by scan.
- Pick one maker. Look at job adverts where you live, or the kit where you work, and see which name keeps coming up. PLC Gym has routes for Siemens, Allen-Bradley and Beckhoff.
- Move on to signals and sequences. Scaling a sensor reading and running a batch through its phases are where it starts to feel like a real plant. Both are on Pro.
- Fix other people's code. You'll often be reading a program someone else wrote and working out why a pump won't stop. Stop doesn't stop it is a good first go, and the PLC troubleshooting guide goes further.
- Then get onto the real tools. Install the maker's software, even if it's just a trial. PLC Gym can export
.sclfiles for TIA Portal and.L5Xfiles for Studio 5000. They're made for that software, but you'd still want to test them there.
If you'd like that laid out for you, the PLC programming course has 74 missions on 26 machines, in 40 stages. If it's a career you're after, read the PLC technician training guide next.
The surest way to get good at this is to write code, watch it go wrong and work out why. Better that happens on a screen than on someone's production line.
Sources
- IEC 61131-3:2025, Programmable controllers, Part 3: Programming languages, International Electrotechnical Commission
- Getting started with S7-1200, Siemens, November 2009 edition
- Programming Guideline for S7-1200/S7-1500, Siemens, V1.6, December 2018
- TIA Portal V21 installation notes, November 2025, Siemens
- TIA Portal, Siemens
- Logix5000 Controllers Common Procedures, Rockwell Automation, March 2004 edition
- Studio 5000 Logix Designer 38.00 release notes, Rockwell Automation
- Connected Components Workbench downloads, Rockwell Automation
- TwinCAT 3 licensing, Beckhoff
- Why you should use normally closed for stop buttons, PLC Academy
Questions about this?Ask in the Locker Room
Try it on a machine
Try it on a working machine
Write real Siemens or Rockwell code in the free online PLC simulator and watch a 3D pump, tank or filling line do exactly what you told it. Nothing to install.


