Pro
35 min

Sorting Machine PLC Program & Ladder Diagram

This page covers the full sorting machine PLC program and ladder diagram — metal-versus-plastic part sorting using an inductive sensor, a pneumatic reject gate, a CTU production counter, and a safety interlock that keeps the gate from firing while a part still breaks the entry beam. It is grounded in a live scenario you can run directly in your browser: write the ladder, watch parts travel and sort, and get instant pass/fail feedback — no PLC hardware, no software install. It is runnable and auto-graded free.

sensorscounterssorting
Sorting Machine scenario preview

Ready to build this?

Sign up free — no credit card required. This scenario requires the Pro plan.

Sign up to play this scenario →

Already have an account? Log in

Briefing

Mixed parts travel along a sorting belt. An entry photo-eye announces each arriving part. An inductive METAL_SENSOR further down the line fires only for metal parts — plastic parts pass it without a signal. Metal parts must be diverted onto a reject lane by firing REJECT_GATE while the part is passing the diverter arm; plastic parts continue straight. A counter watches the reject lane's limit sensor and lights METAL_COUNT_LAMP once five metal parts have been rejected.

Objectives

  • START energises BELT; STOP de-energises it
  • Fire REJECT_GATE so that metal parts are pushed onto the reject lane
  • Leave REJECT_GATE off for plastic parts
  • Light METAL_COUNT_LAMP once 5 metal parts have cleared the reject-lane limit sensor
  • Never energise REJECT_GATE while PART_PE is still broken — the arm would collide with the part

Hints

  • Use SET/RESET on BELT driven by START (set) and STOP (reset)
  • SET REJECT_GATE on METAL_SENSOR and RESET it on REJECT_LIMIT — the belt spacing guarantees PART_PE has already cleared before METAL_SENSOR fires
  • Count REJECT_LIMIT rising edges with a CTU (PV := 5) and drive METAL_COUNT_LAMP from its Q output
  • Plastic parts never trip METAL_SENSOR, so the same gate logic leaves them untouched — no separate plastic branch is needed

I/O Table

Inputs

START

Start push-button (momentary)

BOOL · %I0.0

STOP

Stop push-button (momentary)

BOOL · %I0.1

PART_PE

Entry photo-eye (beam broken by any part)

BOOL · %I0.2

METAL_SENSOR

Inductive sensor (true only for metal parts)

BOOL · %I0.3

REJECT_LIMIT

Reject-lane limit sensor

BOOL · %I0.4

Outputs

BELT

Sorting belt motor contactor

BOOL · %Q0.0

REJECT_GATE

Pneumatic reject-gate solenoid (diverts metal)

BOOL · %Q0.1

METAL_COUNT_LAMP

Metal count ≥ 5 indicator

BOOL · %Q0.2

Your program will be tested against:

All test cases run automatically when you submit. Assertions are hidden until you pass.

  1. #1Metal part fires the reject gate and is diverted

    Inject a metal part: gate energises across the transit window, part reaches the reject lane

  2. #2Start energises the belt, stop drops it

    START -> BELT on; STOP -> off

  3. #3Plastic part passes without firing the reject gate

    Inject a plastic part: reject gate remains off throughout the run

  4. #4Five metal parts light METAL_COUNT_LAMP

    Five metal parts injected spaced apart; METAL_COUNT_LAMP energises after the fifth is rejected

  5. #5Reject gate never fires while a part still breaks the entry beam

    Inject a metal part; assert the gate was never energised while PART_PE was active

How a sorting machine PLC program works

A sorting machine moves mixed parts along a belt and diverts one category onto a reject lane while letting the rest pass straight through. In this scenario the discriminator is material: metal parts must be rejected, plastic parts pass. Object sorting using a PLC comes down to four jobs — run the belt, detect the part type, fire a diverter at the right moment, and count what was sorted.

The belt is the foundation. START energises BELT and STOP de-energises it — a standard motor start/stop you can build with a SET/RESET pair on BELT driven by START (set) and STOP (reset).

Detection uses two sensors in sequence. PART_PE (%I0.2) is an entry photo-eye whose beam is broken by any arriving part — metal or plastic. Further down the line, METAL_SENSOR (%I0.3) is an inductive sensor that fires only for metal: plastic parts pass it without ever producing a signal. That is the whole material discrimination — no separate plastic branch is needed, because plastic simply never trips the inductive sensor.

The diverter is REJECT_GATE (%Q0.1), a pneumatic solenoid that pushes a part onto the reject lane. REJECT_LIMIT (%I0.4) is the limit sensor at the reject lane that confirms a part has been pushed across. Finally, METAL_COUNT_LAMP (%Q0.2) lights once five metal parts have been rejected. Five inputs, three outputs — all pre-wired for you.

Metal-vs-plastic sorting with an inductive sensor and reject gate

The sort logic is one latch. SET REJECT_GATE when METAL_SENSOR detects metal; RESET REJECT_GATE when REJECT_LIMIT confirms the part has reached the reject lane. While the gate is set, the pneumatic arm is extended and pushes the metal part off the main belt; once REJECT_LIMIT trips, the part is clear and the gate retracts ready for the next one.

This is the elegant part of inductive sensor PLC sorting: the same single rung handles both materials. A metal part trips METAL_SENSOR, so the gate fires and diverts it. A plastic part never trips METAL_SENSOR, so the gate stays off and the part rides straight through to the end of the belt. You do not write a 'plastic' rung at all — the absence of an inductive signal is the plastic case.

