Smart Waste Management System Using Arduino Nano, Ultrasonic Sensor & GSM Module – Solar Powered IoT Solution
Smart Waste Management System – Arduino Nano, HC-SR04 & GSM
Solar-powered IoT dustbin that monitors fill level in real time and sends an SMS alert via GSM when waste crosses 80% — full code, wiring & simulation.
Project Overview
This IoT project transforms an ordinary dustbin into a smart bin that monitors its fill level autonomously. An HC-SR04 ultrasonic sensor measures the distance from the lid to the garbage surface. The Arduino Nano converts this into a fill percentage and triggers LED indicators, a buzzer, and a GSM SMS alert as thresholds are crossed.
Ultrasonic Sensing
HC-SR04 measures garbage distance every 60 seconds. Formula: Distance = (Duration × 0.034) / 2
GSM SMS Alert
SIM800/SIM900 sends an SMS to the waste authority when fill level ≥ 80%.
Solar Powered
Solar panel + Li-ion battery + buck converter for 24/7 autonomous, off-grid operation.
LED Indicators
Green / Yellow / Red LEDs give instant visual feedback on bin fill status at a glance.
Components List
Wiring Diagram
Pin Reference Table
| Module | Module Pin | Arduino Nano Pin | Notes |
|---|---|---|---|
| HC-SR04 | VCC | 5V | |
| HC-SR04 | GND | GND | |
| HC-SR04 | TRIG | D2 | Output from Arduino |
| HC-SR04 | ECHO | D3 | Input to Arduino |
| GSM (SIM800/900) | TX | D4 (SoftSerial RX) | GSM TX → Nano D4 |
| GSM (SIM800/900) | RX | D5 (SoftSerial TX) | Use voltage divider for 3.3V GSM |
| GSM (SIM800/900) | VCC | 4V (external) | SIM800 needs 3.7–4.2V, 2A — use separate regulator |
| Buzzer | + | D6 | Active buzzer |
| Green LED + 220Ω | Anode | D7 | Cathode → GND |
| Yellow LED + 220Ω | Anode | D8 | Cathode → GND |
| Red LED + 220Ω | Anode | D9 | Cathode → GND |
| Buck Converter Out | 5V OUT | VIN | Powers entire system |
Working Logic
The system uses two core calculations. First, distance is measured by timing the echo pulse. Second, distance is inverted into a fill percentage using Arduino's map() function.
Decision Flow
| Condition | Green LED | Yellow LED | Red LED | Buzzer | SMS |
|---|---|---|---|---|---|
fillLevel ≤ 50 | ✅ ON | ❌ OFF | ❌ OFF | ❌ OFF | ❌ No |
fillLevel 51–79 | ❌ OFF | ✅ ON | ❌ OFF | ❌ OFF | ❌ No |
fillLevel ≥ 80 | ❌ OFF | ❌ OFF | ✅ ON | ✅ ON | ✅ Sent! |
delay(5000) temporarily.Interactive Bin Simulator
🗑️ Drag the slider to simulate fill level
GSM SMS Alert Setup
The system sends SMS via AT commands over SoftwareSerial. Three commands are chained together:
+91xxxxxxxxxx with your real number in E.164 format.Step-by-Step: Configuring the GSM Module
| # | Action |
|---|---|
| 1 | Insert an active SIM card (voice + data plan, SMS enabled) into the SIM800/SIM900 slot. |
| 2 | Power GSM from a dedicated 4V / 2A supply — NOT from Arduino's 5V pin. |
| 3 | Check for a steady 1-second blink on the module's NET LED — this confirms network registration. |
| 4 | Replace +91xxxxxxxxxx in the code with your authority's phone number. |
| 5 | Upload code and open Serial Monitor at 9600 baud — on startup you should see "Smart Waste Management System Initialized" and an SMS sent. |
| 6 | Cover the HC-SR04 with your hand to simulate a full bin. When distance < 6 cm (80% of 30 cm bin), the red LED, buzzer and SMS will trigger. |
sendSMS() function is called inside the ≥80% condition with a 60-second delay. In production, add a sent flag (bool smsSent = false;) to prevent repeated SMS every minute when the bin stays full.Solar Power System
The system runs 24/7 without mains power using a solar-charged lithium battery with a buck converter for stable 5V output.
Full Arduino Code
Update binHeight to your actual dustbin depth in centimetres, and replace the phone number with your authority's number before uploading.
#include <SoftwareSerial.h> #define TRIG_PIN 2 // Ultrasonic Trigger #define ECHO_PIN 3 // Ultrasonic Echo #define GSM_TX 4 // SoftSerial RX ← GSM TX #define GSM_RX 5 // SoftSerial TX → GSM RX #define BUZZER_PIN 6 // Buzzer #define GREEN_LED 7 // Green LED (0–50%) #define YELLOW_LED 8 // Yellow LED (50–80%) #define RED_LED 9 // Red LED (80%+) SoftwareSerial gsm(GSM_RX, GSM_TX); // RX=D5, TX=D4 const int binHeight = 30; // ← Set your bin depth in cm long duration; int distance, fillLevel; bool smsSent = false; // prevents repeated SMS while full void setup() { pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT); pinMode(BUZZER_PIN, OUTPUT); pinMode(GREEN_LED, OUTPUT); pinMode(YELLOW_LED, OUTPUT); pinMode(RED_LED, OUTPUT); Serial.begin(9600); gsm.begin(9600); // Startup confirmation SMS sendSMS("Smart Waste Management System Initialized"); delay(2000); } void loop() { // ── Measure distance ── digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2); digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW); duration = pulseIn(ECHO_PIN, HIGH); distance = duration * 0.034 / 2; // cm fillLevel = map(distance, 0, binHeight, 100, 0); // % fillLevel = constrain(fillLevel, 0, 100); // clamp Serial.print("Distance: "); Serial.print(distance); Serial.print(" cm | Fill: "); Serial.print(fillLevel); Serial.println("%"); // ── Update LEDs and alerts ── if (fillLevel <= 50) { digitalWrite(GREEN_LED, HIGH); digitalWrite(YELLOW_LED, LOW); digitalWrite(RED_LED, LOW); digitalWrite(BUZZER_PIN, LOW); smsSent = false; // reset flag when bin is emptied Serial.println("Status: OK — Under 50%"); } else if (fillLevel > 50 && fillLevel < 80) { digitalWrite(GREEN_LED, LOW); digitalWrite(YELLOW_LED, HIGH); digitalWrite(RED_LED, LOW); digitalWrite(BUZZER_PIN, LOW); smsSent = false; Serial.println("Status: Warning — 50–80%"); } else if (fillLevel >= 80) { digitalWrite(GREEN_LED, LOW); digitalWrite(YELLOW_LED, LOW); digitalWrite(RED_LED, HIGH); digitalWrite(BUZZER_PIN, HIGH); Serial.println("Status: FULL — Alert!"); if (!smsSent) { // send only once per fill event sendSMS("Bin is 80% full. Please empty."); smsSent = true; } } delay(60000); // read every 60 seconds (change to 5000 for testing) } // ── GSM SMS function ── void sendSMS(String message) { gsm.print("AT+CMGF=1\r"); // Text mode delay(100); gsm.print("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // ← Your number delay(100); gsm.print(message); delay(100); gsm.write(26); // Ctrl+Z = send delay(1000); }
constrain() and a smsSent flag improvement over the original — prevents SMS spam if the bin stays full across multiple readings.Online Simulation
▶ Try it in Wokwi or CirkitDesigner
Simulate the full circuit online — control the HC-SR04 distance value and watch LEDs and buzzer respond. GSM behaviour can be verified via Serial Monitor.
Open Wokwi Open CirkitDesignerSimulation Steps
| # | Step |
|---|---|
| 1 | Go to Wokwi, start a new Arduino Nano project. |
| 2 | Paste the diagram.json above to auto-add HC-SR04, 3 LEDs with resistors, and buzzer. |
| 3 | Paste the code into sketch.ino. Change delay(60000) to delay(2000) for faster simulation. |
| 4 | Click ▶ Start Simulation. Open Serial Monitor to see fill percentages. |
| 5 | Click the HC-SR04 in the simulator and drag the distance slider. Set to 5 cm → bin reports ~83% full → Red LED + buzzer activate. |
| 6 | Set distance to 20 cm → ~33% full → Green LED on. Set to 12 cm → ~60% → Yellow LED on. |
| 7 | For CirkitDesigner: add SIM800 component for full GSM SMS simulation of the alert message. |
Applications & Upgrades
Possible Upgrades
IoT Cloud Dashboard
Swap GSM for ESP8266 — push fill data to ThingSpeak or Blynk for a live web dashboard.
GPS Location
Add a GPS module to report the exact bin location in the SMS for smart route planning.
Odour / Gas Sensor
Add MQ-135 to detect methane from decomposing waste and trigger early alerts.
Mobile App
Build a Flutter/React Native app that receives push notifications from multiple smart bins on a map.
Comments
Post a Comment