Introduction
In this article, we will explain how to create a Smart Dustbin using few components like a 16×2 LCD display, an ultrasonic sensor, a Sim800l module, a NEO-6m module, and the ESP8266 microcontroller. This integration of hardware and software will enable us to monitor the status of the dustbin, Find out the Level of waste management, and provide real-time data for efficient collection and disposal.
Components Needed
- ESP8266 Controller
- GSM Module
- 16×2 LCD Display with I2C
- GPS Module
- Ultrasonic Sensor
- Wire
- Zero PCB
- 5V power supply
Circuit Diagram
LCD Display
-
- SDA: Connected to the SDA pin of the ESP8266
- SCL: Connected to the SCL pin of the ESP8266
- VCC: Connected to the 5V power supply
- GND: Connected to the ground (GND)
Ultrasonic Sensor
-
- Trig: Connected to a digital pin (D6) of the ESP8266
- Echo: Connected to a digital pin (D5) of the ESP8266
- VCC: Connected to the 5V power supply
- GND: Connected to the ground (GND)
GSM Module
-
- RX: Connected to the TX pin (D4) of the ESP8266
- TX: Connected to the RX pin (D3) of the ESP8266
- VCC: Connected to the 5V power supply
- GND: Connected to the ground (GND)
ESP8266
-
- VCC: Connected to the 5V power supply
- GND: Connected to the ground (GND)
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
#include <Wire.h> #include <LiquidCrystal_I2C.h> #include <SoftwareSerial.h> LiquidCrystal_I2C lcd(0x27, 16, 2); SoftwareSerial gsmSerial(D4, D3); const int trigPin = D6; const int echoPin = D5; const int threshold = 75; String phoneNumber = "+9188305848xx"; void setup() { lcd.begin(16, 2); lcd.backlight(); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); gsmSerial.begin(9600); delay(1000); lcd.clear(); lcd.print("Smart Dustbin"); lcd.setCursor(0, 1); lcd.print("Initializing..."); delay(2000); } void loop() { long duration, distance; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration / 2) / 29.1; int fillLevel = map(distance, 0, 100, 100, 0); lcd.clear(); lcd.print("Fill Level: "); lcd.print(fillLevel); lcd.print("%"); if (fillLevel >= threshold) { sendSMSAlert(); } delay(2000); } void sendSMSAlert() { lcd.clear(); lcd.print("Sending Alert..."); gsmSerial.println("AT+CPIN=<SIM_PIN>"); delay(2000); gsmSerial.println("AT+CMGF=1"); delay(1000); gsmSerial.print("AT+CMGS=\""); gsmSerial.print(phoneNumber); gsmSerial.println("\""); delay(1000); String message = "Dustbin Full! Please Empty."; gsmSerial.print(message); delay(1000); gsmSerial.write(0x1A); delay(2000); lcd.clear(); lcd.print("Alert Sent!"); delay(2000); } |
The setup() function
When the microcontroller starts. It initializes the LCD display, sets the pin modes for the ultrasonic sensor (trigPin as OUTPUT and echoPin as INPUT), initializes the GSM module’s serial communication, and displays an initialization message on the LCD.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
void setup() { lcd.begin(16, 2); lcd.backlight(); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); gsmSerial.begin(9600); delay(1000); lcd.clear(); lcd.print("Smart Dustbin"); lcd.setCursor(0, 1); lcd.print("Initializing..."); delay(2000); } |
The loop() function
Tthe main functionality of the code resides. It continuously measures the distance using the ultrasonic sensor, calculates the fill level percentage, and displays it on the LCD. If the fill level exceeds the threshold, the sendSMSAlert() function is called to send an SMS alert.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
void sendSMSAlert() { lcd.clear(); lcd.print("Sending Alert..."); gsmSerial.println("AT+CPIN=<SIM_PIN>"); delay(2000); gsmSerial.println("AT+CMGF=1"); delay(1000); gsmSerial.print("AT+CMGS=\""); gsmSerial.print(phoneNumber); gsmSerial.println("\""); delay(1000); String message = "Dustbin Full! Please Empty."; gsmSerial.print(message); delay(1000); gsmSerial.write(0x1A); delay(2000); lcd.clear(); lcd.print("Alert Sent!"); delay(2000); } |
The sendSMSAlert() function
Responsible for sending an SMS alert. It sends AT commands to the GSM module via the gsmSerial object to set the necessary configurations, recipient phone number, and message content. Finally, it sends the SMS by writing 0x1A (ASCII code for Ctrl+Z) to the GSM module and displays an “Alert Sent!” message on the LCD.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
void sendSMSAlert() { lcd.clear(); lcd.print("Sending Alert..."); gsmSerial.println("AT+CPIN=<SIM_PIN>"); delay(2000); gsmSerial.println("AT+CMGF=1"); delay(1000); gsmSerial.print("AT+CMGS=\""); gsmSerial.print(phoneNumber); gsmSerial.println("\""); delay(1000); String message = "Dustbin Full! Please Empty."; gsmSerial.print(message); delay(1000); gsmSerial.write(0x1A); delay(2000); lcd.clear(); lcd.print("Alert Sent!"); delay(2000); } |
Video
Conclusion
This smart solution allows for real-time monitoring of the dustbin’s fill level, sends alerts to the appropriate authorities, and provides location data for efficient waste management. The integration of these components not only enhances waste collection practices but also contributes to building smarter and more sustainable cities. With further advancements in IoT technology, the possibilities for optimizing waste management are endless.
More Project
i want to know about the connections of GPS module.
ok
i want to know the code for real time website and how to get sms alert