Have you ever stood in front of the trash can and wondered "is this still PMD, residual waste or something else?'" You're not the only one. Proper sorting is important and you want to do it right. This is how we take care of the environment and the people who take care of our waste disposal. A small effort for a better world. But what if you could remove that doubt? What if we could teach an artificial intelligence to sort and so together build a smart trash can? You can! What's more, you don't need a PhD or an overgrown computer to do it. This can be done perfectly with laptop in the classroom!
Supplies
To build a smart trash can that can help us sort, we need a few things. You can run this project on almost any school laptop that has a webcam and runs on a Windows operating system. If necessary, it can be modified to run on Mac, for example, but this requires its own modifications and more extensive knowledge.
What do we need to build this smart trash can?
- A laptop that has a webcam;
- An Arduino Uno, breadboard and LEDs;
- The Arduino IDE software to program the board;
- A USB cable to connect the Arduino Uno to the laptop;
- A sloppy 5,000 photos of garbage to train an AI model.
5,000 pictures of garbage!? Don't worry, I'll help you out with this! But first, a word about how an AI model works and why we need those photos.
How can an AI recognize garbage?
If we want to build a smart trash can with artificial intelligence, we must first teach this AI to recognize and sort trash. This sounds very complicated, but it is very similar to how we teach children new words. If we want to teach children what a kitten, dog or cow is, we show pictures and tell them what the animal is called. We do the same with trash. We show a picture of a plastic bottle and say its name. We do this over and over again. Thousands of times even with our AI. Because that's artificial intelligence: autonomous systems that can imitate human behavior. Like you, an AI can learn!
Inside the computer, through algorithms, our AI model will look for patterns in the images. Typically, the more data and time we give the AI model, the better it becomes at its task. This is called "Machine Learning. As with human learning, there are different strategies to achieve learning. The strategy we use here, where we show the AI model thousands of prayer cards, specifying the name of the class (residual waste, plastic, paper ...), is called supervised learning. In this process, the model learns thanks to the images presorted by humans.
You can do this "machine learning" yourself through your computer. For that, you can use Google's Teachable Machine. You can provide it with collections of pictures that you label, and train it! Once trained, our AI model can do a useful trick: you can take a picture of its learned knowledge (= checkpoint) and download it to the computer. You can load that file into another computer, which the pre-trained model can use immediately. Imagine that a math exam is scheduled. The strongest student in the class studies this subject thoroughly and uploads his/her/their knowledge, then the rest of the class downloads it to their brains.
Voila, the "brains" of our smart garbage can are ready!
HTML - sorting via webcam
Now that we have trained our artificial intelligence, thus endowed our smart garbage can with "brains," it is time to work on the "eyes." To correctly recognize garbage, our AI must, of course, be able to see it. For that, we will use our laptop's webcam and browser.
For this project, you can use my standard HTML and Javascript files. If these computer languages no longer hold any secrets for you, you can modify them yourself to your heart's content.
Arduino - our sorting/traffic light
We have equipped our smart trash can with brains and eyes, but now it also needs to "do something" when it recognizes a certain type of trash. To do this, we are using an Arduino Uno. This is a small programmable computer board that we can very easily connect to a computer. You also have a breadboard on which we place about four LEDs. You can expand this later with servo motors to open/close a physical garbage can.
To program our Arduino, we need the Arduino IDE software. With this, we place a piece of code on our Arduino Uno. Through this piece of code, the Arduino will listen for incoming signals from our computer. Depending on the signal, it will turn on a specific color LED.
When our computer, through the webcam, recognizes a piece of garbage, it will send a signal. To send this signal, we use the computer's USB port and a piece of software that is the bridge between the recognition of our AI model and the Arduino.
Once all the pieces are in place, we can launch our smart garbage can. To do this, we'll use a few lines of Python in the computer's command prompt. Then when you use your web browser, you'll land on the web page that can use your webcam. As a test, hold a piece of garbage in front of it. Check the result on the screen and with the Arduino!
Voila, this is how you build a trash can with artificial intelligence in your classroom and contribute to a better world!