IoT Based Garbage Monitoring System | ESP8266 | Arduino
In this post we are going to make an IoT based garbage bin level monitoring system or simply IoT smart dustbin where real time garbage fill level can be monitored via internet. The proposed system uses non-contact method (ultrasonic based) for measuring garbage level and it can detect solid, semi-solid and liquid waste. The proposed project can send garbage level data at a fixed interval to an IoT cloud server called Thingspeak.
We will see:
- What is IoT based garbage monitoring system?
- Role of big data analytics and AI in garbage monitoring.
- Garbage level detection method.
- Setting your Thingspeak account.
- Block diagram.
- Circuit diagram.
- Program code.
- Tested prototype and result.
What is IoT based garbage monitoring system?
IoT based garbage level monitoring system is an emerging technology that is utilized for monitoring waste fill level of public and industrial garbage bins. The fundamental purpose of a garbage level monitoring system is to help the municipal services to pick the trash at the right time before a garbage bin overflows and cause discomfort to general public.
An advanced garbage monitoring system can not only measure garbage level, it can also detect toxic chemical substances, flammable gases and even radioactive materials using advanced sensors and alert the authorities immediately via internet before any disastrous incident occurs.
Installing these IoT based garbage monitoring systems helps the government to work efficiently when it comes to keeping the city clean and saving millions of dollars a year by saving fuel / energy, labor cost and time, on top of this improvement in general public health which could save millions of lives and billions of dollars around the world otherwise which would have spent on health due to poor management of waste.
Role of big data analytics and AI in garbage monitoring:
What is Big Data Analytics?
In layman terms big data analytics is a domain where meaningful patterns, links and critical conclusions are drawn from massive sets of diverse data, this involves highly skilled people like data scientists, mathematicians and engineers and they use complex tools like software and powerful computers to simulate, analyze and extract meaningful data.
What is the role of Big Data Analytics in garbage monitoring system?
There are loads of benefits when we utilize big data analytics to internet connected garbage monitoring system; we have explained a few examples below.
Installing IoT based garbage monitoring systems is not just for an efficient operation of municipal services but also for understanding general population’s goods consumption and trend.
By understanding people’s goods consumption and current trend a government can decide things like how much funds need to be allocated for the current or next financial year and depending on the consumption trend a government can invest in new technology to tackle pollution due to an emerging trend.
Now, by installing thousands or even millions of garbage monitoring system across a country (say), the government may get bombarded with huge number of data in real-time; by looking into the raw data we will observe only noise, with the help of big data analytics we can find several meaningful and critical data using which a better decision can be executed by a government for a country’s cleanliness.
What is the role of AI in garbage monitoring system?
To detect unusual or criminal activity in a locality, to understand about waste materials that has been dumped and public goods consumption trend to say a few; we can integrate artificial intelligence to develop endless possibilities.
We can utilize advanced chemical sensors and specialized AI algorithms to detect unusual activity in an area like crime. In the past and present law enforcement agencies across several countries have successfully decoded several thousands of crimes using forensic clues from dustbins.
By training AI bots to decode information from the advanced chemical sensors placed on the smart IoT garbage bins will make our law enforcement team’s task much easier and faster.
Using AI we can also find the kind of waste material that is being dumped frequently across a region and understand the trend so that the government can invest to tackle the environmental affect due to the new trend.
How the garbage level is detected?
In this project we are going to use an ultrasonic distance measuring sensor to detect precise level of garbage fill. Using this method we can detect the level of all kind of solid waste as well as liquid waste.
Here, an ultrasonic sensor is placed on the top of the garbage bin which emits ultrasonic waves at 40 KHz (which is far beyond human hearing range) the waves hits the trash and reflects back to the sensor. The time taken between emitted and received is used to measure the garbage fill level.
A public or industrial garbage bin has a maximum waste holding capacity beyond which overflow may occur, the ultrasonic sensor is placed well above this limit.
How liquid waste levels are detected?
Detecting liquid waste level is no different from detecting solid waste level, the ultrasonic waves emitted from the sensor can very well reflect off the liquid surface. You can find more details in this patent.
How to set up your Thingspeak account?
You need to setup your Thingspeak account correctly to receive the garbage level data online. To do this you need to sign up for Thingspeak account here.
- Once you have signed up, you need to click on “New channel”.
This will prompt you to fill the new channel details and you need to fill it exactly as shown below and please take note of your channel ID where you need to enter it in the given code.
- Scroll down and click save.
- Now click “API key” tab and it will show your “write” and “read” API keys using which you can write or read data from your channel. Keep your API keys confidential.
- Take note of your write API key as we need to enter it in the given code.
- Now click “private view” tab, you will see an empty channel waiting for receiving data.
- Once you finished setting-up your Thingspeak account, you need to download and install ESP8266 package to your Arduino IDE, only then ESP8266 based IoT boards will get compatible with your Arduino IDE. You can find the instructions in this article, please scroll to the relevant section.
Block diagram:
Circuit diagram:
Circuit description:
The proposed circuit is simple and just comprises of 4 components: The LCD, ultrasonic sensor, I2C display adapter and a NodeMCU.
The NodeMCU which is based on ESP8266 is the brain of the project which does the following routine: Measures garbage level by triggering the ultrasonic sensor, displaying the garbage level on the LCD and connecting to internet to sending garbage level data to Thingspeak server.
The LCD is paired to an I2C adapter module which reduces the number of wires to 4 that connects to LCD from Arduino. Use its on-board preset resistor to adjust LCD contrast.
The LCD display shows real-time garbage level locally without the need for internet. The whole circuit is powered from a micro USB power cable.
Download the following library before you compile the code:
Library 1: I2C LCD
Library 2: Thingspeak.h
Program code:
//-----------------(C)Electronics-project-hub.com----------------// #include "ThingSpeak.h" #include <ESP8266WiFi.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); //----------- Enter you Wi-Fi Details---------// char ssid[] = "XXXXXXXX"; //SSID char pass[] = "YYYYYYYY"; // Password //-------------------------------------------// // ---------- garbage bin details ------------// const int total_height = 30; // garbage bin height in CM const int hold_height = 25;// garbage holding capacity (height) in CM //-------------------------------------------// //----- Minutes -----// int Minute = 1; // Data update in min. //------------------// //----------- Channel Details -------------// unsigned long Channel_ID = 123456; // Channel ID const char * WriteAPIKey = "ABCDEFG123456"; // Your write API Key // ----------------------------------------// const int trigger = 14; const int echo = 12; long Time; int x; int i; int distanceCM; int resultCM; int bin_lvl = 0; int snsr_to_max = 0; const int Field_number = 1; WiFiClient client; void setup() { lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("IoT Garbage lvl"); lcd.setCursor(0, 1); lcd.print("Monitoring Sys."); Serial.begin(115200); pinMode(trigger, OUTPUT); pinMode(echo, INPUT); WiFi.mode(WIFI_STA); ThingSpeak.begin(client); snsr_to_max = total_height - hold_height; delay(2500); } void loop() { internet(); measure(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Garbage Level:"); lcd.setCursor(5, 1); lcd.print(bin_lvl); lcd.print('%'); Serial.print("Garbage Level:"); Serial.print(bin_lvl); Serial.println("%"); upload(); for (i = 0; i < Minute; i++) { Serial.println("-------------------------"); Serial.println("System Standby...."); Serial.print(i); Serial.println(" Minutes elapsed."); delay(20000); delay(20000); delay(20000); } } void upload() { internet(); x = ThingSpeak.writeField(Channel_ID, Field_number, bin_lvl, WriteAPIKey); if (x == 200)Serial.println("Data Updated."); if (x != 200) { Serial.println("Data upload failed, retrying...."); delay(15000); upload(); } } void measure() { delay(100); digitalWrite(trigger, HIGH); delayMicroseconds(10); digitalWrite(trigger, LOW); Time = pulseIn(echo, HIGH); distanceCM = Time * 0.034; resultCM = distanceCM / 2; bin_lvl = map(resultCM, snsr_to_max, total_height, 100, 0); if (bin_lvl > 100) bin_lvl = 100; if (bin_lvl < 0) bin_lvl = 0; } void internet() { if (WiFi.status() != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); while (WiFi.status() != WL_CONNECTED) { WiFi.begin(ssid, pass); Serial.print("."); delay(5000); } Serial.println("\nConnected."); } } //-----------------(C)Electronics-project-hub.com----------------//
You need to enter your following credentials in the above program code:
Wi-Fi details:
//----------- Enter you Wi-Fi Details---------// char ssid[] = "XXXXXXXX"; //SSID char pass[] = "YYYYYYYY"; // Password //-------------------------------------------//
You need to enter the dimensions of the garbage bin here:
You need to enter the total height of your garbage bin and the waste holding capacity height in centimeter.
// ---------- garbage bin details ------------// const int total_height = 35; // garbage bin height in CM const int hold_height = 30 ;// garbage holding capacity (height) in CM //-------------------------------------------//
Here you need to enter how frequent the garbage fill data must sent to Thingspeak in minutes:
//----- Minutes -----// int Minute = 1; // Data update in min. //------------------//
For example, if you enter 1, it will send data every one minute, if you enter 60, it will send data every 60 minutes / 1 hour and so on.
Here you need to enter your channel ID and your write API key:
//----------- Channel Details -------------// unsigned long Channel_ID = 123456; // Channel ID const char * WriteAPIKey = "ABCDEFG123456"; // Your write API Key // ----------------------------------------//
Prototype and result:
Please scroll up to the section “How the garbage level is detected?” and refer the diagram for installing the ultrasonic sensor properly on top of a trash bin.
Private view on Thingspeak in percentage:
If you have any questions regarding this project, feel free to ask us in the comment section and you will get a guaranteed reply from us.
Hye, i really interested with your project. Right now, im having a final year project and i choose to pick this topic. Can you share full report for this project. Thank you
The article is the full report……….
Hi, i didn’t understand connections between nodemcu and lcd .so I want full connections of project .I hope as early as possible ,you send all relavant information to me.thank you
Hi, all details we have is in the article, we don’t have any additional info.
Hi, I have not connected lcd so which code will be remove.
You no need to remove anything on the code, you just remove the LCD from your circuit.
If i using Arduino Uno and Esp8266 module, how should i write the coding?
We will try to update it in future.
do you update with Arduino uno?
Can you please rephrase your question?
I can’t get the correct reading. It only shows 0% even the garbage is full. What should i have to do? Please help me….
Please check the ultrasonic sensor connections to Arduino…
Hello I want to ask due to this lockdown period we don’t have hardware parts arduino etc so how we can show it or set up it virtually? If any software there.
You may use a simulation software called proteus. But it won’t send any data to Thingspeak but you can observe serial data activity on virtual terminal.
Hi can i get circuit diagram and coding for Arduino and ESP8266? Thanks in advanced!
We will try to update in future, if possible.
this code are thorow an error this says that the
#include library are not found
Hi,
Please download and install the mentioned library files from the links provided.
Regards
Thank you for sharing your knowledge. I tried and everything worked perfectly
That’s great!
Can I able to connect Raspberry Pi with ThingSpeak cloud?
Yes! but not with this project.
Hi, I want to add LED for this project but I don’t have any idea how to code it. Can you help me?
Can you please elaborate more..
Hi sorry I’m late
I want to Add LED to indicate the level of the garbage base on the percentage
RED LED = FULL or 100%
YELLOW LED = MODERATE 50 – 70%
GREEN EMPTY = 0-40 %
Thank you sir
Thank you for your suggestion, we will try to implement it in our next update on this article.
What changes do we have to add if we include radioactive sensor,flame sensor and toxic chemical substance sensor?
Hi,
It can be done, but those changes are not simple to make or easy to explain in the comment with couple of lines, we will try to update the post with advanced sensor in future.
Regards
how do we know whether the essp8266 is connected to my ssid, i think i am having a problem with it the other part works fine and thank you for sharing man.
Hi,
You can view your ESP8266 in admin panel of your router.
Regards
its saying thingspeak.h: No such file or directory
Hi,
Add the thingspeak library to your Arduino IDE from the given link in the post.
Hello,How to connect gps gsm module with this for getting a message with location and what is the coding for that?
How get a api code from thingspeak for smart garbage monitoring system using iot project in mobile. Apk
Login to your thingspeak account from your smartphone using any browser.
Hi I want to ask.. how to make the thingspeak view to public? is we need to create url?
Hi,
Follow this article where I mentioned how to create public view: http://electronics-project-hub.com/iot-based-car-parking-system-using-arduino/
Hlo sir..
IoT Based Garbage Monitoring System | ESP8266 by using this project i need to add some more components like GSM sim900A module for alart message when dustbin is full..
Hi, we will try to make one in near future.
May i know connection for 12c adaptor
We will update it shortly.
whether this garbage monitoring system project code working or not
it may have so many errors
how can i clear that
Hi,
The proposed project is working and tested, please mention your exact problem so that I can help you.