📖 Scenario: You are programming a conveyor sorting system in a factory. The conveyor moves items, and sensors detect the item type. Based on the type, the system activates different sorting arms to direct items to the correct bins.
🎯 Goal: Build a simple PLC program that reads item types from sensors, uses a configuration threshold to decide sorting, and activates the correct sorting arm outputs.
📋 What You'll Learn
Create a variable to hold the current item type detected by the sensor
Create a configuration variable for the sorting threshold
Use a conditional statement to decide which sorting arm to activate based on the item type and threshold
Output the activation signal for the correct sorting arm
💡 Why This Matters
🌍 Real World
Conveyor sorting systems are common in factories to automate sorting of products by type, size, or quality. PLC programs control sensors and actuators to perform this task efficiently.
💼 Career
Understanding how to program sorting logic in PLCs is essential for automation engineers working in manufacturing and industrial automation.
Progress0 / 4 steps
1
Set up the item type variable
Create a variable called itemType of type INT and set it to 3, representing the detected item type.
PLC Programming
Hint
Use the VAR block to declare variables. Set itemType to 3.
2
Add sorting threshold configuration
Add a variable called sortingThreshold of type INT and set it to 2. This will be used to decide sorting logic.
PLC Programming
Hint
Declare sortingThreshold in the same VAR block as itemType.
3
Implement sorting logic
Write an IF statement that checks if itemType is greater than sortingThreshold. If true, set a BOOL variable activateArm1 to TRUE, else set activateArm2 to TRUE. Declare both BOOL variables before the IF statement and initialize them to FALSE.
PLC Programming
Hint
Use IF...THEN...ELSE to compare itemType and sortingThreshold. Set the BOOL variables accordingly.
4
Output the sorting arm activation
Write code to output the values of activateArm1 and activateArm2 to the console using WriteLn statements. Output exactly these two lines: WriteLn("Arm1 Active: ", activateArm1); and WriteLn("Arm2 Active: ", activateArm2);
PLC Programming
Hint
Use WriteLn to print the BOOL variables with the exact text.
Practice
(1/5)
1. In a conveyor sorting system, what is the main role of sensors?
easy
A. To power the entire system
B. To move the conveyor belt forward
C. To detect items and send signals for sorting decisions
D. To clean the conveyor belt automatically
Solution
Step 1: Understand sensor function in sorting
Sensors detect the presence or type of items on the conveyor.
Step 2: Connect sensor signals to sorting
The system uses sensor signals to decide where to send each item.
Final Answer:
To detect items and send signals for sorting decisions -> Option C
Quick Check:
Sensors detect items = C [OK]
Hint: Sensors detect items to guide sorting [OK]
Common Mistakes:
Confusing sensors with motors
Thinking sensors power the system
Assuming sensors clean the belt
2. Which of the following is the correct syntax for a simple IF statement in PLC ladder logic to check if a sensor is ON?
easy
A. IF Sensor1 = TRUE THEN Conveyor := ON;
B. IF (Sensor1 == ON) { Conveyor = ON }
C. IF Sensor1 THEN Conveyor ON;
D. IF Sensor1 = ON THEN Conveyor := ON;
Solution
Step 1: Identify correct PLC syntax
PLC languages often use ':=' for assignment and 'THEN' for conditions.
Step 2: Check sensor condition and assignment
IF Sensor1 = TRUE THEN Conveyor := ON; uses 'Sensor1 = TRUE' and 'Conveyor := ON;' which matches PLC style.
Final Answer:
IF Sensor1 = TRUE THEN Conveyor := ON; -> Option A
Quick Check:
Correct PLC IF syntax = A [OK]
Hint: Look for ':=' assignment and 'THEN' keyword [OK]
Common Mistakes:
Using '==' instead of '='
Missing ':=' for assignment
Using curly braces which are not PLC style
3. Given the following PLC code snippet for a conveyor sorting system:
IF SensorA = TRUE THEN Diverter := LEFT; ELSE Diverter := RIGHT; END_IF;
What will be the value of Diverter if SensorA is FALSE?
medium
A. LEFT
B. FALSE
C. TRUE
D. RIGHT
Solution
Step 1: Analyze the IF condition
The code sets Diverter to LEFT if SensorA is TRUE.
Step 2: Determine ELSE action when SensorA is FALSE
When SensorA is FALSE, Diverter is set to RIGHT.
Final Answer:
RIGHT -> Option D
Quick Check:
SensorA FALSE leads to Diverter RIGHT [OK]
Hint: FALSE condition triggers ELSE branch [OK]
Common Mistakes:
Assuming Diverter stays unchanged
Confusing TRUE and FALSE branches
Mixing variable names
4. Identify the error in this PLC code snippet for sorting items:
IF Sensor1 = TRUE THEN Conveyor := ON ELSE Conveyor := OFF; END_IF;
medium
A. Missing semicolon after 'Conveyor := ON'
B. Incorrect use of ELSE statement
C. Sensor1 should be compared with FALSE
D. Assignment operator ':=' is invalid
Solution
Step 1: Check statement endings
Each assignment line in PLC code must end with a semicolon.
Step 2: Locate missing semicolon
The line 'Conveyor := ON' lacks a semicolon at the end.
Final Answer:
Missing semicolon after 'Conveyor := ON' -> Option A
Quick Check:
Semicolon missing = D [OK]
Hint: Check each line ends with semicolon [OK]
Common Mistakes:
Ignoring semicolon errors
Misreading ELSE syntax
Thinking ':=' is wrong assignment
5. You want to program a conveyor sorting system that directs items to three paths: LEFT, CENTER, or RIGHT based on two sensors: SensorX and SensorY.
If SensorX is TRUE and SensorY is FALSE, send to LEFT. If SensorX is FALSE and SensorY is TRUE, send to RIGHT. Otherwise, send to CENTER.
Which PLC code snippet correctly implements this logic?
hard
A.
IF SensorX = TRUE OR SensorY = FALSE THEN
Diverter := LEFT;
ELSEIF SensorX = FALSE OR SensorY = TRUE THEN
Diverter := RIGHT;
ELSE
Diverter := CENTER;
END_IF;
B.
IF SensorX = TRUE AND SensorY = FALSE THEN
Diverter := LEFT;
ELSIF SensorX = FALSE AND SensorY = TRUE THEN
Diverter := RIGHT;
ELSE
Diverter := CENTER;
END_IF;
C.
CASE
WHEN SensorX = TRUE AND SensorY = FALSE THEN Diverter := LEFT;
WHEN SensorX = FALSE AND SensorY = TRUE THEN Diverter := RIGHT;
ELSE Diverter := CENTER;
END_CASE;
D.
IF SensorX = TRUE THEN
Diverter := LEFT;
ELSEIF SensorY = TRUE THEN
Diverter := RIGHT;
ELSE
Diverter := CENTER;
END_IF;
Solution
Step 1: Match conditions to logic
IF SensorX = TRUE AND SensorY = FALSE THEN
Diverter := LEFT;
ELSIF SensorX = FALSE AND SensorY = TRUE THEN
Diverter := RIGHT;
ELSE
Diverter := CENTER;
END_IF;
uses AND to check both sensors exactly as required.
Step 2: Verify ELSEIF and ELSE branches
IF SensorX = TRUE AND SensorY = FALSE THEN
Diverter := LEFT;
ELSIF SensorX = FALSE AND SensorY = TRUE THEN
Diverter := RIGHT;
ELSE
Diverter := CENTER;
END_IF;
correctly uses ELSIF for second condition and ELSE for default.
Step 3: Check other options for errors
IF SensorX = TRUE OR SensorY = FALSE THEN
Diverter := LEFT;
ELSEIF SensorX = FALSE OR SensorY = TRUE THEN
Diverter := RIGHT;
ELSE
Diverter := CENTER;
END_IF;
uses OR incorrectly, C uses CASE but syntax is not standard PLC, D misses combined conditions.
Final Answer:
The code snippet with AND conditions -> Option B
Quick Check:
Correct AND conditions and ELSIF = A [OK]
Hint: Use AND for combined sensor checks, ELSIF for second condition [OK]
Common Mistakes:
Using OR instead of AND for combined conditions
Incorrect CASE syntax in PLC
Missing combined sensor checks
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.