The Self-sorting Bin
This is the Self-sorting bin project - a machine that tells you how to sort your trash! Simply show a piece of trash to the device and it will tell you where to throw it.
The self-sorting bin project is a proof of concept to show how waste sorting can be made more convenient and appealing. Its purpose is to contribute to increased recycling and decreased pollution.
The device consists of a Raspberry Pi, a camera, an LCD display, an RGB light and an ultrasonic sensor. It hosts a YOLO26n object detection model that has been trained to recognize different kinds of trash.
The source code is available on GitHub.
Supplies
- Raspberry Pi 5 (135 euro)
- USB camera (40 euro)
- RGB LED light (6 euro)
- Ultrasonic sensor (6 euro)
- LCD Display (9 euro)
- Jumper wires (7 euro)
- 6mm thick MDF wood (17 euro)
Total cost ~220 euro
See bill of materials for links to components and more details.
Downloads
Collecting Data
The first thing that was done was collecting data. A total of 2303 images were taken of different kinds of trash with different backgrounds and in different lighting conditions.
The data was divided into six classes and annotated manually using bounding boxes in Roboflow.
The classes were:
- Cardboard / paper
- Glass jars
- Plastic bottles
- Plastic packaging
- Metal cans
- Organic
The training/validation/test split was 70/15/15.
Settings for preprocessing were applied to the images and the training set was enhanced with augmented copies.
Preprocessing:
Auto-Orient: Applied
Resize: Fit (black edges) in 640x640
Augmentations:
Outputs per training example: 3
Flip: Horizontal, Vertical
Rotation: Between -15° and +15°
Saturation: Between -34% and +34%
Brightness: Between -23% and +23%
Exposure: Between -13% and +13%
Note: The split percentages changes after augmentations (new copies of images) are applied.
Training the Model
YOLO26n from Ultralytics was the object detection model of choice because its lightweight and runs well on a Raspberry Pi.
The training was done locally on a laptop with an RTX 3070 Laptop GPU. The following settings were used:
epochs=300, imgsz=640, verbose=True, batch=8
Connecting Components
The RGB light, LCD display, and the ultrasonic sensor were connected directly to the pins on the Raspberry Pi.
RGB light:
- R -> pin 29 (GPIO 5)
- G -> pin 31 (GPIO 6)
- B -> pin 33 (GPIO 13)
- GND -> pin 9
LCD Display:
- 5v -> pin 2
- SDA -> pin 3
- SCL -> pin 5
- GND -> pin 14
Ultrasonic sensor:
- 5v -> pin 4
- TXD -> pin 8
- RXD -> pin 10
- GND -> pin 6
The Backend
The backend was created using FastAPI and Postgres, and it was deployed on the Raspberry Pi using Docker.
The API was made with full CRUD functionality, though not all endpoints were utilized in the final prototype.
The database was structured as follows (underline = primary key, * = foreign key):
CLASS (classID, name, description)
SESSION (sessionID, timeFrom, timeTo)
DETECTION (detectID, classID*, confidence, timestamp)
LOG (logID, type, log, timestamp)
PS. if you clone the repository, all you have to do is to install Docker Engine and Docker Compose, and run docker compose up --build in the RPi/api folder.
Python & Startup
The main logic was entirely written in python. Classes were created for each hardware component and a Graphical User Interface was created using Gradio.
If you clone the repository, all you have to do is to install myproject.service on your Raspberry Pi and enable it on boot to automatically start the main program at startup.
You can do this with the following commands:
Install and test:
Enable on boot:
Housing
The housing was laser cut out of 6mm thick MDF wood. The SVG files (for the laser cutter) were created using Boxes.py and Inkscape. Two boxes were created, one main box and one tall, standing box where the camera was mounted. The standing box had its bottom attached to the main box with two screws.
The Raspberry Pi was mounted to the inside of the main box using screws and glue. Holes were cut out for the RGB light, LCD display and the ultrasonic sensor, which were taped to the inside of the box to stay in place.
Note: It's of course possible to glue the components to the box but since I had to return them to the university, I decided to use tape instead.