Project Report - akkipant/IoT-Fall-2019 GitHub Wiki
Title: Trash Classifier
Abstract:
Waste management is critical to maintain proper hygiene in our surrounding. In many public places such as college cafeterias, movie theaters, bus/railway stations, etc., the trash is not properly categorized which causes the difficulty for garbage management. So, in this project, we aim to build a smart trash classifier to categorize trash. To implement this project, we train a deep-learning model to detect the type of trash. With Android Studio we build an android APP. Our users just need to take a picture of the waste and the APP then detects the type of waste and publishes it with the MQTT broker, NodeMCU then opens the organic or recycle trash bin lid according to the message it receives. So, our users can throw the trash to the right trash bin without thinking about the category of the trash. We also attached an ultrasonic sensor to detect if the trash bin is full. This project has two features. The first feature will distinguish between the type of garbage after scanning the object and the second feature will detect when the garbage bin is full and send an indication to the mobile app. Our smart trash bin makes the trash category easier and more convenient for our users. It will help us sort the waste into proper categories.
Introduction:
Recycling is important to prevent the elements like plastic from deteriorating the environment. Because waste management impacts the health and environment of our society. If waste is sorted into proper categories like 1. organic waste and 2. recyclable waste it will be easy to recycle recyclable materials and dispose of the organic waste to generate compost. We got this motivation after observing in the college cafeteria that the students throw the trash into bins without looking at the appropriate category. They throw all the waste items into a single bin. This is cumbersome for the garbage management system to sort the items after collecting the trash. Hence, a smart system will help people to dispose of the waste into proper bins. This will lead to proper recycling of waste and organic waste can be processed to create biofuels and compost. Our goal is to implement a smart trash detector to make the garbage management system more effective. Our object is to build a basic model which will first sort the trash into just two categories. Based on the type of trash it will detect its type and indicates the smart bin the lid to be opened for discarding the item. The second objective is to detect whether the bin is full or not and indicate the management system with a notification indicating the need to empty the bin if the bin is full.
Literature Review/Background Study:
Android Studio
Android Studio is the integrated development environment (IDE) for Google's Android operating system which provides drag and drop UI development. It is built on JetBrains' IntelliJ IDEA software and designed for Android application development. Language used is majorly Java. We used Android Studio to develop an Android APP for garbage classification. We studied how to develop the APP and design its UI. We also studied to communicate with MQTT protocol with the MQTT broker.
MQTT (Message Queuing Telemetry Transport)
We learned MQTT in ICP 6 of Module 1. With MQTT trash bin can communicate with mobile APP in an efficient, fast and reliable manner through publishing/subscribing message using the MQTT broker. Mobile APP detects the type of trash and the trash bin opens the organic or recycle trash bin lid according to the message it receives.
- MQTT stands for Message Queuing Telemetry Transport.
- It is an example of a publish/subscribe system (usually shortened to pub/sub system) which lets sensors publish updates that all delivered to client subscribed to that sensor.
- MQTT uses a topic model allowing publishers (e.g. sensors) to create topics and publish data to the topics equally,
- Subscribers subscribing to a topic will receive asynchronous notification of data posted to the topic.
- The MQTT protocol, apart from being asynchronous, is also lightweight and doesn’t have as high an overhead as HTTP; which for resource-constrained devices is often an important advantage.
NodeMCU
NodeMCU is an open-source microcontroller with an in-built ESP8266 Wi-Fi module. Arduino IDE supports NodeMCU for uploading the sketch to the hardware. It supports the IoT MQTT protocol and best for projects with less input/outputs. We require to operate 2 servos and interface an ultrasonic sensor to it. So, we decided to use NodeMCU in our project.
Methodology:
We divided our project into two parts. First, Deep learning for classifying the type of trash. Second, the hardware part, which will get activated after the type of bin is detected.
Trash Hardware
- We designed a trash box for demo purpose using a normal packaging box with two lids.
- We divided that box into 2 compartments for 1. organic and 2. Recyclable trash.
- We attached the servo motors for each lid and connected the servos to the NodeMCU controller. We connected two sticks to the servos in order to open the lid.
- We also connected an ultrasonic sensor to NodeMCU and attached it at the top of the trash bin.
Node MCU
- We did the hardware connections as per the circuit diagram to connect NodeMCU with the servos and ultrasonic sensor.
- Developed a sketch for NodeMCU for receiving messages from mobile APP through MQTT and activating the respective servo motor.
- Install and include the servo.h library for interfacing the servo motors, ESP8266WiFi.h for WiFi connectivity, PubSubClient.h for MQTT protocol.
- Declare the MQTT server. We have used Hive MQ broker "broker.mqttdashboard.com".
- Connect the WiFi using SSID and password using the Setup_WiFi function.
- Call the 'client.setServer' function. Port used is 1883. Call the 'client.setCallback' for listening and receiving the MQTT message.
- In the loop, check if the client is connected and call the reconnect function. In the 'reconnect' function once, the client is connected, subscribe to the MQTT topic. We have named our topic 'iot_project_trash/bin'. The NodeMCU will receive messages until it is subscribed to the topic.
- Then, we have used the digital pins to interface the ultrasonic sensor's pins, 'echo' and 'trigger'.
- The trigger Pin is on the HIGH state for 10 microseconds. It reads the echo Pin and returns the sound wave travel time in microseconds.
- Duration and Distance is calculated based on the time. If the distance is less than 20cm, it will indicate that the bin is full.
Android App and Deep-learning
- We used Google Colaboratory (Colab) to write a python code for deep-learning.
- We have used the Waste Classification dataset from Kaggle. Link is provided in the references.
- We used Keras MobileNet model and trained it to work on our dataset from Kaggle by freezing all the layers except the last 5 layers and adding a dense layer at the end.
- We then converted this modified Keras model into a compressed flat buffer with the TensorFlow Lite Converter (tflite) to make it work on android seamlessly.
- In Android Studio, we created the APP layout first and then deployed the tflite file into the device.
- After, running the prediction algorithm, the message is published to the MQTT broker (Hive MQ).
Circuit Diagram:
Results and Evaluation:
Project Video: Project_Video_Trash_Classifier
We initially were struggling with the integration of the mobile APP with the NodeMCU due to short of time. Later we studied the MQTT protocol transfer from APP to NodeMCU using the Hive MQ broker at backend. The MQTT publish from NodeMCU to the mobile APP is pending but the message is received by Hive MQ successfully when the trash bin is full and requires to be emptied.
Prediction Accuracy:
- Tomato: 94%
- Potato: 95%
- Gel bottle: 94.6%
- Chocolate wrapper: 74%
- Apple: 85%
- Insulation Tape: 99%
Project Review and Screens:
Future Work:
This project can be further developed to attach a camera on the trash bin and after scanning the garbage, it will automatically detect the type of trash and open the respective lid of the bin. This can be done using Raspberry Pi. Due to short of time, we did not complete this task. We will take this project ahead to build this feature in the future. Also, the 'bin full' message is sent by the NodeMCU to the MQTT broker, but we have to further add the feature in the mobile app to receive the message from the trash bin and send an E-mail to indicate bin is full.
Conclusion:
Our Trash Classifier project provides accurate results for the classification of trash into recyclable and organic. Around 90-95% prediction accuracy is obtained for organic trash and 80-95% accuracy is obtained for recyclable trash. This helps in automatically classifying the trash and helps eliminates the human error. The project after implementing the future scope with proper mechanical hardware can be used in colleges and public places.