Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

COMPUTER APPLICATIONS DEPARTMENT

COLLEGE OF COMPUTER STUDIES


Mindanao State University – Iligan Institute of Technology
Tibanga, Iligan City

Efficient Waste Monitoring: ESP32-enabled


Smart Trash Bin with Email Notifications
via IFTTT

Subject BCA144: Introduction of Internet of Things

Submitted to:
Leah Aquino-Alindayo, D. Eng., PCpE

Submitted by:
Fuentes, Christine Jay F.
Solon, Hanzel Bam G.
Tagas, Monica B.

JUNE 2023
COMPUTER APPLICATIONS DEPARTMENT
COLLEGE OF COMPUTER STUDIES
Mindanao State University – Iligan Institute of Technology
Tibanga, Iligan City

INTRODUCTION
Background of the Study

Proper waste management is essential to prevent garbage from being scattered


everywhere, which can lead to health problems and environmental pollution. The waste management
container is a crucial element in maintaining a clean and beautiful environment by providing a
designated place for everyone to dispose of their waste. Given the urgency and significance of
addressing the waste problem, it is important to ensure the availability of sufficient waste containers
that can effectively contain trash.
Traditionally, waste containers come with lids that help contain odors and prevent them
from escaping to the surroundings. Such an innovative trash bin incorporates features to monitor the
level of trash inside, indicating whether it is full or not. This real-time monitoring system would help
people quickly identify whether the garbage container needs to be emptied or if there is still space
available. By integrating these features into a garbage disposal container, the practicality and
convenience of disposing of trash would be greatly enhanced. Users would be able to throw their
garbage away with the assurance that they are aware of the trash level. This advanced trash bin
contributes to more efficient waste management and assists in maintaining cleanliness and
environmental aesthetics in cities and other areas.
In the context of waste management, one of the challenges highlighted by previous
researchers is the absence of a scheduling system to regulate the cleaning of trash when containers are
full. People often lack information about when a trash bin is filled with waste, which hampers the
timely disposal of garbage. To ensure efficient waste management, it is crucial to identify bins that are
full so that cleaners can promptly empty them at designated collection points, such as incinerators,
trash crushers, or recycling bins. Proper monitoring mechanisms are necessary to facilitate this
process and support waste management. Failing to manage waste containers properly can have
significant negative impacts on the environment and public health.
Waste management activities encompass various essential actions, including the
transportation of waste to landfills. Typically, garbage collectors follow predetermined schedules for
waste transportation. However, when a garbage container becomes full and it is not the scheduled
time for the cleaning staff to attend to it, people are unable to dispose of their garbage in the container.
This delay in emptying trash containers in public places can disrupt the community's comfort and
order when it comes to waste disposal. Manually checking which garbage containers are full of trash
is time-consuming and inefficient for the janitors. Kumar et al. (2021) emphasized the need to develop
an efficient waste management system, suggesting the implementation of a control system. Therefore,
creating an intelligent waste container system is crucial for ecological well-being and serves as a
clever solution to the waste management system.

In this IoT project, the primary focus is on the user input to detect the level of trash. If the
ESP32 device is connected to the internet, the control can be done through the Arduino IoT Cloud
dashboard. However, if the device is not connected to the internet, we will not be able to control the
trash level using the Arduino IoT Cloud.

BLOCK DIAGRAM
COMPUTER APPLICATIONS DEPARTMENT
COLLEGE OF COMPUTER STUDIES
Mindanao State University – Iligan Institute of Technology
Tibanga, Iligan City

INPUT PROCESS OUTPUT

ESP32
MICROCONTROLLER
ULTRASONIC
SERVO IFFT PLATFORM

CLOUD

Figure 1. Block Diagram of IOT-Based Smart Trash Bin using ESP32


The input stage comprises only one sensor, an ultrasonic sensor, which can detect the level of
garbage. Next, when the garbage container is filled with trash, the ESP32 microcontroller obtains
information from the waste container application system via the internet network. Finally, the ESP32
sends instructions to the IFFT. The IFFT, connected to the IFFT platform, enables storage and access
to data and programs via the Internet. The IFFT platform is to send Email notifications when the
Trash Bin filled more than 70%. In the output stage, users can monitor the level of the garbage.
CIRCUIT DESIGN
The circuit design of our proposed Efficient Waste Monitoring is illustrated below, depicting the
sensor connections and the corresponding wiring configuration.

