PLC Simulator
tutorial
sequencing
sfc

PLC State Machines, Grafcet & Sequential Function Chart (SFC) Explained

By PLC Simulation Software9 min read

PLC State Machines, Grafcet & Sequential Function Chart (SFC)

A PLC state machine breaks a machine's behaviour into a small set of named steps — like Idle, Fill, Drain and Done — where only one step is active at a time, and you move from one step to the next only when a defined transition condition becomes true. Grafcet is the formal graphical method for drawing these step-and-transition sequences, and the Sequential Function Chart (SFC) defined in IEC 61131-3 is the PLC language built directly from it. Once you think in steps and transitions, even a complicated batch sequence becomes a tidy diagram you can implement in ladder, Structured Text, or SFC.

This guide shows you the state-machine mindset, the Grafcet/SFC structure, two ways to code it on a real PLC, and the design steps that keep your sequences clean.

PLC state machine, Grafcet and Sequential Function Chart explained

What is a state machine on a PLC?

Most machines do things in order. A bottle filler waits for a bottle, fills it, lets it settle, caps it, then ejects it — always in that sequence, never out of order. A state machine captures exactly that: a finite list of states (steps), and the rules for moving between them.

The key idea is that exactly one step is active at any moment. That single rule is what makes a state machine so much easier to debug than free-form logic: at any instant you can ask "which step are we in?" and the machine gives one clear answer.

Simple PLC state machine state diagram with Idle, Fill, Drain and Done states

Each arrow is a transition with a condition. You leave Idle for Fill when a Start button is pressed; you leave Fill for Drain when the level sensor reports full; you leave Drain for Done when the tank is empty. Nothing happens "by accident" because every move requires its condition to be true.

Grafcet and the Sequential Function Chart (SFC)

Grafcet (from the French GRAphe Fonctionnel de Commande Étapes/Transitions) is the formal way to draw a sequence as alternating steps and transitions. The international standard built on it is the Sequential Function Chart (SFC) — one of the five languages in IEC 61131-3, alongside ladder, Structured Text, function block and instruction list.

An SFC reads top to bottom. Each step can carry actions (the outputs to drive while that step is active), and each transition carries a condition that must be true before the active step passes the token down to the next step.

Sequential Function Chart SFC structure showing steps, transitions and actions for a Grafcet PLC sequence

The beauty of SFC is that the order of operations is visible in the diagram itself. You are no longer hunting through dozens of rungs trying to reconstruct what runs when — the chart is the sequence.

State machine vs spaghetti logic

If you have ever inherited a program where the same output is set on six different rungs under tangled interlock conditions, you have met spaghetti logic. It "works" until you need to change it, and then every edit risks breaking a hidden case.

Comparison of a structured PLC state machine approach versus unstructured spaghetti ladder logic

A state machine forces discipline: one output is owned by the step that needs it, and a step only runs when the sequence has legitimately reached it. The result is logic that a colleague — or you, six months later — can actually follow.

How to design a state machine

You do not start by writing code. You start by listing the steps a person would do by hand, then naming the event that ends each one.

Flowchart showing how to design a PLC state machine from a sequence of steps and transitions

Work through it on paper or in a Grafcet diagram first. List every step, write the transition condition that exits it, and decide which outputs each step drives. By the time you reach the keyboard, the program almost writes itself.

Implementing a state machine in ladder logic

You do not need the SFC language to use the SFC idea. The most portable approach across Allen-Bradley, Siemens and any other vendor is a set of step bits — one boolean per step — driven by Set and Reset (latch/unlatch) coils.

When a transition fires, you Set the next step bit and Reset the current one. Because exactly one step bit is on, your output logic just reads the relevant step bit.

Ladder rung implementing a PLC state machine step using Set and Reset coils with step bits

The pattern for each transition is one rung: "if I am in step N and the transition condition is true, then advance to step N+1." Holding a step active is exactly the same seal-in / latch pattern you already use for motor start-stop circuits — a state machine is really just a chain of well-organised seal-in rungs.

