Waste management is a concern among all citizens and governments, as there is an increasing trend in recycling and smart management systems. Personally, I can think of nobody who likes seeing oversaturated containers surrounded by bags full of leaking trash. Just take a look at this real example in Spain!
Poor handled recycling systems do not only worsen the appearance of your neighbourhood, but also they represent a major issue for public health and increased costs in maintenance and collection.
The good thing is that recycling rates are increasing every year. However the waste management systems are still the same since decades ago. This leaves some questions hanging in the air. Is our current waste management up to speed in a world guided by consumism and disposable products?
What about a system of waste management (SWM), by which customized pickup routes are created according to necessity? Is there any possibility of saving costs and enhancing the collection processes?
In order to answer these questions, we have to keep in mind one thing: conventional garbage must be collected EVERYDAY, as it consists of organic residue. If not, it may cause strong odors and undesired effects due to its quick decomposition.
A more defined application is then presented, smart management systems for recycled materials.
THE IDEANowadays intelligent containers are state-of-the-art devices which are slowly implemented in big cities worldwide. However, they are still too expensive to integrate in small and medium cities, which undoubtedly can take advantage of smart management systems.
That's where the Microchip AVR-IoT Mini Cellular Board plays a crucial role in the revolution of IoT devices. Thanks to its relative low price and its high potential functionalities, low-cost smart trash containers can come to fruition!
In order to design a product that overcomes the problem, these well differentiated requirements are presented:
- Connectivity: it has to be able to connect with a dashboard that indicates the necessity of pickups and shows the current level of trash. All of this through LTE network with a SIM card. Thankfully this is already integrated in the powerful Microchip AVR-IoT Mini Cellular Board.
- Quickresponsetimes: no fun in having to wait to take out the trash, huh?
- Possibilityofresettingthesystem: this feature represents the possibility of emptying the trash containers. This will be done by the maintenance team and trash collectors.
- Long lastingbatteries: the less maintenance needed, the better. As it happens with all IoT devices, batteries are the major problem.
Once all the premises are well established, let's dive into the execution of the project!
DESIGNING THE SCHEMATICS AND CHOOSING COMPONENTSOnly a few components will be needed to create the minimum viable product (MVP).
- Microchip AVR-IoT Mini Cellular Board: the microcontroller used. It provides the connectivity to LTE networks and an already integrated MCP9808 temperature sensor.
- Servomotor: the idea is to let the users throw the trash in a given safe time. Then the container has to be closed, and blocked if it's full until the collection. Conventional servomotors will do it in this 3D printed prototype.
- Ultrasound sensor: this is the key component that provides trash level readings according to the distance to the container's floor.
- Structure: a 3D printed structure based on a real trash container is designed and produced. It should integrate all the parts together in a pleasant way.
For the upload and representation of data, the MQTT protocol and the Adafruit IO platform are selected.
ITC: DIRECTIONS FOR USEUsers and waste managers should have no worries when using the ITC, as it outstands because of its simplicity.
If users want to throw the trash when the container is not full, they have to press the "introduce trash" button. In the case of the developed prototype, it refers to the SW0 integrated button. Once it is pressed, the lid is opened to let the user deposit the trash within a safe period of time prior to closing the lid again.
At the time the button is pressed, a message to the dashboard log is sent. It indicates that someone is throwing trash in the container. After the safe period of time passes, the lid is again closed. Then with the ultrasound sensor measurements of the distance to the floor are taken to determine the current trash level.
The ITC performs also temperature measurements periodically and post them in the dashboard.
With the trash level bar, it is possible to know exactly how much trash is the container holding.
When a container has reached the limit of its capacity, it is blocked in order to avoid oversaturation. In consequence, it is indicated in the dashboard for managers to perform the emptying. The trash level bar becomes red, the log does the warning, and a red flashing LED indicates the necessity for a pickup.
After the emptying of the container, the trash levels return to zero and the ITC is again operative. The lid unblocks to users until the next full capacity warning. To represent the emptying of the container, the ITC prototype is "emptied" by pressing the SW0 button for five consecutive seconds.
Here are the main key aspects of the code explained. You can see the full code below though!
The libraries needed are the following:
// Libraries
#include <Arduino.h>
#include <mcp9808.h> // Temperature sensor
#include <Servo.h> // Servomotor
#include <mqtt_client.h> // MQTT comms
#include <lte.h> // LTE connection
The code lies on interruptions of the SW0 button, which are enabled and disabled depending on the status of the container. If it's not full, pressing the button means that someone wants to use it. However, if it is indeed full, the interruption is disabled and the button serves only as a reset.
void sw0_pressed(){
new_trash = true; // Someone wants to use the container
Serial3.println("Someone is introducing trash");
}
Sending MQTT messages is simplified by using the mqtt_client library. Two functions are defined to publish in the log and control the other indicators.
void publishing_log(String string){ // Function to publish in log
// Attempt to connect to the broker
if(MqttClient.begin(MQTT_THING_NAME,
AIO_SERVER,
AIO_SERVERPORT,
MQTT_USE_TLS,
MQTT_KEEPALIVE,
MQTT_USE_ECC,
IO_USERNAME,
IO_KEY)){
Serial3.println("MQTT connection established");
bool publishedSuccessfully = MqttClient.publish(MQTT_PUB_TOPIC1, string.c_str());
if (publishedSuccessfully) {
Serial3.print("Published message: ");
Serial3.println(string);
} else {
Serial3.println("Failed to publish");
}
Serial3.println("Closing MQTT connection");
}else{
Serial3.println("Connection to MQTT failed");
}
MqttClient.end();
}
void publishing_data(char opt, String num){ // Function to publish in numeric indicators
bool publishedSuccessfully;
// Attempt to connect to the broker
if(MqttClient.begin(MQTT_THING_NAME,
AIO_SERVER,
AIO_SERVERPORT,
MQTT_USE_TLS,
MQTT_KEEPALIVE,
MQTT_USE_ECC,
IO_USERNAME,
IO_KEY)){
Serial3.println("MQTT connection established");
// Topic selection according to indicator
switch(opt){
case 0:
publishedSuccessfully = MqttClient.publish(MQTT_PUB_TOPIC2, num.c_str());
break;
case 1:
publishedSuccessfully = MqttClient.publish(MQTT_PUB_TOPIC3, num.c_str());
break;
case 2:
publishedSuccessfully = MqttClient.publish(MQTT_PUB_TOPIC4, num.c_str());
break;
default:
Serial3.println("ERROR");
}
if (publishedSuccessfully) {
Serial3.print("Published message: ");
Serial3.println(num);
} else {
Serial3.println("Failed to publish");
}
Serial3.println("Closing MQTT connection");
delay(2000);
}else{
Serial3.println("Connection to MQTT failed");
}
MqttClient.end();
}
The LTE initialization is done in the setup block.
// Establish LTE connection
if (!Lte.begin()) {
Serial3.println("Failed to connect to operator");
// Halt here
while (1) {}
}
Serial3.println("Connected to operator");
In the loop block, the behavior of the container is split into different functions.
if( (millis() - last_time_tem) > period_ms_tem){ // Checks if it has to measure temperature
// Temperature
int TempC = (int)Mcp9808.readTempC();
int Temp = ((TempC - 32) * 5 / 9); // Conversion to ºC
Serial3.println("Temperature: ");
Serial3.print(TempC);
Serial3.println(" ºF");
Serial3.print(Temp);
Serial3.println(" ºC");
publishing_data(1, (String) Temp);
last_time_tem = millis();
}
if(new_trash && !full ){ // Only opens if button pressed and it's not full
float volume = 0;
servo.write(90);
publishing_log("Someone is dumping trash");
delay(8000); // 10 s delay to let users throw the trash
digitalWrite(Trigger, LOW);
delayMicroseconds(5);
digitalWrite(Trigger, HIGH);
delayMicroseconds(10);
digitalWrite(Trigger, LOW);
pinMode(Echo, INPUT);
duration = pulseIn(Echo, HIGH);
cm = (duration/2) / 29.1;
Serial3.print("Distance = ");
Serial3.print(cm);
Serial3.println(" cm");
volume = (float) (((15 - cm) * 100)/ 13); // 15 cm but 12 are in range of measurement
if( cm > 0 && cm < 6){
full = true;
Serial3.println("Container is full!");
publishing_log("Container is full. Please empty");
publishing_data(0, "1");
detachInterrupt(digitalPinToInterrupt(SW0)); // Button no longer responds to users as it is full
}
publishing_data(2, (String) volume);
servo.write(0);
digitalWrite(PIN_PE1, LOW);
new_trash = false;
}
if(!digitalRead(SW0)){ // Checks if SW0 is pressed for 5 sec
last_time_pressed = millis();
while(!digitalRead(SW0)){}
if( (millis() - last_time_pressed ) > reset){
full = false;
Serial3.println("Container has been emptied");
publishing_log("Container has been emptied");
publishing_data(0, "0"); // Off indicator
publishing_data(2, "0"); // Reset trash levels
attachInterrupt(digitalPinToInterrupt(SW0), sw0_pressed, FALLING); // Enable interrupt again
}
}
FUTURE EXPECTATIONSITC prototype presents a solution to the waste management systems in the IoT world we have ahead, yet it can be improved for a better implementation in large scale. Here are some insights I want to address to take this project to the next level in the future.
- Efficient sleep modes: enlarging the batteries is not the only solution to the consumption of the IoT systems. There is indeed another more elegant way of controlling this issue: Sleep states. By creating a sleep routine, the microcontroller consumption plummets, extending the duration of the system.
- High quality trash level measurements: this could be solved by designing a mesh of ultrasound sensors on the ceeling of the container. As trash is far from regular-shaped, having a mesh of measurements would indicate in a more proper way the actual level of trash.
The society is changing and evolving constantly, and so are our needs and desires. With the arrival and development of IoT devices in the last decades, conventional systems can be transformed to satisfy our present needs. This is the case with recycling and waste management systems.
I strongly believe that ITC or similar IoT waste management devices, powered by more and more awesome boards as the AVR-IoT Mini, can contribute to keep us on the right track to a brilliant and green future. For now, we must all keep recycling to achieve this goal!
Comments