Figure 2. Circuit Design of IoT-based "Efficient Waste Monitoring using ESP32


COMPUTER APPLICATIONS DEPARTMENT
COLLEGE OF COMPUTER STUDIES
Mindanao State University – Iligan Institute of Technology
Tibanga, Iligan City

In this project, we are interfacing the ultrasonic sensor with ESP32. HC-SR04 ultrasonic sensor works
on 5V. The VCC pin of the ultrasonic sensor is connected to the VIN pin of Esp32. Trig and Echo
pins are connected to D2 and D5 pin of ESP32 while the GND pin of the sensor is connected to the
GND pin of ESP32.

ALGORITHM (Pseudocode)

1. Initialize the necessary libraries: WiFi and WiFiClient.


2. Define the pin numbers for the ultrasonic sensor (trigPin and echoPin).
3. Declare variables to store the duration and distance measurements from the sensor.
4. Declare a function named send_event that takes an event name as a parameter.
5. Declare a variable to store the level of the dustbin as a percentage.
6. Define the SSID and password for the Wi-Fi network.
7. Define the host and privateKey for sending events.
8. Create a WiFiServer object named server on port 80.
9. Define the setup function:
 Set the trigPin as OUTPUT and echoPin as INPUT.
 Initialize the Serial communication with a baud rate of 115200.
 Connect to the Wi-Fi network using the provided SSID and password.
 Wait until the Wi-Fi connection is established.
 Print the Wi-Fi connection status and the local IP address.
 Start the server.

10. Define the loop function:


 Trigger the ultrasonic sensor by sending a short pulse.
 Measure the duration it takes for the pulse to return and calculate the distance.
 Print the distance and calculate the dustbin level based on the distance.
 Delay for 1 second.
 Check if a client is available to connect to the server.
 If a client is connected:
 Read the request from the client.
 Send HTTP response headers to the client.
 Send the HTML content with the dustbin level to the client.
 If the dustbin level is equal to or greater than 70, send an event using the send_event
function.
11. Define the send_event function:
 Connect to the host specified in the global variable.
 Create a URL with the event name and private key.
 Send an HTTP GET request to the host with the constructed URL.
 Read the response from the host and print it.
 Close the connection with the host.
The algorithm starts by setting up the necessary libraries and defining variables for the
ultrasonic sensor, Wi-Fi network, and event parameters. In the setup function, it connects to the
specified Wi-Fi network and starts the server. In the loop function, it triggers the ultrasonic sensor to
measure the distance and calculates the dustbin level based on that distance. It then checks if a client is
connected to the server, and if so, it sends an HTTP response with the dustbin level displayed in an
COMPUTER APPLICATIONS DEPARTMENT
COLLEGE OF COMPUTER STUDIES
Mindanao State University – Iligan Institute of Technology
Tibanga, Iligan City

HTML page. If the dustbin level exceeds or equals 70, it sends an event using the send_event function.
The send_event function connects to the specified host, constructs a URL with the event name and
private key, sends an HTTP GET request to the host, and prints the response. Overall, the algorithm
continuously measures the dustbin level, updates the webpage for connected clients, and sends an event
when the Smart Trashbin is almost full.

CODING:

#include <WiFi.h>
#include <WiFiClient.h>

// define the pins where you connected the Trig and Echo pins and also define two variables for
calculating distance and duration.

const int trigPin = 5;


const int echoPin = 2;

long duration;
int distance;

void send_event(const char *event);


float level;

// make instances for Wi-Fi name, Wi-Fi password, IFTTT host name and private key.

const char* ssid = "DESKTOP-JAQOT0L 1396";


const char* password = "12345678";

const char *host = "maker.ifttt.com";


const char *privateKey = "npU3bY1cu2DlEEpbUmg11R4BKZ6O_8ppOYGaZnXOVfY"; //
replace this with Private key

//Now to access the WiFiServer, we declared an object WifiServer library. 80 is the default port for
HTTP.
COMPUTER APPLICATIONS DEPARTMENT
COLLEGE OF COMPUTER STUDIES
Mindanao State University – Iligan Institute of Technology
Tibanga, Iligan City

