Comparison Instructions (EQ, NE, GT, LT) in PLC Programming
📖 Scenario: You are programming a simple PLC (Programmable Logic Controller) to control a machine. The machine needs to check sensor values and make decisions based on comparisons.For example, the machine should check if a temperature sensor reading equals a setpoint, or if a pressure sensor reading is greater than a safety limit.
🎯 Goal: Build a PLC program that uses comparison instructions EQ (equal), NE (not equal), GT (greater than), and LT (less than) to compare sensor values with setpoints and store the results in boolean variables.
📋 What You'll Learn
Create integer variables for sensor readings and setpoints
Create boolean variables to store comparison results
Use EQ, NE, GT, and LT instructions to compare values
Output the boolean results using print statements
💡 Why This Matters
🌍 Real World
PLC programs often need to compare sensor readings with setpoints to make decisions like turning machines on or off, triggering alarms, or adjusting controls.
💼 Career
Understanding comparison instructions is essential for PLC programmers to write logic that controls industrial machines safely and efficiently.
Progress0 / 4 steps
1
Create sensor and setpoint variables
Create integer variables called temperature and pressure with values 75 and 120 respectively. Also create integer variables called temp_setpoint and pressure_limit with values 75 and 100 respectively.
PLC Programming
Hint
Use simple assignment statements to create variables with the exact names and values.
2
Create boolean variables for comparison results
Create boolean variables called temp_equals_setpoint, pressure_not_equal_limit, pressure_greater_than_limit, and temperature_less_than_setpoint. Initialize them all to False.
PLC Programming
Hint
Use assignment statements to create boolean variables with the exact names and set them to False.
3
Use comparison instructions to update boolean variables
Use the comparison instructions EQ, NE, GT, and LT to update the boolean variables: set temp_equals_setpoint to True if temperature equals temp_setpoint, pressure_not_equal_limit to True if pressure is not equal to pressure_limit, pressure_greater_than_limit to True if pressure is greater than pressure_limit, and temperature_less_than_setpoint to True if temperature is less than temp_setpoint.
PLC Programming
Hint
Use Python comparison operators ==, !=, >, and < to set the boolean variables.
4
Print the comparison results
Print the values of temp_equals_setpoint, pressure_not_equal_limit, pressure_greater_than_limit, and temperature_less_than_setpoint each on a new line.
PLC Programming
Hint
Use print() to display each boolean variable on its own line.
Practice
(1/5)
1. Which comparison instruction checks if two values are exactly the same in PLC programming?
easy
A. EQ
B. NE
C. GT
D. LT
Solution
Step 1: Understand the meaning of EQ
EQ stands for 'equal' and checks if two values are exactly the same.
Step 2: Compare with other instructions
NE means not equal, GT means greater than, and LT means less than, so they do not check equality.
Final Answer:
EQ -> Option A
Quick Check:
EQ means equal [OK]
Hint: EQ means equal, so it checks if values match exactly [OK]
Common Mistakes:
Confusing EQ with NE
Thinking GT checks equality
Mixing LT with EQ
2. Which of the following is the correct syntax to check if variable A is greater than variable B in a PLC program?
easy
A. IF A LT B THEN
B. IF A NE B THEN
C. IF A EQ B THEN
D. IF A GT B THEN
Solution
Step 1: Identify the comparison for 'greater than'
GT means 'greater than', so to check if A is greater than B, use 'A GT B'.
Step 2: Check other options
LT means less than, EQ means equal, NE means not equal, so they are incorrect for this check.
Final Answer:
IF A GT B THEN -> Option D
Quick Check:
GT means greater than [OK]
Hint: GT means greater than, so use it to compare if A > B [OK]
Common Mistakes:
Using LT instead of GT
Confusing EQ with GT
Using NE for greater than check
3. Given the following PLC code snippet:
VAR
X: INT := 5;
Y: INT := 10;
Result: BOOL;
END_VAR
Result := X LT Y;
What will be the value of Result after execution?
medium
A. Syntax Error
B. FALSE
C. TRUE
D. Undefined
Solution
Step 1: Understand the comparison LT
LT means 'less than'. The code checks if X (5) is less than Y (10).
Step 2: Evaluate the condition
Since 5 is less than 10, the condition is true, so Result will be TRUE.
Final Answer:
TRUE -> Option C
Quick Check:
5 LT 10 = TRUE [OK]
Hint: LT means less than; 5 < 10 is true [OK]
Common Mistakes:
Thinking LT means greater than
Assuming Result is FALSE
Confusing syntax with error
4. Identify the error in this PLC comparison instruction:
IF A NEQ B THEN
// do something
END_IF
medium
A. Missing THEN keyword
B. NEQ is not a valid comparison instruction
C. Comparison should be EQ instead of NEQ
D. IF statement missing parentheses
Solution
Step 1: Check the comparison instruction used
The code uses 'NEQ' which is not a standard PLC comparison instruction.
Step 2: Identify correct instruction
The correct instruction for 'not equal' is 'NE', not 'NEQ'.
Final Answer:
NEQ is not a valid comparison instruction -> Option B
Quick Check:
Use NE for not equal, not NEQ [OK]
Hint: Use NE for not equal, not NEQ [OK]
Common Mistakes:
Using NEQ instead of NE
Forgetting THEN keyword
Adding unnecessary parentheses
5. You want to write a PLC program that turns on a motor only if the temperature is greater than 50 and the pressure is less than 100. Which combination of comparison instructions correctly checks this condition?
hard
A. IF Temperature GT 50 AND Pressure LT 100 THEN Motor := TRUE;
B. IF Temperature LT 50 OR Pressure GT 100 THEN Motor := TRUE;
C. IF Temperature EQ 50 AND Pressure EQ 100 THEN Motor := TRUE;
D. IF Temperature NE 50 AND Pressure NE 100 THEN Motor := TRUE;
Solution
Step 1: Translate the condition into comparisons
The motor should turn on if temperature is greater than 50 (GT 50) and pressure is less than 100 (LT 100).
Step 2: Check each option
IF Temperature GT 50 AND Pressure LT 100 THEN Motor := TRUE; uses GT and LT with AND, matching the condition exactly. Other options use wrong comparisons or OR instead of AND.
Final Answer:
IF Temperature GT 50 AND Pressure LT 100 THEN Motor := TRUE; -> Option A
Quick Check:
GT and LT with AND matches condition [OK]
Hint: Use GT for greater, LT for less, combine with AND for both conditions [OK]
Common Mistakes:
Using OR instead of AND
Using EQ instead of GT or LT
Mixing NE with equality checks
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.