All projects

Project 07

Bagasort

A low-cost machine that singulates oranges, inspects each one with two cameras and an on-device neural network, and sorts it into healthy, unhealthy or inconclusive bins.

Status
Completed
Role
Team of four for the Integration Workshop 3 course in Computer Engineering. I was the main developer of all the software: Python core, ESP32 firmware, ML pipeline and dashboard.
Period
Mar to Jun 2026
Source
Public repository
Simplified flow
  1. Thrower + LDR
  2. Two cameras
  3. Raspberry Pi (TFLite)
  4. ESP32 + servo
  5. 3 bins

Sorting fruit by quality by hand is slow and inconsistent. The goal was a machine built on a student budget that could do it on its own, with fruit in motion, glare and motion blur instead of clean studio photos.

A ramp and a stepper-driven thrower line the oranges up one at a time. Laser tripwires detect each fruit, a second stepper turns it in front of two USB cameras, and a Raspberry Pi 4 runs a MobileNetV3 model (TFLite, FP32 with XNNPACK) on the sharpest frames. The Python core pools the scores over a short time window, decides, and tells an ESP32 over UART to set the sorting servo. Every decision is stored in SQLite with evidence images and shown in a React dashboard.

  • 80% accuracy in the final test of 90 oranges (6 runs of 15). Healthy and unhealthy mix-ups counted as errors; inconclusive did not.
  • About 7 s per orange, roughly 500 per hour, on a final budget of R$ 1,186.
  • A model trained only on public datasets failed on the real rig, with recall falling to about 12%. A rig dataset of 555 images, labeled with our own review tool, plus a threshold calibrated on real events fixed it.
  • Seven-state machine with handshake, calibration, jam detection and a failsafe state, mirrored by a failsafe state in the firmware and a keepalive watchdog.
  • Per-frame quality gates for blur, brightness and orange presence, one capture thread per camera and a single inference worker that discards stale results.
  • Custom line-based UART protocol between the Pi and the ESP32, with modular C++ drivers for the steppers, the servo, the LDR tripwires and the LED status strip.
  • About 370 tests across unit, integration and hardware-in-the-loop suites, plus written postmortems for the incidents found during integration.