← Course overview
Week 9 of 12 · Mechatronics

The Sorting Mechanism & Gravity Slide

Design a low-friction rotating gravity slide and kinematic distribution table to route classified candies into 5 sorted collection cups.

~6 hrs CAD + Kinematics + Code 2nd Stepper

Concept Gravity Flow & Low-Inertia Motion

This week turns classification decisions from Week 8 into physical movement. A second stepper motor rotates a directional gravity chute to align with 5 destination buckets.

Slide Friction Mechanics: Candy sugar coatings sliding over 3D printed PLA layer lines have a static coefficient of friction μs ≈ 0.40–0.48. To guarantee that a Skittle always slides under gravity without stalling, the slide slope must exceed the critical angle θ where tan(θ) > μs (θ > 25.6°). We engineer our slide at 32° to 35° pitch, providing rapid acceleration and zero mid-chute hangs.

Minimizing Rotational Inertia ($I = m \cdot r^2$): When sorting at speed, the motor must accelerate, travel up to 180°, and decelerate to a dead stop in under 200 milliseconds. Any excess weight at the tip of the slide increases rotational inertia quadratically, causing the stepper to skip steps. The chute is designed with thin 1.6mm ribbed walls and a tapered radial profile (slide_v1.stl).

Kit What you need this week

  • Second NEMA-17 stepper motor + Motor HAT (Port M2)
  • Second VMA327 limit switch (wired to GPIO18 / pin 12)
  • 3D printer + PLA filament
  • M3 × 4.5mm heat-set insert + M3 grub screw
  • Reference parts: 3D Files/slide_v1.stl, base_for_slide.stl, cup_plate.stl

Build Step by step

Step 1

CAD: Design the low-friction gravity slide

In Fusion 360 (referencing 3D Files/slide_v1.stl):

  • Sketch a central 5.15mm D-shaft hub with an M3 heat-set grub screw boss.
  • Create a 32° inclined guide chute extending 75mm radially from the motor axis.
  • Model a 16mm wide U-channel with smooth 3mm bottom corner fillets so the candy stays centered without wedging against sidewalls.
  • Add a large 12mm transition fillet at the top entry funnel to catch candies falling vertically from the inspector wheel.
Step 2

CAD: Model the 5-bucket radial cup plate

The collection cups sit in a semi-circular arc beneath the discharge tip of the slide (cup_plate.stl):

  • Create 5 cup receptacles spaced evenly across an 80° arc (20° angular separation between buckets).
  • Add a homing contact switch standoff adjacent to Bucket #1.
Step 3

Print & install the sorting subassembly

Slice the slide with 4 perimeters and 20% infill. Orient the slide tilted on its spine to maintain smooth internal sliding surfaces. Install the M3 brass insert and clamp the chute to the second stepper motor shaft.

Step 4

Wire the second motor and limit switch

Connect the second stepper to Port M2 on the Adafruit Motor HAT. Wire the sorting limit switch signal to GPIO18 (pin 12) and ground to pin 14.

Step 5

Code the calibrated angle table

Map each colour name to its physical step offset from the home switch:

from adafruit_motorkit import MotorKit
from adafruit_motor import stepper
import RPi.GPIO as GPIO
import time

SORT_SWITCH = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(SORT_SWITCH, GPIO.IN, pull_up_down=GPIO.PUD_UP)
kit = MotorKit(0x60)

# Calibrated step offsets from Home (Bucket 1)
BUCKET_STEPS = {
    "Red": 0,       # Bucket 1 (Home)
    "Orange": 18,   # Bucket 2 (+32.4°)
    "Yellow": 36,   # Bucket 3 (+64.8°)
    "Green": 54,    # Bucket 4 (+97.2°)
    "Purple": 72,   # Bucket 5 (+129.6°)
    "Unknown": 90   # Bucket 6 / Reject bin
}

current_bucket_pos = 0

def go_home_slide():
    global current_bucket_pos
    print("Homing sorting slide...")
    while GPIO.input(SORT_SWITCH) == GPIO.HIGH:
        kit.stepper2.onestep(direction=stepper.BACKWARD, style=stepper.SINGLE)
        time.sleep(0.008)
    for _ in range(8):
        kit.stepper2.onestep(direction=stepper.FORWARD, style=stepper.SINGLE)
        time.sleep(0.008)
    kit.stepper2.release()
    current_bucket_pos = 0
    print("Slide homed at Bucket 1 (Red).")

def route_candy(color_name):
    global current_bucket_pos
    target_steps = BUCKET_STEPS.get(color_name, BUCKET_STEPS["Unknown"])
    delta = target_steps - current_bucket_pos
    
    direction = stepper.FORWARD if delta > 0 else stepper.BACKWARD
    for _ in range(abs(delta)):
        kit.stepper2.onestep(direction=direction, style=stepper.SINGLE)
        time.sleep(0.006)
    
    current_bucket_pos = target_steps
    print(f"Slide routed to {color_name} (position {target_steps} steps).")
    kit.stepper2.release()
32° Slide Pitch (> friction angle) 1:Red 2:Org 3:Yel 4:Grn 5:Pur
Figure 9.1: Gravity slide inclination angle and 5-cup radial distribution arc.
Make it yours
  • Add a 6th "Reject / Mixed" bucket position to handle anomalous scans or cracked Skittles.
  • Try polishing the printed chute with 600-grit wet sandpaper to minimize friction and watch candy speed increase.

If it breaks Troubleshooting

Candy stalls mid-slideSlide surface has layer stair-stepping or dust accumulation. Increase slide angle to 35° or sand the inner chute smooth.
Slide overshoots destination bucketStep velocity is too fast causing motor momentum overshoot. Lower motor step delay from 0.006s to 0.010s.
This week's checkpointThe sorting slide homes reliably to Bucket 1 on startup. When given a colour name, it moves directly to the target bucket with zero lost steps and candy glides cleanly into the cup.
Next week: The feeder & agitator — hopper funnel mechanics, critical bridging angles, and singulation geometry.