Introduction: IDC2018IOT GarbageCan-Online

Introduction

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

Main Features

  1. Monitoring Dashboard:
    • Main Section:
      • Fullness level of each garbage can.
      • Temperature and humidity of each garbage can.
    • Statistics Section:
      • Fullest garbage can.
      • Hottest garbage can.
  2. Alerts & Notifications System:
    • The following events are supported:
      • Garbage can is Full.
      • A sensor error occurred.
    • 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.
  3. Scalability:
    • 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:

  1. Garbage can(preferably with a lid): This will be used for... well.. you know what we are going to do with this one, eh? ;)
  2. Breadboard: To connect all of the different components without using any soldering.
  3. NodeMCU (ESP-8266): In charge of reading the sensors and sending the information to the cloud.
  4. Distance IR Sensor - Sharp 0A41SK: This sensor will measure the amount of garbage (Fullness level) inside the can.
  5. Temperature & Humidity Sensor - DHT11: This sensor will measure the temperature and humidity inside the garbage can.
  6. Momentary Switch: Will be used to calibrate the distance sensor according to the size of the garbage can.
  7. Aluminum Foil: Will be used to form a detector for the lid status - whether it is opened or closed.
  8. Jumper wires: Get plenty, and at different lengths and colors. Will connect everything together.
  9. Duct Tape: We will have to attach things into place.
  10. Micro-USB Cable: To connect the NodeMCU to your computer for programming, and later on for a power supply.
  11. USB Power Supply (smartphone charger): Will provide power to the NodeMCU when installed on the garbage can.

Step 2: Wiring & Assembling

Wiring

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
  • Temperature & Humidity Sensor - DHT11:
    • Vin (Red) --> 3V3
    • GND (Black) --> GND
    • DATA (Yellow) --> D4
  • Momentary Switch:
    • Pin1 --> D3
    • Pin2 --> GND
  • Lid status (open\close) wires:
    • Wire1 --> D2
    • Wire2 --> GND

Assembly

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:

  1. 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!
  2. Place the temperature & humidity sensor somewhere inside the garbage can. Secure with tape.
  3. 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.

  1. Signup to CloudMQTT with the free plan. Note your credentials to the MQTT server (username and password).
  2. 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.
  3. Download the IFTTT app to your phone and sign in with your credentials. This will allow you to get push notifications.
  4. Signup to FRED with the free plan.
  5. 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.
  6. Edit one of the MQTT nodes (one is enough) to update your CloudMQTT credentials.
  7. 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.

  1. Download and install the Arduino IDE from here.
  2. Install and set the NodeMCU board type as explained in the beginning of the following instructable.
  3. Install the following libraries (Sketch --> Include Library --> Manage Libraries...):
    1. Adafruit MQTT Library (by Adafruit)
    2. DHT sensor library (By Adafruit)
    3. SharpIR (by Giuseppe Masino)
    4. EEPROMAnything - explanation here.
  4. Open up GarbageCanOnline.ino file, and update the following:
    1. Your WiFi credentials (WLAN_SSID, WLAN_PASS)
    2. Your CloudMQTT credentials (MQTT_USERNAME, MQTT_PASSWORD)

    3. If this is a second garbage can or more, change the garbage can ID (GARBAGECAN_ID)

  5. Upload the updated sketch to your NodeMCU.
  6. Open up the serial monitor window (Ctrl+M) and make sure that it manages to publish the sensors data to CloudMQTT.
  7. Now, when the lid is closed and the garbage can is empty, long-press the calibration button to calibrate the garbage can capacity.
  8. The garbage can is all set. You may disconnect it from your computer, and connect it in its designated location using the USB power supply.

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:

  1. Widgets - Sensorial information being fed into Node-RED is then displayed on the dashboard via gauges and graphs.
  2. 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.
  3. 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...

Challenges

The main challenges in this project were mostly handling the MQTT and Node-RED services. We first used AdafruitIO, but its custom MQTT implementation was not quite good for us. It wasn't convenient to work with its "feeds" inside Node-RED. Therefore we eventually opted for CloudMQTT, which is based on the Mosquitto MQTT server, and is much more standard. Then we moved on to handle Node-RED, which was quite challenging, mostly because Node-RED is a beast. For example, it is much more comprehensive and professional than IFTTT in our point of view. We had to adjust and learn how to use it's flow-based design approach to construct our required features of the system. Moreover, one of its biggest advantages is the support of javascript code, but it took as a while to get used to as we are not javascript programmers. Despite all of that, we really enjoyed working with this particular tool, and we found it to be very interesting and useful.

Limitations

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:

  1. Move on to non-free cloud services. (single day of work).
  2. Adding a garbage compressor to the garbage can, thus reducing the frequency of emptying it. (4 months of work)
  3. 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).
  4. 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).