Variables and Assignment
Declare and assign values to variables in Structured Text on rungs.dev. Learn naming rules, := assignment semantics, and how variables map to PLC tags during execution.
Variable Naming
In Structured Text (ST), variables are the building blocks of your logic. They represent inputs, outputs, and internal states within your PLC program.
Naming Rules
-
Must begin with a letter (A–Z or a–z)
-
Can contain letters, digits, and underscores ( _ )
-
No spaces, symbols (except _ ), or starting digits
-
Case-insensitive in most environments (but using consistent case is recommended)
Good Naming Conventions
-
Use descriptive names that reflect the purpose of the variable.
-
Use camelCase or PascalCase consistently (or whatever style your team/project uses).
-
Prefixes can be helpful (e.g., is, has, num, val, btn, etc.)
Examples:
Start_Command // BOOL (0 or 1) trigger
Counter_Value // DINT counter
Temperature_Set // REAL setpoint (e.g., 23.5)
Valve_Open // BOOL output signalAvoid names like:
x1, val, temp2, a123 // Not meaningfulAssignment Operator
In Structured Text, assignment is done using :=, not =.
Variable := Value;-
:= assigns the value on the right to the variable on the left.
-
A semicolon ( ; ) must follow the assignment.
Examples:
Motor_On := 1;
Counter := Counter + 1;Note: The = symbol is used only in comparisons, such as IF x = 10 THEN.
Tag References
variables (also called tags) are categorized into:
1. Input Tags
-
Represent physical or logical input signals from sensors, buttons, etc.
-
Usually read-only inside logic.
Start_Button, Temp_Sensor, Limit_Switch2. Output Tags
-
Represent signals that go out to actuators, motors, alarms, etc.
-
Controlled by your logic.
Motor_Start, Buzzer, Valve_Open3. Internal Tags
-
Variables used for intermediate logic, memory, and calculations.
-
Not tied to physical I/O.
Counter_Value, Temp_Average, isRunningEach tag type can be used in ST just like normal variables, but their source (hardware or logic) determines how they behave in the program.
Examples
// Start the motor when the start button is pressed
Motor_Start := Start_Button;
// Increment the counter value
Counter_Value := Counter_Value + 1;
// Turn on the fan if the temperature exceeds the setpoint
IF Temp_Sensor > Temp_Setpoint THEN
Fan_On := 1;
END_IF;
// Reset the counter when the stop button is pressed
IF Stop_Button THEN
Counter_Value := 0;
END_IF;Practice
Practice in the Count Up exercise — increment a counter and raise a Done flag when it reaches its target.
Basic ST Syntax
Statement structure, semicolons, expressions, and basic syntax rules for Structured Text in rungs.dev — the foundation every ST program in the simulator follows.
Arithmetic and Comparison Operators
Reference for arithmetic and comparison operators in Structured Text on rungs.dev, including built-in math functions and DINT/REAL rounding rules.