Intro: IDC2018IOT GarbageCan-Online
Everybody knows what happens when we leave the trash in the garbage can for too long without removing it. Well, the most obvious thing is that there is no room for more trash, but it also starts to stink, and it gets very unpleasant.
With this project, we aim to help you monitor your garbage cans around the house\workspace\etc, so you can always know when they are full, and can take immediate action by taking the trash out.
The system will alert you by phone notification or dashboard alert that you have to empty the garbage can. The system takes into account the fullness level of the garbage can, but also the temperature and humidity measured inside it. We are all familiar with the urgency of emptying the garbage cans in hot and humid days...
- Monitoring Dashboard:
- Main Section:
- Fullness level of each garbage can.
- Temperature and humidity of each garbage can.
- Main Section:
- Statistics Section:
- Fullest garbage can.
- Hottest garbage can.
- Alerts & Notifications System:
- The following events are supported:
- Garbage can is Full.
- A sensor error occurred.
- The following events are supported:
- Fullness alerts take into account the fullness level of the garbage can, but also the temperature and humidity levels of the garbage can.
- Alerts can be sent via phone notifications and dashboard alerts.
- Each alert channel can be turned on and off via the dashboard.
- Using the calibration button, it is possible to adjust the system to different garbage cans with varying capacities.
- It is possible to add more garbage cans relatively easily. One can assemble the same system on a new garbage can, set the garbage can ID and calibrate it (push of a button). Having more than 3 garbage cans will require extending the Dashboard (easy task to perform).
Who are we?
This project was created (with love and dedication!) by Rom Cyncynatus and Daniel Alima - Students of the IDC Herzliya as a final project for our IoT course. We hope you will find our work useful, and enjoy using it!
Step 1: Required Parts
In order to build the system, you will have the acquire the following components and parts:
- Garbage can(preferably with a lid): This will be used for... well.. you know what we are going to do with this one, eh? ;)
- Breadboard: To connect all of the different components without using any soldering.
- NodeMCU (ESP-8266): In charge of reading the sensors and sending the information to the cloud.
- Distance IR Sensor - Sharp 0A41SK: This sensor will measure the amount of garbage (Fullness level) inside the can.
- Temperature & Humidity Sensor - DHT11: This sensor will measure the temperature and humidity inside the garbage can.
- Momentary Switch: Will be used to calibrate the distance sensor according to the size of the garbage can.
- Aluminum Foil: Will be used to form a detector for the lid status - whether it is opened or closed.
- Jumper wires: Get plenty, and at different lengths and colors. Will connect everything together.
- Duct Tape: We will have to attach things into place.
- Micro-USB Cable: To connect the NodeMCU to your computer for programming, and later on for a power supply.
- USB Power Supply (smartphone charger): Will provide power to the NodeMCU when installed on the garbage can.
Step 2: Wiring & Assembling
Place the NodeMCU on the breadboard so that it will be convenient to attach it later to your garbage can, and connect the USB cable to it. Then, consult the wiring diagram picture above to connect the different components to the NodeMCU. Make sure to use long wires for the sensors and status wires so it will be convenient to install the system and to use the garbage can with it.
- Distance IR Sensor - Sharp 0A41SK:
- Vin (Red) --> Vin
- GND (Black) --> GND
- Vout (Yellow) --> A0
- Vin (Red) --> 3V3
- GND (Black) --> GND
- DATA (Yellow) --> D4
- Pin1 --> D3
- Pin2 --> GND
- Wire1 --> D2
- Wire2 --> GND
Assembling the system on the garbage can is quite simple. Attach the Breadboard to the garbage can, preferably close to the lid. Use either tape or cable tie to secure it into place. Then:
- Place the IR distance sensor in the middle of the lid (from the inner side!). Make sure to secure it properly, or you will encounter false readings!
- Place the temperature & humidity sensor somewhere inside the garbage can. Secure with tape.
- Cover the side of the lid and the tip of the garbage can with aluminum foil. Make sure there is good contact when the lid is closed. This will signal the system that the garbage can is opened or closed. Then stick each of the lid status wires in one of the aluminum foil, and secure with tape.
Step 3: Setup MQTT, Node-RED and IFTTT
Most of the project logic is actually implemented in the cloud. The NodeMCU sends the data to the MQTT server, and Node-RED consumes it and applies its logic on it (more about the architecture further ahead). Lastly, in order to transmit push notifications (alerts) to our smartphone, we used IFTTT.
We will use the CloudMQTT and FRED cloud services as our MQTT and Node-RED servers respectively, and we will use IFTTT for push notifications.
- Signup to CloudMQTT with the free plan. Note your credentials to the MQTT server (username and password).
- Signup to IFTTT. Create a new applet of "Webhooks --> IFTTT app notification". Use "Mobile Phone Notification" as the WebHookds event name. Consult the image above for the nitty gritty details. Note your maker API key.
- Download the IFTTT app to your phone and sign in with your credentials. This will allow you to get push notifications.
- Signup to FRED with the free plan.
- Once you have the FRED instance up and running, import the attached flows into it (3 Bars button --> Import --> From clipboard). Just paste the contents of each file (widgest.json, alerts.json, statistics.json) and import it.
- Edit one of the MQTT nodes (one is enough) to update your CloudMQTT credentials.
- Edit the IFTTT node to update your IFTTT maker API key.
Step 4: Program the NodeMCU and Garbage Can Capacity Calibration
Once we have everything wired up, we need to program the NodeMCU with the appropriate software (sketch) so that it will actually utilize all the stuff that is connected to it, and communicate with the internet.
- Download and install the Arduino IDE from here.
- Install and set the NodeMCU board type as explained in the beginning of the following instructable.
- Install the following libraries (Sketch --> Include Library --> Manage Libraries...):
- Adafruit MQTT Library (by Adafruit)
- DHT sensor library (By Adafruit)
- SharpIR (by Giuseppe Masino)
- EEPROMAnything - explanation here.
- Your WiFi credentials (WLAN_SSID, WLAN_PASS)
Your CloudMQTT credentials (MQTT_USERNAME, MQTT_PASSWORD)
If this is a second garbage can or more, change the garbage can ID (GARBAGECAN_ID)
Step 5: Using the System
If you've reached this far, everything should be up and running. Let us do a quick overview of the different usage aspects of the system.
We assume you have only a single garbage can connected, but it is easy to add up more later on!
First, notice the main dashboard. You should be in the home screen, seeing the garbage can fullness, temperature and humidity levels. You can control phone notifications and Dashboard alerts using the switches on the left.
When the garbage amount inside the garbage can changes, you will see the gauge changes accordingly. This is also the case for the temperature and humidity graphs.
When fullness level reaches 85%-90% (exact threshold depends on the temperature and humidity), or a sensor error occurred, you will get a notification via your preferred method(s). You will get notified once every hour per garbage can.
In the Statistics view, you will be able to see the currently fullest garbage can, and the hottest one. Unflattering title, if we may say...
Step 6: Understanding the Flow
As you have probably noticed by now, the system has a lot of "moving parts". We will try to clarify how things are connected to each other.
First, we have our garbage can with the NodeMCU and its sensors. We can have plenty of these - just "copies" of each other.
The NodeMCU measures the different sensors placed in the garbage can, and publishes the data to the MQTT server (MQTT protocol). You can think of the MQTT server as a big information exchange, that many garbage cans can report their information to.
Another entity that connects to the MQTT server is Node-RED. Node-RED listens to the different messages coming from the garbage can(s) carrying the sensorial data, and applies its logic on it. It works by utilizing "flows" of information. Each time a message is received, based on its type (MQTT topic), it enters specific chains of operations that end up activating the different features of the system (updating the dashboard, sending alerts, etc.) It would be very correct to say that Node-RED is the "brain" of the system. It is aware to everything that happens everywhere, and can take actions accordingly.
Inside Node-RED we have constructed 3 main flows of information:
- Widgets - Sensorial information being fed into Node-RED is then displayed on the dashboard via gauges and graphs.
- Alerts - Sensorial information is processed to conclude whether an alert should be triggered (on dashboard or to the smartphone app). The fullness level, with the temperature & humidity are taken into account to decide to inform the user that the garbage can is full. Also, sensorial errors are reported by the same flow.
- Statistics - Sensorial information is aggregated to display the fullest and hottest garbage cans.
In order for Node-RED to send push notification, it connects to a service called IFTTT (by HTTP protocol). It activates a certain IFTTT event with the relevant notification text, and IFTTT sends the notification to our smartphone (HTTP & XMPP protocols).
Consult the images above to better understand (a) the general structure of the system, and (b) the 3 different information flows inside Node-RED.
Step 7: Challenges, Limitations and Plans for the Future...
In regard to limitations, the first one would be the fact that we used free services only, and they won't allow going full scale. CloudMQTT free plan will not allow having more than 5 parallel connections, meaning we can have only 4 garbage cans and the Node-RED. FRED Node-RED free plan only allows 24 hours of straight usage, after which you have to manually log-in and reset the timer. However, these issues are easily solvable by either running these services locally, or paying a little extra to lift the limitations. The second limitation is the fact that when one add the fourth garbage can and onwards, he has to manually edit the widgets flow in Node-RED to add its appropriate widgets.
Plans for the Future
We had some ideas to further enhance our system and extend it:
- Move on to non-free cloud services. (single day of work).
- Adding a garbage compressor to the garbage can, thus reducing the frequency of emptying it. (4 months of work)
- Working with urban and industrial trash cans to improve the efficiency of the city trucks that handle the trash in the city. This would mean to greatly improve the dashboard and notification system so that truck drivers can plan their route much better when handling the trash. (6 months of work).
- Adding recycling abilities to the garbage can, like ability to pour special biological solutions into the garbage and help recycle it while it is still inside the garbage can. This can be used domestically for example to produce compost for gardens, but can clearly be used also on industrial cans as well. (6 months of work).