Back to projects

Project

Optical coffee bean sorting with robotic arm

Project Summary

Senior design prototype for detecting rocks in coffee beans using Raspberry Pi vision, Random Forest classification, mechanical sorting, load-cell feedback, and robotic delivery.

Status
Senior design prototype
Role
Computer vision + ML + camera pipeline
Team
Brian Huang, Tae Kang, Young Lai
Stack
Python, OpenCV, scikit-learn, NumPy, Raspberry Pi
Code
github.com/taekang1117/pourover

Interactive Sorting Visualization

The animation below shows the sorting problem, the gap between industrial and manual inspection, and the prototype workflow that uses camera-based classification to drive a physical sorting gate.

I. Overview

The project targets a practical quality-control problem for small cafes and roasters: rocks or foreign objects mixed with beans can damage grinders, but manual sorting is slow and inconsistent. The prototype automates that final inspection step by combining vision, classification, mechanical routing, weighing, and robotic delivery in one system.

II. Problem and Objective

The system is designed to detect and remove rocks from coffee beans before packaging or grinding. A Raspberry Pi camera captures each object, the computer vision pipeline extracts features, and the machine learning model classifies each object as an accepted bean or rejected debris.

The goal was not only to train a classifier, but to connect that classifier to physical actuation. The prediction drives a motorized flipper, while load-cell feedback tracks accepted bean weight and triggers the robotic arm delivery sequence when the target batch is ready.

III. System Architecture

The hardware workflow begins with a slow feeder that meters unsorted beans and rocks so objects enter the camera region in a controlled sequence. The Pi captures the region of interest, isolates contours, extracts geometric, color, texture, and Hu-moment features, then classifies each object as bean or rock.

The classifier result drives a motorized flipper that sends accepted beans toward the bean path and rejected objects toward the rock bin. A load cell tracks accumulated accepted weight; once the target is reached, the system stops feeding and triggers a robotic arm delivery sequence.

IV. Computer Vision and Machine Learning

I primarily worked on the computer vision and machine learning subsystem, including the Raspberry Pi camera workflow, data sampling process, feature extraction, classifier testing, and the decision logic that connects perception output to the rest of the sorting pipeline.

The vision stack used a Raspberry Pi Camera V2, OpenCV preprocessing, 16-feature extraction, and Random Forest classification. The full system also depended on Raspberry Pi GPIO, stepper-driven feeder and flipper control, Arduino serial communication, and load-cell feedback.

V. Results and Testing

The standalone classifier reached 86% accuracy. The complete prototype reached 70.7% end-to-end sorting accuracy across 300 mixed objects, with 72.4% bean retention and 62.0% rock rejection.

70.7% Overall Accuracy 212/300
72.4% Bean Accuracy avg 36.2/50
62% Rock Rejection avg 6.2/10
300 Objects Tested 50 beans + 10 rocks x 5 trials
Trial Beans to Basket Rocks to Reject Bean Acc. Rock Acc.
Trial 1 39/50 5/10 78% 50%
Trial 2 35/50 6/10 70% 60%
Trial 3 37/50 8/10 74% 80%
Trial 4 35/50 5/10 70% 50%
Trial 5 37/50 7/10 74% 70%
Avg 36.2/50 6.2/10 72.4% 62%

The standalone vision model performed better than the complete machine. Most full-system losses came from feeder and flipper mechanics rather than only the classifier.

VI. Technical Challenges

The hardest lesson was that a decent classifier is not enough. The vision model reached 100% rock precision when it predicted a rock, but rock recall was 73%, meaning some rocks still looked too similar to beans under the available lighting, orientation, and sample-size constraints.

The full system also lost accuracy when objects landed near the flipper edge or when tray-level actuation sent nearby beans to the reject side along with a rock.

VII. What This Project Demonstrates

This project shows embedded AI as a full physical system rather than a notebook result. It required Linux/Raspberry Pi setup, camera calibration, OpenCV preprocessing, model training, hardware control, serial communication, weighing feedback, and debugging across software and mechanics.

It also shaped how I evaluate ML systems: the real question is not only whether the model is accurate, but whether the whole pipeline is reliable.