Ladder vs SFC vs CASE in Structured Text

There are three common ways to build the same state machine, and the best choice depends on your toolchain and team.

Comparison table of implementing a PLC state machine in ladder logic, Sequential Function Chart and CASE in Structured Text

In Structured Text the state machine is delightfully compact: a single CASE Step OF block, one branch per step, where each branch drives its outputs and sets Step to the next value when its transition is true. It reads almost exactly like the Grafcet diagram.

State machine best practices

A few habits keep step sequencers reliable on real machines.

Checklist of PLC state machine and Grafcet best practices

The two that save the most pain: always include an Idle/Reset state you can fall back to, and make sure an E-stop or fault forces the machine into a known safe step rather than freezing it mid-sequence.

Parallel and branching sequences

Real machines are not always one straight line. Grafcet and SFC let you branch — choose one of several paths based on a condition (an alternative branch) — or run parallel steps that all execute at once and rejoin later (a simultaneous branch).

PLC state machine state diagram showing a branching and parallel SFC sequence

A divergence picks a path; a convergence waits for the active branches to finish before continuing. This is how you model "either fill from tank A or tank B" (alternative) or "heat and stir at the same time" (parallel) without abandoning the clean step-and-transition structure.

Build a state machine in your browser

The fastest way to make sequencing click is to wire up a real step sequence and watch the active step move as conditions change. You can do exactly that in the free browser PLC simulator — build the step bits, set and reset them on transitions, and step through the scan to see exactly which state is active. Try it on one of the sequencing practice scenarios like a traffic light or a batch fill, where the whole point is getting the order right.

FAQ

What is a PLC state machine? A PLC state machine breaks a machine's behaviour into a small set of named steps where only one step is active at a time, and you advance to the next step only when a defined transition condition becomes true. It makes sequential logic easy to read and debug.

What is the difference between Grafcet and SFC? Grafcet is the original graphical method (from French standard NF C 03-190) for describing a sequence as steps and transitions. Sequential Function Chart (SFC) is the IEC 61131-3 PLC programming language built on the same step-and-transition model.

Is SFC the same as ladder logic? No. SFC is a separate IEC 61131-3 language that shows the order of operations as a chart of steps and transitions, while ladder logic shows boolean rungs. You can implement the same state machine in either — SFC just makes the sequence visible.

How do you write a state machine in Structured Text? Use a CASE Step OF block with one branch per step. Each branch drives that step's outputs and assigns the next value to Step when its transition condition becomes true, so exactly one step runs per scan.

Can you build a state machine in ladder logic? Yes. The portable pattern uses one step bit per state, driven by Set and Reset (latch/unlatch) coils: a transition rung sets the next step bit and resets the current one, so only one step is ever active.

Share:X / TwitterLinkedIn

Practice this yourself in the simulator

3 scenarios free — no install, no credit card. Write real ladder logic against a live machine model.

Try the simulator free →

Related articles

robotics
universal robots

How to Program a Universal Robot: A Beginner's Guide (2026)

A practical, from-zero guide to programming a Universal Robots cobot: the teach pendant and PolyScope, frames and the TCP, waypoints, your first pick-and-place, digital I/O and grippers, safety and protective stops, and how to practise without owning a robot.

June 19, 2026 · 11 min read
hmi
allen bradley

FactoryTalk View Tutorial: What It Is, What It Costs, and How to Learn HMI Free

Learn what FactoryTalk View ME, SE and Studio are, why the download hunt is frustrating, which concepts transfer to any HMI, and how to build those skills free in your browser.

June 11, 2026 · 11 min read
hmi
scada

HMI Programming Tutorial: Screens, Tags, Alarms, and Navigation

A vendor-neutral HMI programming tutorial covering screens, tag binding, pushbuttons, lamps, numeric entry, alarm design, and ISA-101 colour discipline. Practical and concept-first.

June 11, 2026 · 13 min read