# Smart Waste Classification System (SWCS)

> An offline, edge-AI closed-loop waste sorter for small venues: YOLOv8 finds the object, MobileNetV3 classifies the material, a confidence gate decides, and dual Arduinos drive the servo that physically routes it.

- Author: Li Yanpei (Lucian)
- Type: Case study
- Language: English (en)
- Reading time: 2 min
- Role: Solo final-year ECE capstone — design, model training, firmware, mechanics
- Timeline: 2025 – 2026
- Stack: Edge AI, Computer Vision, Jetson, YOLO, Robotics
- Canonical: <https://lucian-dev.com/work/swcs>

---

## Overview

**SWCS** is a compact, **offline-capable** recycling station for small venues — cafés, office pantries, labs, school micro-recycling points — where there's no staff to watch the bin and no network to rely on. It closes the full loop from _sensing → recognition → decision → physical sorting_, not just classification on a screen.

It was my final-year project for **ELEC S411F (Electronic & Computer Engineering Project, 2025/26)**, supervised by Dr. Tong Kwong Bun Bruce.

[Demo](https://www.youtube.com/watch?v=jkAqK3vqILI)

## The problem

Recycling quality collapses when materials are contaminated at the source. Most academic work stops at lab accuracy, and most commercial "smart bins" are large, expensive, network-dependent installations for big facilities. There's a real gap for something **small, cheap, robust and offline** that can actually _act_ on its decision — and safely refuse to act when it isn't sure.

## Approach

A two-stage edge-vision pipeline plus a confidence-gated controller:

- **Localize** — YOLOv8 detects the item and crops the region of interest (ROI).
- **Classify** — MobileNetV3-Large labels the ROI as paper / plastic / metal / glass / cardboard. Chosen for edge latency (not just accuracy) and deployable via ONNX / TorchScript / TensorRT / CUDA.
- **Decide** — a Decision Engine fuses the model probabilities and applies a **confidence gate**: divert only if the class _and_ its confidence clear a threshold; otherwise the item stays on the default bypass route. Low-confidence cases never trigger a wrong physical action.

## System architecture

- **Upper machine:** NVIDIA Jetson Orin Nano runs camera capture, YOLO localization, ROI cropping, classification and the Decision Engine.
- **Lower machines:** two Arduinos — `belt_arduino` (IR trigger + conveyor) and `servo_arduino` (sorting flap) — for clean separation of control.
- **Protocol:** USB-serial **JSON** with an identity handshake between the Jetson and each Arduino.
- **Closed loop (FSM):** IR sensor detects an item → stop belt → capture frames → YOLO + MobileNetV3 + confidence gate → JSON command → servo flap rotates → belt resumes → cycle logged with image, prediction, confidence, action and timing.

Training used PyTorch + PyTorch Lightning (OmegaConf config, torchvision ImageFolder) on a self-collected dataset that ranged from clean backgrounds to cluttered, real-world, varied-lighting scenes to harden against contamination and occlusion.

## Results

A labelled 120-cycle closed-loop experiment (60 metal + 60 non-metal), using metal routing as the physical test case:

- **Offline classifier accuracy:** 93.59% — metal 93.69% precision / 95.59% recall / 94.63% F1
- **System routing accuracy (2-class):** 90.8% — metal precision 94.5%, recall 86.7%
- **False diversion:** 5.0% · **Missed diversion:** 13.3%
- **Mean end-to-end cycle:** 3.29 s — of which recognition was only **\~61 ms**

## What I learned

- **The AI was never the bottleneck.** Recognition took \~61 ms; the full cycle \~3.29 s, dominated by servo actuation (\~2.7 s) and conveyor recovery. The hard engineering was mechanical timing, not inference.
- **Closed-loop accuracy depends on the actuator, not just the model.** A high-torque servo caused PWM jitter and unstable flap angles — a _correct_ classification could still mis-sort. An independent 5 V supply with a common ground to the Arduino removed the jitter entirely.
- **Confidence gating is a trade-off.** It kept false diversion low (5%) but raised missed metal diversions (13.3%) — a knob to tune against labelled system-level data, not just offline validation.

## Further work

Multi-path routing for all five materials (not only the metal test path), latency reduction in the mechanical chain, and long-duration reliability testing — camera drift, serial stability, belt misalignment, servo wear.
