Fareed Mohmed← Project library

Engineering · Raspberry Pi · Project 21 of 47 · Industrial automation · Advanced

Conveyor sorter with a diverter gate

A belt carries parts past two beam sensors at different heights. A tall part breaks both beams, a short part breaks only the low one. A servo gate sends each part to the right bin.

▶ Open in the simulator

Raspberry Pi simulator drawing of the circuit for Conveyor sorter with a diverter gate: the board, its power supply and the parts wired to the 40-pin header
Machine safety. This project only shows signalling and logic. A real emergency stop must cut power through hard-wired safety-rated contacts and relays and must never depend on software or a Raspberry Pi.

Parts in this circuit

PartType
Conveyor motorL298N motor driver
Low beam (3 cm)Beam sensor
High beam (8 cm)Beam sensor
Diverter gateServo

Wiring, pin by pin

Red = 5 V, orange = 3.3 V, black = GND, other colours = signals. “Pin” is the position on the 40-pin header; the GPIO number is what the code uses. Power the Pi from a 5.1 V supply and wire with the power off.

#ColourFrom (part and leg)To (header pin)
1ColouredConveyor motor - ENAPin 32 (GPIO12)
2ColouredConveyor motor - IN1Pin 29 (GPIO5)
3ColouredConveyor motor - IN2Pin 31 (GPIO6)
4RedConveyor motor - 5VPin 2 (5V)
5BlackConveyor motor - GNDPin 6 (GND)
6RedLow beam (3 cm) - VCCPin 4 (5V)
7ColouredLow beam (3 cm) - OUTPin 7 (GPIO4)
8BlackLow beam (3 cm) - GNDPin 9 (GND)
9RedHigh beam (8 cm) - VCCPin 2 (5V)
10ColouredHigh beam (8 cm) - OUTPin 15 (GPIO22)
11BlackHigh beam (8 cm) - GNDPin 14 (GND)
12ColouredDiverter gate - signalPin 33 (GPIO13)
13RedDiverter gate - 5 VPin 4 (5V)
14BlackDiverter gate - GNDPin 20 (GND)

Python code (gpiozero)

from gpiozero import Motor, Button, AngularServo
from time import sleep

belt = Motor(5, 6, enable=12)
low = Button(4)               # beam 3 cm above the belt
high = Button(22)             # beam 8 cm above the belt
gate = AngularServo(13)       # -45 degrees = bin A, +45 degrees = bin B

short_count = 0
tall_count = 0

belt.forward(0.6)             # run the belt at 60 % speed
gate.angle = 0
print("Belt running. Use the buttons under the board to send parts.")

while True:
    low.wait_for_press()      # a part has arrived
    sleep(0.05)               # let both beams settle
    if high.is_pressed:
        tall_count += 1
        gate.angle = 45
        print("TALL part -> bin B   (tall:", tall_count, ")")
    else:
        short_count += 1
        gate.angle = -45
        print("SHORT part -> bin A  (short:", short_count, ")")
    low.wait_for_release()    # wait until the part has gone

How the code works

You will learn

  • Sorting with two sensors
  • Sequencing: detect, decide, act, wait
  • Driving a belt and a gate from one program

Try this

  • Send a short part, then a tall part, and watch the gate move.
  • Run the belt at full speed and move the gate at the right time with sleep().
  • Stop the belt and light a lamp when 10 parts have been sorted.

On a real Pi

  • Use a PLC for a real sorter. A Pi is good for learning the logic and for slow, low-risk lines.
  • Place the gate close to the beams and use the belt speed (distance divided by speed) to time the gate.
  • Add guards and an e-stop that cuts power to the motor with hard-wired contacts.

Parts to buy

The links open a search on each store, so you see what is in stock today. Check the model, voltage and price before you order.

#ItemQtyBuy / compare
1Raspberry Pi 4 Model B
about 4000 to 9000 INR
1Robu.in Amazon.in ThinkRobotics
2Official 15 W USB-C power supply (5.1 V, 3 A)
Do not use an old phone charger
1Robu.in Amazon.in ThinkRobotics
3microSD card 32 GB, class 10 / A1 (with Raspberry Pi OS)
And a card reader to write it
1Robu.in Amazon.in ThinkRobotics
4SG90 micro servo1Robu.in Amazon.in ThinkRobotics
5L298N motor driver module1Robu.in Amazon.in ThinkRobotics
6TT gear motor with wheel, 6 V1Robu.in Amazon.in ThinkRobotics
74 x AA battery holder (6 V) or 9-12 V adapter
Motor supply, separate from the Pi
1Robu.in Amazon.in ThinkRobotics
8IR beam / break-beam sensor pair (3.3 V compatible)2Robu.in Amazon.in ThinkRobotics
9Dupont jumper wires, male-to-female, 20 cm (pack of 40)1Robu.in Amazon.in ThinkRobotics
10Breadboard 830 points
For resistors and shared GND / 5 V
1Robu.in Amazon.in ThinkRobotics
← 20. Machine stack light with start, stop and e-stopAll projects22. Motor start/stop with a seal-in circuit →

This is a learning tool. The simulator checks the program logic, not the electrical design. Never put more than 3.3 V on a GPIO pin.