Schneider PLC Structured Text Programming Examples
Published on Sep 01, 2025 | Category: oper-block
Share this Page:
Arithmetic operators are the foundation of any Structured Text (ST) program in a Schneider PLC.
Using operators like +, -, *, and /, engineers perform real-time
calculations for process values such as flow rate, temperature, or motor speed. Within EcoStruxure Control Expert,
arithmetic logic lets you scale analog inputs, create set-point adjustments, and implement energy-saving formulas
directly in code.
Once raw values are calculated, conditional operators and IF…THEN…ELSE statements
decide how the PLC should react. For example, you can instruct the controller to open a valve if pressure exceeds a
threshold, or stop a motor when a limit switch is active. Conditional logic turns numeric data into clear yes/no
actions, ensuring that your automation sequence behaves predictably and safely.
Combining arithmetic and conditional statements builds the core of most real-world programs. In Schneider
EcoStruxure, you can layer loops, timers, and counters on top of this logic to manage batching, machine cycles, or
safety interlocks. Mastering these building blocks early makes future tasks—like advanced PID control, data
logging, or diagnostics—much easier, while keeping your PLC code clean, readable, and efficient.
Arithmetic Operators in Structured Text (ST)
In Structured Text (ST) for PLCs, an arithmetic operator is a symbol used to perform
mathematical calculations on numeric variables or constants. ST behaves much like a high-level language, so the math
symbols are simple and familiar.
- + – Addition, e.g. Total := A + B; adds A and B.
- - – Subtraction, e.g. Diff := A - B; subtracts B from A.
- * – Multiplication, e.g. Prod := A * B; multiplies A by B.
- / – Division, e.g. Ratio := A / B; divides A by B.
- MOD – Modulus (remainder), e.g. R := A MOD B; stores the remainder of A ÷ B.
- ** – Exponentiation (if supported), e.g. P := A ** 2; calculates A squared.
Operations follow normal precedence (exponent → multiply/divide/mod → add/subtract). Use parentheses
() to control the calculation order, for example Avg := (A + B) / 2;. These operators make
it easy to handle scaling, set-point math, and real-time process calculations inside the PLC.
Arithmetic Operator Examples in Structured Text (ST)
Structured Text in Schneider PLCs allows engineers to perform clear and readable calculations directly inside the
controller. Arithmetic operators form the backbone of scaling analog inputs, calculating machine efficiency, or
preparing set-points for downstream logic. Below are practical examples showing how each operator is applied.
-
Addition
Total := A + B;
Adds the value of A and B. For instance, this can be used to sum two flow sensor
readings before logging the combined total flow.
-
Subtraction
Difference := A - B;
Subtracts B from A. Typical in level monitoring, e.g., calculating the difference
between a target set-point and the actual tank level.
-
Multiplication
Power := Voltage * Current;
Multiplies two process values. A real-world use is computing electrical power (kilowatts) by multiplying
instantaneous voltage and current measurements.
-
Division
Average := (A + B) / 2;
Divides the sum of A and B by 2. Commonly used to calculate an average
temperature when two redundant sensors are installed on the same process line.
-
Complex Formula
Result := ((A + B) * (C - D)) / (E + 1);
Combines addition, subtraction, multiplication, and division:
- Adds A and B to combine two measurements.
- Subtracts D (a correction factor) from C.
- Multiplies the two partial results for an adjusted value.
- Divides by E + 1 (a scaling factor) to normalize the final result.
Such a formula is useful for advanced control strategies—e.g., computing a compensated flow rate based on
temperature and density corrections while avoiding division by zero.
Always use parentheses () to control the order of operations. Structured Text follows normal precedence
(exponent → multiply/divide/mod → add/subtract), so explicit grouping ensures the PLC performs calculations exactly
as intended. This disciplined approach keeps your math routines predictable, easier to review, and ready for
expansion when the process grows more complex.
Practical Arithmetic Example in Structured Text (ST)
Let’s consider a scenario in a water treatment plant where you need to calculate the adjusted flow rate of a pump
based on measured flow, temperature compensation, and a scaling factor. This shows how arithmetic operators are
used in a real PLC program.
-
Variables:
- FlowSensor1 – Measured flow from sensor 1 (L/min)
- FlowSensor2 – Measured flow from sensor 2 (L/min)
- TempComp – Temperature compensation factor
- ScaleFactor – Scaling factor to adjust units
- AdjustedFlow – Calculated final flow (L/min)
-
ST Code Example:
AverageFlow := (FlowSensor1 + FlowSensor2) / 2;
TempAdjustedFlow := AverageFlow * TempComp;
AdjustedFlow := TempAdjustedFlow * ScaleFactor;
-
Explanation:
- Step 1: Calculate the average of the two flow sensors to reduce measurement error.
- Step 2: Apply temperature compensation to account for fluid density changes.
- Step 3: Multiply by a scaling factor to convert to the desired units or adjust for pump calibration.
This simple arithmetic chain demonstrates how addition, division, and multiplication operators can be combined in a
practical, real-world PLC application. Engineers can extend this logic further by adding safety checks, conditional
limits, or integrating it into alarms and data logging routines.
Conditional Operators in Schneider PLC Structured Text (IF…THEN…ELSE)
Conditional operators in Structured Text (ST) allow a PLC program to make decisions based on
process values. Using IF…THEN…ELSE statements, you can compare variables and execute specific code
blocks only when certain conditions are met. This is essential for automation tasks such as controlling motors,
valves, alarms, or any equipment that needs to react to changing process conditions.
-
Basic IF Statement
IF Temperature > 70 THEN Fan := TRUE; END_IF;
Turns on a fan if the temperature exceeds 70°C.
-
IF…ELSE Statement
IF Level < 50 THEN Pump := TRUE;
ELSE Pump := FALSE;
END_IF;
Starts the pump if the tank level is below 50% and stops it otherwise.
-
Nested IF Example
IF Pressure > 100 THEN
Valve := FALSE;
ELSIF Pressure > 80 THEN
Valve := TRUE;
ELSE
Valve := TRUE;
END_IF;
Demonstrates multiple conditions: the valve reacts differently depending on the measured pressure.
Conditional operators are essential for process control and safety logic. They allow your Schneider PLC program
to react dynamically to changing inputs, implement alarms, control actuators, or manage machine cycles effectively.
Combining conditional logic with arithmetic operations enables advanced automation strategies.
Practical Conditional Example in Schneider PLC Structured Text
Building on our previous example of calculating AdjustedFlow, we can use conditional operators to
make decisions. For instance, we may want the PLC to start or stop a pump depending on the flow, or trigger an
alarm if the flow is too high or too low. This demonstrates how arithmetic results feed directly into process control.
-
Variables:
- AdjustedFlow – Calculated final flow (L/min)
- MinFlow – Minimum safe flow threshold
- MaxFlow – Maximum safe flow threshold
- PumpStatus – Boolean to start/stop the pump
- Alarm – Boolean for high/low flow alarms
-
ST Code Example:
IF AdjustedFlow < MinFlow THEN
PumpStatus := TRUE; // Start pump
Alarm := TRUE; // Low flow alarm
ELSIF AdjustedFlow > MaxFlow THEN
PumpStatus := FALSE; // Stop pump
Alarm := TRUE; // High flow alarm
ELSE
PumpStatus := TRUE; // Normal operation
Alarm := FALSE; // No alarm
END_IF;
-
Explanation:
- If the adjusted flow is below the safe minimum, the pump is turned on to reach target flow and a low-flow alarm is activated.
- If the flow exceeds the maximum safe limit, the pump is turned off to prevent overpressure, and a high-flow alarm is triggered.
- If the flow is within safe limits, the pump continues normal operation and no alarm is activated.
This example shows how conditional operators in Structured Text can control real-world processes safely and efficiently.
Combining arithmetic calculations with IF…THEN…ELSE logic allows the PLC to react dynamically to changing conditions,
ensuring reliable and automated operation of industrial equipment.
Combined Arithmetic and Conditional Example in Schneider PLC Structured Text
In real-world industrial automation, arithmetic operations are often followed by conditional checks. For example,
after calculating an adjusted flow rate, a PLC can decide whether to start or stop a pump and trigger alarms if
necessary. This example shows how both arithmetic and conditional operators work together in Schneider PLC Structured Text.
-
Scenario: Control a water pump based on flow measurements from two sensors, apply temperature compensation,
and ensure the pump operates safely within predefined limits.
-
Variables:
- FlowSensor1, FlowSensor2 – Measured flows (L/min)
- TempComp – Temperature compensation factor
- ScaleFactor – Flow scaling factor
- AdjustedFlow – Calculated flow after arithmetic adjustments
- MinFlow, MaxFlow – Safe flow thresholds
- PumpStatus – Boolean to start/stop pump
- Alarm – Boolean for high/low flow alarms
-
ST Code Example:
// Arithmetic calculations
AverageFlow := (FlowSensor1 + FlowSensor2) / 2;
TempAdjustedFlow := AverageFlow * TempComp;
AdjustedFlow := TempAdjustedFlow * ScaleFactor;
// Conditional logic
IF AdjustedFlow < MinFlow THEN
PumpStatus := TRUE; // Start pump
Alarm := TRUE; // Low flow alarm
ELSIF AdjustedFlow > MaxFlow THEN
PumpStatus := FALSE; // Stop pump
Alarm := TRUE; // High flow alarm
ELSE
PumpStatus := TRUE; // Normal operation
Alarm := FALSE; // No alarm
END_IF;
-
Explanation:
- Step 1: Calculate the average of two flow sensors to reduce measurement errors.
- Step 2: Apply temperature compensation and scaling to get the final adjusted flow.
- Step 3: Use conditional operators to decide whether to start/stop the pump and trigger alarms.
- Step 4: Ensure the pump runs safely within minimum and maximum flow limits.
Combining arithmetic and conditional logic in this way allows Schneider PLC programs to perform real-time calculations
and make decisions automatically. This pattern is widely used in industrial automation for process control, safety,
and efficiency improvements.