Two test cases pin this down. The discriminating 'metal-part-diverts' case injects a metal part and checks the gate is still off before the part reaches METAL_SENSOR (~2 s in), energised after METAL_SENSOR fires (~4 s), and dropped again after REJECT_LIMIT (~6 s) — and that the physics counted exactly one rejected metal part. The 'plastic-part-passes' case injects a plastic part, lets it traverse the entire belt, and asserts REJECT_GATE never energised and the metal-rejected count stayed at zero. Get the SET sensor wrong — fire on PART_PE instead of METAL_SENSOR — and the plastic test fails because the gate would divert everything.

Counting rejects with a CTU — lighting the lamp after five metal parts

Once the gate is sorting correctly, the metal sorting PLC program needs a production count: light METAL_COUNT_LAMP after five metal parts have been rejected. This is a textbook CTU (count-up) application.

Add a CTU with its preset (PV) set to 5. Drive the count-up input from REJECT_LIMIT — but through a rising-edge detector. REJECT_LIMIT is a level signal: it stays true for as long as a part is physically over the limit sensor. Feed that level straight into the CTU and the counter would increment on every scan the sensor is blocked, adding dozens of spurious counts per part. An R_TRIG (or equivalent one-shot) converts the level to a single pulse, giving you exactly one count per rejected part.

Wire the CTU's done output (CTU.Q in IEC, CTU.DN in Allen-Bradley) to METAL_COUNT_LAMP. When the accumulator reaches 5 the done bit goes true and the lamp lights.

The 'counter' test injects five metal parts spaced seven seconds apart — wide enough that each part clears the entry beam before the next reaches the inductive sensor. It asserts METAL_COUNT_LAMP is still off after the fourth part has been rejected and on after the fifth, and it checks the physics engine's metalRejectedCount is exactly 5. Because plastic parts never reach the reject lane, they never trip REJECT_LIMIT and never inflate the count — the counter inherently tallies only metal.

The safety interlock — never fire the gate while the entry beam is broken

Every diverter on a sorting line has the same mechanical hazard: if the reject gate extends while a part is still partly over the arm's pivot, the arm slams into the part and jams the machine. The safety rule, stated as an objective, is that REJECT_GATE must never energise while PART_PE — the entry photo-eye — is still broken.

The scenario's belt spacing makes the safe design natural rather than fiddly. By the time a part travels far enough down the belt to reach METAL_SENSOR, it has already cleared the entry photo-eye, so PART_PE is no longer broken. That is exactly why the sort latch is built to SET REJECT_GATE on METAL_SENSOR and not on PART_PE: firing on the inductive sensor guarantees the part is already past the entry beam. If instead you fired the gate the instant PART_PE detected a part, the arm could collide with the part while it is still entering — the violation the interlock exists to prevent.

The 'safety-invariant' test injects a metal part, lets it run the full length of the belt past REJECT_LIMIT, and then asserts the physics flag rejectWhileEntryViolation is false — i.e. at no point during the run was the gate energised while PART_PE was still broken. A solution that sorts correctly on count and material but fires the gate too early will pass the divert and counter tests yet fail this one.

The whole sorting machine PLC ladder diagram is runnable and auto-graded on this page. Write it, press Run, and watch metal parts divert onto the reject lane while plastic parts pass — with five automated test cases grading the belt, the metal divert, the plastic pass-through, the five-count lamp, and the entry-beam safety interlock. No physical PLC, conveyor or sensors required.

Frequently asked questions

How does a PLC sorting machine separate metal from plastic?

It uses an inductive proximity sensor, which produces a signal only when a metal part passes in front of it — plastic parts pass without any signal. The PLC program latches a reject-gate solenoid on when the inductive sensor fires and resets it when a reject-lane limit sensor confirms the part has been pushed across. Metal parts trip the inductive sensor and get diverted; plastic parts never trip it, so the gate stays off and they pass straight through. No separate plastic-detection logic is needed.

What ladder logic does a sorting machine PLC program use?

A sorting machine PLC ladder diagram uses a SET/RESET pair on the belt motor (SET on START, RESET on STOP), a SET/RESET pair on the reject-gate solenoid (SET when the inductive metal sensor fires, RESET when the reject-lane limit sensor confirms the divert), and a CTU count-up counter fed by a rising-edge detector on the limit sensor to tally rejected parts. The CTU done bit drives the count lamp once the preset (for example 5) is reached.

How do you count sorted parts in a PLC program?

Add a CTU (count-up) counter with its preset set to the target — for example 5. Drive the count-up input from the reject-lane limit sensor through a rising-edge detector (R_TRIG) so the counter increments exactly once per part rather than once per scan while the sensor is blocked. Wire the CTU done output (CTU.Q in IEC, CTU.DN in Allen-Bradley) to the indicator lamp; it lights when the accumulator reaches the preset. Because only diverted metal parts reach the limit sensor, the counter inherently tallies metal only.

What is the safety interlock in a sorting machine PLC program?

The reject gate must never extend while a part is still breaking the entry photo-eye, or the pneumatic arm collides with the part and jams the machine. The safe design sets the gate on the inductive metal sensor rather than the entry photo-eye: by the time a part reaches the metal sensor further down the belt, it has already cleared the entry beam. The scenario verifies this with a test that injects a metal part and asserts the gate was never energised while the entry beam was still broken.

Can I simulate a sorting machine PLC program without hardware?

Yes. The Sorting Machine scenario on this page runs directly in your browser — write the ladder logic, press Run, and watch metal parts divert onto a reject lane while plastic parts pass straight through. The physics engine moves parts at a realistic belt speed and fires the photo-eye, inductive sensor and limit sensor at the correct positions, and the auto-grader checks the belt start/stop, the metal divert, the plastic pass-through, the five-part count lamp, and the entry-beam safety interlock. No physical PLC, conveyor or sensors required.

Ready to build this?

Sign up free — no credit card required. This scenario requires the Pro plan.

Sign up to play this scenario →

Already have an account? Log in