Structured Text (ST) is one of the five IEC 61131-3 standard programming languages used in PLC development. Among its powerful features is the ability to handle complex logical operations using standard Boolean operators. These logical operators—AND, OR, NOT, XOR—are essential tools for implementing conditional logic, interlocks, safety checks, and control decisions in industrial automation systems. They allow programmers to make decisions based on multiple input conditions or states of the machine or process.
Logical operators work on Boolean variables (TRUE or FALSE) and can be used directly in IF statements, WHILE loops, CASE structures, or as part of complex expressions. For example, using an AND operator ensures that multiple conditions must be met before proceeding, while OR allows any one of the conditions to be true. The NOT operator inverts a condition, making it useful for negating inputs or reversing logic states. XOR is particularly useful in toggle or exclusive control situations, where only one condition should be true at a time.
This page provides a detailed explanation of each logical operator used in Structured Text programming, including their symbols, functions, and example code. Whether you're a beginner learning PLC programming or a professional refining your ST logic, understanding these logical operations is fundamental. Through practical examples and simple syntax explanations, this guide will help you write smarter and more efficient logic for real-time industrial applications.
The logical AND operator in Structured Text is used to evaluate multiple conditions. The result of the AND operation is TRUE only if all the individual conditions are TRUE; otherwise, it returns FALSE. In Structured Text, the keyword for AND is AND, and the symbol used is &. This behavior is identical to an electronic AND gate — where the output is HIGH (1) only when all inputs are HIGH (1); otherwise, the output is LOW (0).
Let’s consider a simple industrial example: we have three limit switches that act as safety interlocks. Each limit switch can either be ON or OFF (TRUE or FALSE). The control logic requires all three switches to be ON (i.e., operated) before a gate can open. This means all the inputs must be TRUE for the output (gate open command) to be activated. If even one switch is OFF, the gate remains closed. The Structured Text logic for this condition uses the AND operator to combine the status of the three switches.
In the first example above, when all three limit switches are TRUE, the program sets the output (e.g., gateOpen := TRUE), and the gate opens. In another example, you can use the AND operator to compare three temperature readings from thermocouples. Suppose you want to activate an alarm only if: temp1 < 20°C, temp2 > 50°C, and temp3 = 40°C. Only when all these conditions are satisfied simultaneously, the logical AND expression evaluates to TRUE, and the alarm is triggered. This demonstrates how AND is used to combine different condition types in a single logical decision.
The logical OR operator returns TRUE when one or more of the evaluated conditions are TRUE; otherwise, the result is FALSE. Its behavior is the same as an electronic OR gate—where the output is HIGH (1) if any of the inputs are HIGH. In Structured Text, the keyword for the OR operation is OR.
Let’s take two simple examples. In the first example, we have four push buttons wired to start a motor. If any one of the push buttons is pressed, the logical OR condition becomes TRUE, and the motor starts. Even if all buttons are pressed, the result is still TRUE. However, if none of the buttons are pressed, the motor remains OFF. This is a typical use case of the OR logic in machine control systems.
In the second example, consider three pressure gauges monitoring a pneumatic line. If the reading of any one of the pressure gauges falls below a predefined setpoint, the compressor will start to maintain system pressure. Even if all gauges read below the setpoint, the compressor still starts. This shows how the OR operator can help detect any failure or threshold breach across multiple inputs.
The XOR (exclusive OR) logical operator returns TRUE only when exactly one of the specified conditions is TRUE. If more than one or none of the conditions are TRUE, the result is FALSE. This behavior is similar to an XOR logic gate in electronics. In Structured Text, the keyword used for this operation is XOR.
A common example involves limit switches and conveyor control. Imagine a system where a conveyor should start only if exactly one of the two limit switches is triggered. If both limit switches are OFF or both are ON, the XOR result is FALSE, and the conveyor will not start. This ensures exclusive operation — useful for safety interlocks or toggling actions where multiple signals shouldn’t be active simultaneously.
In the example shown above, if only one limit switch is operated, the XOR expression evaluates to TRUE, and the conveyor starts. If both switches are inactive or both are triggered at the same time, the result is FALSE, and the conveyor remains stopped. XOR logic is commonly used in error detection, toggles, and mutually exclusive condition checks.
The NOT logical operator in Structured Text is used to invert the result of a logical condition. If the original condition evaluates to TRUE, applying NOT will change the result to FALSE—and vice versa. This is similar to the behavior of a NOT logic gate, where the output is LOW (0) when the input is HIGH (1), and the output is HIGH when the input is LOW.
The NOT operator is helpful when you want to execute an action only when a condition is not met. It can be used with a single condition or to invert the result of more complex logical expressions. In Structured Text, the keyword used is NOT. This operator is especially useful for creating reverse logic, safety stops, or exception handling.
In the first example, the motor remains OFF when the push button is pressed because the NOT operator reverses the logic of the condition. That is, even though the button is ON (TRUE), the NOT makes the condition FALSE, preventing motor operation. In the second example, multiple NOT operators are used together to invert complex expressions, allowing more control over logic behavior in a compact and efficient way.
In the above Structured Text example, multiple logical operators such as AND, OR, NOT, and XOR are combined within a single conditional statement. This demonstrates how complex logic can be constructed using a mix of Boolean expressions to achieve precise control logic in PLC programming.
In the first IF block, the condition checks whether push_button_1 is pressed, pressure_guage_2 is less than or equal to 20.3, or Motor_start_cmd is NOT active. If any of these combined conditions are met, the variable pressure_normal_condition is set to TRUE. Otherwise, it is set to FALSE.
In the second IF block, the condition becomes more advanced by combining pressure_normal_condition AND Motor_start_cmd_sts with a nested XOR and NOT condition. This shows how logical operators can be used together to build layered, decision-based logic in real-time control systems. You can create custom logic based on your application needs using this approach.