Beginner
Structured Text for Beginners: A Complete Guide to PLC Programming
Start your PLC programming journey with this beginner-friendly guide to Structured Text — the most versatile IEC 61131-3 language.
What Is Structured Text?
Structured Text (ST) is a high-level programming language defined in the IEC 61131-3 standard for Programmable Logic Controllers (PLCs). Unlike Ladder Diagram or Function Block Diagram, ST uses text-based syntax similar to Pascal or C, making it powerful for complex logic, math-heavy operations, and data processing.
Why Learn Structured Text?
Your First Structured Text Program
Let's write a simple motor start/stop program:
PROGRAM MotorControl
VAR
StartButton : BOOL := FALSE;
StopButton : BOOL := FALSE;
MotorRunning : BOOL := FALSE;
END_VARIF StartButton AND NOT StopButton THEN
MotorRunning := TRUE;
ELSIF StopButton THEN
MotorRunning := FALSE;
END_IF;
END_PROGRAM
Breaking It Down
Structured Text Data Types
| Type | Description | Example |
|---|---|---|
| BOOL | Boolean (TRUE/FALSE) | sensor_active : BOOL |
| INT | 16-bit integer | count : INT := 0 |
| REAL | Floating-point number | temperature : REAL := 22.5 |
| STRING | Text string | name : STRING := 'Pump_01' |
| TIME | Duration value | delay : TIME := T#5s |
Control Structures
IF / THEN / ELSE
IF temperature > 80.0 THEN
alarm := TRUE;
coolingFan := TRUE;
ELSIF temperature > 60.0 THEN
alarm := FALSE;
coolingFan := TRUE;
ELSE
alarm := FALSE;
coolingFan := FALSE;
END_IF;
💡 Syntax fragment. To run this, declare temperature : REAL;, alarm : BOOL;, and coolingFan : BOOL; in the VAR panel.
FOR Loop
FOR i := 1 TO 10 DO
total := total + sensorValues[i];
END_FOR;
average := total / 10.0;
💡 Syntax fragment. Declare i : INT;, total, average : REAL;, and sensorValues : ARRAY[1..10] OF REAL; in the VAR panel.
CASE Statement
CASE machineState OF
0: status := 'IDLE';
1: status := 'RUNNING';
2: status := 'PAUSED';
3: status := 'ERROR';
END_CASE;
💡 Syntax fragment. Declare machineState : INT; and status : STRING; in the VAR panel.
Next Steps
Now that you understand the basics, try our interactive ST editor to write and simulate your own programs. Start with Lesson 1 in our curriculum to build a traffic light controller!