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.

What you’ll learn

The project consists of an emulated Raspberry Pi connected to digital input/output and a ultrasonic sensor.

Basic Concept

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.

IBM Bluemix powered Smart Trashcan

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.

Underlying concept

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.

Project Components

To build this project, we need the following components.

The reference architecture of the entire system is shown below.

Software Components

As for the software, we have the following components in this project

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.

The complete source code for this application is available in GitHub in this repository.
Refer the README file for steps to configure and build the software components of this application.

So let’s dive in and build this application.

1. IBM Bluemix account setup

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)

Variable Line # Description
organization 182 IBM account organization ID
authKey 189 Generated API key
authToken 190 Generated Authentication token

Optional Twilio configuration

Variable Line # Description
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

2. IOTIFY Smart TrashCan Project

Signup with 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.

Setting up project dependencies

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.

Step 3: Install the dependencies for the trash can python script

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.

We can install the above two dependencies through the python’s installer ‘pip’ as follows

sudo pip install ibmiotf

sudo pip install twilio

Step 4: (Optional) Load 1 wire temperature sensor kernel module

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

sudo modprobe w1-gpio
sudo modprobe w1-therm
cd /sys/bus/w1/devices

3. Configure and run

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.

git clone

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 ‘’

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.

Configure and build the mobile app

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

Refer the mobile app configuration section under README, for the steps to configure the javascript source file for the mobile app. These configurations are related to IBM IoT platform. Once configured, follow the steps in Mobile App Build section to build the app.

Run the Project

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.

That’s all folks

We are looking forward to hearing your comments and thoughts at our forum below