WiFiServer server(80);

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(115200);
Serial.print("Connecting to Wi-Fi Network: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Successfully connected to WiFi.");
Serial.print("IP address is: ");
Serial.println(WiFi.localIP());
server.begin();
Serial.println("Server started");
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.0340 / 2;
Serial.println("Distance:");
Serial.println(distance);
level = ((14 - distance) / 14.0) * 100;
Serial.println("Level:");
COMPUTER APPLICATIONS DEPARTMENT
COLLEGE OF COMPUTER STUDIES
Mindanao State University – Iligan Institute of Technology
Tibanga, Iligan City

Serial.println(level);
delay(1000);

WiFiClient client = server.available();

if (client) {
Serial.println("Web Client connected");
String request = client.readStringUntil('\r');
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 10");
client.println();

\\ This code is for the display of our project the font and design
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<style>html { font-family: Cairo; display: block; margin: 0px auto; text-align:
center;color: #333333; background-color: #f3ffee;}");
client.println("body{margin-top: 50px;}");
client.println("h1 {margin: 50px auto 30px; font-size: 50px; text-align: center;}");
client.println(".side_adjust{display: inline-block;vertical-align: middle;position: relative;}");
client.println(".text1{font-weight: 180; padding-left: 5px; font-size: 50px; width: 170px; text-
align: left; color: #3498db;}");
client.println(".data1{font-weight: 180; padding-left: 1px; font-size: 50px;color: #3498db;}");
client.println(".data{padding: 1px;}");
client.println("</style>");
client.println("</head>");
client.println("<body>");
client.println("<div id=\"webpage\">");
client.println("<h1>IoT Based Trashbin</h1>");
client.println("<div class=\"data\">");
client.println("<div class=\"side_adjust text1\">Status:</div>");
client.println("<div class=\"side_adjust data1\">");
COMPUTER APPLICATIONS DEPARTMENT
COLLEGE OF COMPUTER STUDIES
Mindanao State University – Iligan Institute of Technology
Tibanga, Iligan City

client.print(level);
client.println("<div class=\"side_adjust text1\">% filled</div>");
client.println("</div>");
client.println("</div>");
client.println("</body>");
client.println("</html>");

if (level >= 10) {


send_event("Trashbin_event");
}
}
}

void send_event(const char *event) {


Serial.print("Connecting to ");
Serial.println(host);

WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("Connection failed");
return;
}

String url = "/trigger/";


url += event;
url += "/with/key/";
url += privateKey;

Serial.print("Requesting URL: ");


Serial.println(url);

client.print(String("GET ") + url + " HTTP/1.1\r\n" +


COMPUTER APPLICATIONS DEPARTMENT
COLLEGE OF COMPUTER STUDIES
Mindanao State University – Iligan Institute of Technology
Tibanga, Iligan City

"Host: " + host + "\r\n" +


"Connection: close\r\n\r\n");

while (client.connected()) {
if (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
} else {
delay(50);
}
}

Serial.println();
Serial.println("Closing connection");
client.stop();
}

Result and Findings

Figure 3
COMPUTER APPLICATIONS DEPARTMENT
COLLEGE OF COMPUTER STUDIES
Mindanao State University – Iligan Institute of Technology
Tibanga, Iligan City

Figure 4 and 5: Labeling the Waste Monitoring of the IoT-Based Trash Bin using ESP32 on
IFTTT
In Figure 4 and Figure 5, the trash display label shows that the trash levels are 0% and 81% respectively.
When the label of the trash bin exceeds 70%, an email notification is sent to inform that the trash bin is almost
full.

Figure 6: Notification
COMPUTER APPLICATIONS DEPARTMENT
COLLEGE OF COMPUTER STUDIES
Mindanao State University – Iligan Institute of Technology
Tibanga, Iligan City

BILL OF MATERIALS

NAME COST QUANTITY TOTAL


ESP32 microcontroller ₱195.00 1 unit ₱195.00
Ultrasonic Sensor ₱80.00 1 unit ₱80.00
Breadboard ₱85.00 2 unit ₱170.00
Jumper Wires ₱40.00 1 bundle ₱40.00
Trash Bin ₱40.00 1 unit ₱40.00
Stick Glue ₱30.00 1 bundle ₱30.00
TOTAL AMOUNT ₱555.00

REFERENCES:
https://www.researchgate.net/publication/353161459_Smart_Dustbin_Using_IOT_Notif
ication
https://quartzcomponents.com/blogs/electronics-projects/iot-based-smart-dustbin-
using-nodemcu

You might also like