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:

#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.setCursor(0, 0);
  lcd.print("IoT Garbage lvl");
  lcd.setCursor(0, 1);
  lcd.print("Monitoring Sys.");
  pinMode(trigger, OUTPUT);
  pinMode(echo, INPUT);
  snsr_to_max = total_height - hold_height;
void loop()
  lcd.setCursor(0, 0);
  lcd.print("Garbage Level:");
  lcd.setCursor(5, 1);
  Serial.print("Garbage Level:");
  for (i = 0; i < Minute; i++)
    Serial.println("System Standby....");
    Serial.println(" Minutes elapsed.");
void upload()
  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....");

void measure()
  digitalWrite(trigger, HIGH);
  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: ");
    while (WiFi.status() != WL_CONNECTED)
      WiFi.begin(ssid, pass);

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:

IoT based garbage monitoring system - Prototype
IoT based garbage monitoring system – Prototype

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.

Avatar photo

My nick name is blogthor, I am a professional electronics engineer specialized in Embedded System. I am a experienced programmer and electronics hardware developer. I am the founder of this website, I am also a hobbyist, DIYer and a constant learner. I love to solve your technical queries via comment section.