Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 37 ยท Projects and Practice

PLC Project - Conveyor Sorting Line with Shift Register

Build a conveyor sorting line: part detection, size classification, tracking parts with a shift register, diverter timing, counters, jam detection and a runnable C simulation.

A conveyor carries parts past a sensor; a diverter pushes the tall ones off to a side chute; a counter keeps totals; a jam detector stops the belt if something gets stuck. This project is typical of packaging and logistics machines and uses nearly everything from the earlier chapters: edges, counters, timers, a state machine and fault handling. It also introduces tracking: remembering where each part is while the belt moves.

PLC hardware is not available on this site. The design is a plan with read-only text, and the runnable programs are C stand-ins that simulate the belt.

Requirements

  • A belt moves at constant speed. A photo-eye (E1) at the start detects each part; a height sensor (H1) at the same position says tall or short when the part passes.
  • Tall parts must be pushed off by a diverter cylinder 1.6 m downstream. Short parts continue to the end.
  • A counter tracks tall parts, short parts and the total.
  • If E1 stays blocked longer than 3 s, there is a jam: stop the belt and alarm.
  • If the diverter does not confirm its retracted position within 1 s after a push, fault the line.
  • Start/stop buttons, an E-stop (hardwired safety) and a reset.

Tracking parts with a shift register

The diverter is far from the sensor, so the PLC must remember each part's classification until it arrives. Two common techniques:

  1. Timer-based: start a delay when a tall part is detected; fire the diverter when it expires. Simple, but wrong if the belt speed changes.
  2. Encoder-based shift register: an encoder gives pulses proportional to belt travel. Every N pulses (one "slot", for example 50 mm), all stored values shift one position, and a new value enters at the sensor position. The diverter looks at the slot where it is located. This stays correct at any speed.
flowchart LR
    S["Sensor slot 0"] --> A["slot 1"] --> B["slot 2"] --> C["..."] --> D["slot 31<br/>diverter position"]

On each belt step the register shifts one slot toward the diverter. Slot values are 0 = empty, 1 = short, 2 = tall.

A shift register in C

A byte array plays the role of the register. We shift it on each belt step and inject parts at the start.

C C stand-in: tracking parts down the belt

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Each tall part moves down the register until it reaches the diverter slot, where the output fires for that step. The same register handles any belt speed because it advances per belt movement, not per second.

Counting with edges and a jam timer

The sensor must be counted on its rising edge once per part, and a jam is a blocked sensor for too long. Both can be done by the same input.

C C stand-in: counting parts and detecting a jam

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

The three short blocks are counted as three parts. The long block adds a fourth count (its rising edge) and then trips the jam timer.

Putting the controller together

The main states are STOPPED, RUNNING, JAMMED and FAULT, with the sort logic active in RUNNING. The diverter itself is a small sequence: extend, wait for the end sensor, retract, wait for the home sensor, each with a timeout. Here is the full simulation with the register, counters and the diverter timing combined.

C C stand-in: complete sorting line simulation

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Four tall parts arrive but only two are pushed (tall: 2): the cylinder needs a step to extend and another to retract, so tall parts reaching the diverter while it is busy pass by unpushed. The cylinder cycle time limits throughput, which means a faster cylinder, wider part spacing or a second diverter. Finding such limits early is a core design skill.

Test checklist

  1. Single tall and short parts are classified and counted correctly.
  2. Parts arriving close together: does the diverter keep up? Define the minimum spacing.
  3. Belt stops and starts mid-run: the register keeps positions (it advances only when the encoder moves).
  4. Jam: belt stops and alarm shows; after clearing and reset, the register is cleared.
  5. E-stop and recovery follow the safety rules.
  6. Counters survive a power cycle (retentive) or reset as specified.

Extensions

  • Send counts to a SCADA historian every minute.
  • Add a third class (medium) with a second diverter.
  • Add a reject station using a barcode reader result received over a network protocol.
  • Display the register contents on the HMI as a live belt picture.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why use an encoder-driven shift register instead of a simple time delay?

    The register advances with belt travel, not elapsed time, so positions stay right at any speed.
  2. 2. What distinguishes a jam from a normal part passing the sensor?

    A normal part blocks the sensor briefly; a long block means something is stuck.
  3. 3. Two tall parts arrive faster than the diverter can cycle. What is the likely result?

    The actuator's cycle time limits throughput; the design must respect it.
  4. 4. Why count parts on the rising edge of the sensor?

    A part blocks the sensor for many scans, so counting levels would multiply the count.

Summary

  • Track parts with an encoder-driven shift register so positions are independent of time.
  • Count with rising edges; detect jams with a blocked-time limit.
  • Sequence the diverter with timeouts, and respect actuator cycle times.
  • Test spacing, stops and restarts, jams and recovery.
  • The C programs are stand-ins simulating the belt.

Next: PLC Practice Exercises and Review