Smart Trash Can
Simulate a connected trash can in cloud to build a complete prototype for a citywide Smart Trash management application. View Source
Welcome to the Smart Trash Can project.
Waste management is one of the vital function of a smart city. Current mechanisms do not take into account the actual fill level from containers, and instead schedule collection on predefined intervals. Since the generation of trash is dynamic in nature, it often results in some trash cans getting overloaded and leaking while other remain almost empty. An overflowing trash can be not only aesthetically unpleasant, it could also be a health hazard for communities, especially in warm environments. Did you ever find yourself wanting to adjust garbage into an overflowing trash can because the neighbor had a big party last night? Or you could not bear the nauseating smell of the trash decomposing in front of your house because the summer is unusually hot and the waste collection only happens once in 3 days? The smart trash can project is your solution!
Last, but not least, the traffic congestion due to slow moving vehicles like trash pickup truck is really annoying. Wouldn’t it be nice if the vehicles know in advance which trash can should be picked and which could be skipped? You could build one right away. Let’s get started.
- Basics of measuring empty distance through reflection of ultrsonic wave
- Interaction with hardware such as reading digital input and output.
- Interfacing with IBM bluemix, one of the leading IoT cloud platform.
The project consists of an emulated Raspberry Pi connected to digital input/output and a ultrasonic sensor.
The measurement of Trash can fill level could be done by multiple means such as measuring the distance between the lid and trash content level. Another possible measurement could be measuring the weight of the trash can via a load cell (weight sensor). However due to the fact that trash contents could vary in nature (such as solid waste vs plastic or paper) measuring weight could not guarantee an accurate fill level. Therefore measuring empty space remains most practical way to measure the fill contents. It also simplifies the design because all the circuitry could be contained at one place, i.e. the top of trash can.
As an embedded system, we will use an emulated Raspberry Pi platform (based upon Raspberry Pi® 2 Model B+). To measure the trash fill level we will use the most popular HCSR04 Ultrasonic distance sensor. The user guide documentation of this sensor, including functioning information, can be found here. This sensor requires two connections to the Raspberry Pi GPIO. One GPIO connection for the trigger and another GPIO connection for the echo.
The trigger can be considered a simple pulse that turns the sensor on, each time a distance is going to be measured. It should last 10 micro seconds. The echo is the output signal. The length of the signal is proportional to the distance measured, and is hence used to measure the actual distance. In our application, trigger is connected to the pin 5 (GPIO) and echo is connected to pin 6 (GPIO). Knowing that, the distance can be calculated by:
2 x Distance = (Echo Duration) * (Ultrasonic Velocity)
Note that there is a 2 x factor in the equation. This is because the formula is used to measure the total distance traveled by the ultrasonic waves, hence it accounts for both directions of travel.
Knowing that the ultrasonic velocity is of X m/s, the Distance can be calculated as:
Distance = (Echo Duration) * 17150
To get started with Smart Trash Can powered by IBM Bluemix, please follow our step by step guide.
Towards the goal of building a smarter planet, we present to you a prototype of an IoT-enabled trash can. This use case is one of the many ones, around IoT, which empowers the things to talk to us, instead of we checking on them.
Note: This project requires a functional account with IoTIFY. If you don’t have an account yet, please sign up here.
A trash can is one of those ubiquitous things, which hardly gets any attention until it is full and the trash seems to spill out of it. So the most obvious way to make it smart would be to detect if it is getting full and then send a notification to the personnel responsible for clearing it.
In this guide, we present to you the IOTIFY’s Trashcan Simulator, which can be used to build a smart trash can monitoring system such that the user gets notified about the trash can’s garbage level in real-time via a mobile app.
The best way to detect the level of filled trash in a trash can is by using an ultrasonic sensor attached to the lid as shown below.
The ultrasonic sensor mounted on the lid will face downwards and send trigger waves towards the bottom of the trash can. In case the can is filled up to a certain level, the waves will bounce back as echo which will be captured back by the sensor. Sensing the time difference between the sending of trigger signal and reception of echo signal provides a reasonable measure of the level of the trash can.
To build this project, we need the following components.
- IBM Bluemix IOT Service: IBM offers it’s inhouse IoT messaging service based on MQTT protocol. It is available as part of the IBM Bluemix catalog. You will need to signup for IBM Bluemix trial account to use it.
- IOTIFY Smart TrashCan Simulator: This is the complete hardware emulation of a trash can, available under IOTIFY. You will need to signup for IOTIFY subscription to access this.
- Android Mobile (Optional): In order to monitor this virtual trash can via mobile, we will need an Android mobile phone.
The reference architecture of the entire system is shown below.
As for the software, we have the following components in this project
- TrashCan Python Script: This is a Python application which runs on the IOTIFY Smart TrashCan Simulator. It monitors the level of trash can every few seconds and publishes the readings to IBM IOT service.We will write this python script which will act as the application program running on this setup for demonstrating the working of smart trash can.
- Cordova Android Mobile App: This is a Cordova-based Android mobile app which is used to monitor the trash can remotely. We will build this app and showcase how to use it in conjunction with IOTIFY Smart Trashcan simulator.
Note: This application also uses Twilio messaging service for sending SMS notifications to the user’s mobile in case the trash can reaches critical level. Refer Twilio documentation for setting up a Twilio trial subscription.
So let’s dive in and build this application.
Follow this guide to configure IBM Bluemix platform for this use case.
At the end of the configuration, you will have following configuration values from IBM and Twilio (Optional)
|organization||182||IBM account organization ID|
|authKey||189||Generated API key|
|authToken||190||Generated Authentication token|
Optional Twilio configuration
|account_sid||23||Twilio account SID|
|auth_token||24||Twilio account authToken|
|twilionumber||28||Twilio Number ( Your Twilio subscribed number)|
|receivernumber||29||Twilio verified number (where you want to receive the SMS notifications). Should have country code, for example +18458892405|
Signup with iotify.io if you haven’t yet. The free account will have sufficient credits to run this project. Once you are logged into the IoTIFY main application, go to the virtual lab and click on the Smart Trash project.
Provide a unique name for your project. Then simply click launch.
The project takes 3-5 minutes to launch. The project state will automatically change to running once it is ready. You could then simply click the Open button and it will launch a new window with the Workspace of the project.
The webview has a simulated trash can with a knob to control temperature and adjustable fill level of the can. All of these internally connected to an emulated raspberry pi 2, so that you can interact with the corresponding peripheral from the terminal by the programming.
Open the project workspace and you will be greeted with a gigantic green trash can fitted with an ultrasonic sensor.
Note: You can also see a side note on the right of trash can about the connections to the Raspberry Pi’s GPIO ports. This will help you understand how the trash can events are detected by the hardware.
Open the console by clicking on the small console icon on the top left corner above the directory listing.
Note: The console may appear to be unresponsive initially, if you try to type some command. Wait for a minute till it is fully loaded and then you can start using it.
Now we are ready to install the python script which is the trash can’s software application that runs on this simulation setup. But before that we have to install the following dependencies for it.
- ibmiotf: IBM IoT python SDK available under the IBM IoT Foundation documentation page
- twilio : Twilio python sdk for integrating text messaging
We can install the above two dependencies through the python’s installer ‘pip’ as follows
The project also has a simulated 1 wire temperature sensor based upon DS18B20.
In order to load the kernel module for this, please issue following commands at console
If we have reached this far then, it is now time for some action. We are finally ready to run our application.
But there is one last step to be performed, which is to configure the python script so that it registers with IBM IoT platform service using the appropriate device id & authentication token that we created earlier.
But first, lets clone the GitHub repository of this project in the project workspace so that we have access to the python script.
The repository contains all the project sources including the mobile app as well as the other files. For the smart trash can simulator we are only interested in file ‘Trashcan.py’
Open the file by double clicking it on the side left explorer. This will open a editor in the workspace.
Refer the python script configuration section under README file for the steps to configure the python script. These configurations are related to IBM IoT platform and Twilio. You will also need a trial account of Twilio for this.
Once the configurations are in place, save the file and run the script
WARNING : Running the python script without these configuration settings will lead to unexpected behaviour or termination of the program.
For building the mobile app, you will have to clone the repository again on a build system, which is ideally a Ubuntu/Linux OS based computer which has the Android build dependencies already installed. The dependencies are
- Cordova SDK
- Android Studio
FINALLY!! , we are all set. Make sure that the python script is running under IOTIFY workspace and the IBM IoTF service is also up. Launch the app and you are now live tracking your trash can.
You can also see the live ultrasonic sensor readings on IBM IOT Service dashboard by clicking on TRASHCANAPP_001 device under the “DEVICES” sub-menu.
We are looking forward to hearing your comments and thoughts at our forum below