Classify your trash with Raspberry Pi

Maker Jen Fox took to hackster.io to share a Raspberry Pi–powered trash classifier that tells you whether the trash in your hand is recyclable, compostable, or just straight-up garbage.

Jen reckons this project is beginner-friendly, as you don’t need any code to train the machine learning model, just a little to load it on Raspberry Pi. It’s also a pretty affordable build, costing less than $70 including a Raspberry Pi 4.

“Haz waste”?!

Hardware:

  • Raspberry Pi 4 Model B
  • Raspberry Pi Camera Module
  • Adafruit push button
  • Adafruit LEDs
Watch Jen giving a demo of her creation

Software

The code-free machine learning model is created using Lobe, a desktop tool that automatically trains a custom image classifier based on what objects you’ve shown it.

The image classifier correctly guessing it has been shown a bottle cap

Training the image classifier

Basically, you upload a tonne of photos and tell Lobe what object each of them shows. Jen told the empty classification model which photos were of compostable waste, which were of recyclable and items, and which were of garbage or bio-hazardous waste. Of course, as Jen says, “the more photos you have, the more accurate your model is.”

Loading up Raspberry Pi

Birds eye view of Raspberry Pi 4 with a camera module connected
The Raspberry Pi Camera Module attached to Raspberry Pi 4

As promised, you only need a little bit of code to load the image classifier onto your Raspberry Pi. The Raspberry Pi Camera Module acts as the image classifier’s “eyes” so Raspberry Pi can find out what kind of trash you hold up for it.

The push button and LEDs are wired up to the Raspberry Pi GPIO pins, and they work together with the camera and light up according to what the image classifier “sees”.

Here’s the fritzing diagram showing how to wire the push button and LEDS to the Raspberry Pi GPIO pins

You’ll want to create a snazzy case so your trash classifier looks good mounted on the wall. Kate cut holes in a cardboard box to make sure that the camera could “see” out, the user can see the LEDs, and the push button is accessible. Remember to leave room for Raspberry Pi’s power supply to plug in.

Jen’s hand-painted case mounted to the wall, having a look at a plastic bag

Jen has tonnes of other projects on her Hackster profile — check out the micro:bit Magic Wand.

14 comments

Emma Ormond avatar

This is great, I might have to build one so I can stop being the person who answers the is it recyclable question all the time. Then i might make one for my mum :)

Jen Fox avatar

Thanks so much, Emma! I’d be so stoked if you built your own!! Please feel free to reach out if you have any questions along the way :)

Ravichandran JV avatar

This is amazing because only a few days ago I was mentioning this idea of a PI driven drone that could scan garbage dumps for viruses/bacteria ?… Very ambitious idea but it could be a very useful community service… would a camera be able to distinguish atomic particles in tons of garbage is the more pertinent question and to match it with an image classifier!! And of course would a drone be able to carry the weight of the pi would be another!

The great thing about your initiative is it gives hope for bigger things! ?

Thank you, Jen, for the share?

Alessio avatar

Thanks Jen for sharing. I think this is more than just a hobby project as it could be the base for a trash sorter which could automate the daunting task of having to pick the right bin for a particular item.

Jen Fox avatar

Thanks so much! Glad to hear you enjoyed the project :) I’d love to see someone build a trash sorter or a commercial product out of this idea!! Definitely would be a great thing to have!

Mikael Bonnier avatar

In Sweden we have other categories for waste sorting e.g. metal packages, plastic packages, glass packages (colored and non-colored in different bins), carton packages, paper, food waste, batteries, bulbs (different bins for bulbs with mercury, tungsten, or LEDs), electronics, the non-hazardous rest. Non-package or non-food waste and hazardous packages should be left at stations, but also sorted there. Thus, this project is not immediately useful here now.

Tony avatar

Similar here in Switzerland, but I believe the system could be trained to recognise all those types of material.

Jen Fox avatar

Thanks for the comment! Wanted to reiterate what Tony said: the ML model I made is specific to Seattle’s municipal garbage collection, but you can build a model for your region! In fact, that’s exactly what I recommend :) Lobe is a free, no-code way to build custom ML models: https://lobe.ai
Once you build your model, export via TF Lite and follow the tutorial instructions as-is. The more categories, the more photos you’ll need, so I’d suggest family-or-friend-sourcing photos (getting them to help take pics) or using Kaggle for open-source datasets.
Hope that helps!

Spectre avatar

it has greater implications than that. In my town, as in many others, a lot of recycling ends up in the landfill. driving down the costs associated with sorting, done magnetically and manually now, would be great.

Jen Fox avatar

Absolutely agree! Hoping this project makes trash classification easier and more accessible for lots more folks!

ameyring avatar

I’ve heard that plastics in some places in the US are sorted with the help of light sensors. They can miss black containers since they absorb light. You have a great project here and a visit to a recycling center can give you ideas to optimize it.

Jen Fox avatar

Thanks so much! That is definitely a great idea, My goal w/ this project is to show folks what’s possible and to use as a starting point — I really hope someone takes it and makes it better! *wink wink*

Yadwinder avatar

Have any idea when pi400 coming with 8gb RAM?

Leonor Louro avatar

Thank you so much for sharing this idea! I am currently trying to make it as a project for school and seem to have run into a problem running the code in the Raspberry Pi terminal. When I try to run the code the error ‘Segmentation fault’ appears.
Is there any way you would be able to help solve this issue?

Comments are closed