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?

  • Universal: Works on Siemens S7, Allen-Bradley, CODESYS, Beckhoff TwinCAT, Schneider Electric, and more
  • Powerful: Handles loops, arrays, structs, and complex math that are tedious in graphical languages
  • Industry demand: Automation engineers with ST skills command higher salaries
  • Readable: Easier to document, version-control, and maintain than graphical programs
  • 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_VAR

    IF StartButton AND NOT StopButton THEN MotorRunning := TRUE; ELSIF StopButton THEN MotorRunning := FALSE; END_IF; END_PROGRAM

    Breaking It Down

  • PROGRAM / END_PROGRAM: Defines a Program Organization Unit (POU)
  • VAR / END_VAR: Declares variables with types and optional initial values
  • BOOL: A Boolean data type (TRUE or FALSE)
  • IF / ELSIF / END_IF: Conditional logic — the backbone of PLC programming
  • Structured Text Data Types

    TypeDescriptionExample
    BOOLBoolean (TRUE/FALSE)sensor_active : BOOL
    INT16-bit integercount : INT := 0
    REALFloating-point numbertemperature : REAL := 22.5
    STRINGText stringname : STRING := 'Pump_01'
    TIMEDuration valuedelay : 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!

    Key Takeaways

  • Structured Text is the most versatile IEC 61131-3 PLC language
  • It uses familiar programming constructs: variables, conditionals, loops
  • ST skills transfer across all major PLC platforms
  • Practice in a simulator before deploying to real hardware