Skip to main content

Smart Waste Management System Using Arduino Nano, Ultrasonic Sensor & GSM Module – Solar Powered IoT Solution

Smart Waste Management System – Arduino Nano, HC-SR04 & GSM | MakeMindz
♻️ Smart City IoT

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.

Arduino Nano HC-SR04 SIM800 / SIM900 Solar Powered SMS Alert Smart City IoT Beginner–Intermediate
0 – 50%
🟢 Green LED ON
Buzzer OFF · No SMS
50 – 80%
🟡 Yellow LED ON
Buzzer OFF · No SMS
80%+
🔴 Red LED ON
Buzzer ON · 📱 SMS Sent!
1

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.

2

Components List

🔷
Arduino Nano
ATmega328P, 5V
×1
🔊
HC-SR04
Ultrasonic sensor
×1
📡
SIM800 / SIM900
GSM module + SIM
×1
☀️
Solar Panel
5V–6V, 1W–3W
×1
🔋
Li-ion Battery
3.7V / 18650
×1
Buck Converter
MP1584 / LM2596
×1
🔔
Buzzer
5V active buzzer
×1
🔴
LEDs (R/Y/G)
+ 220Ω resistors
×3
🔌
Jumper Wires
M-to-F assorted
×12+
📦
Only SoftwareSerial (built-in) is required. No additional libraries needed. GSM uses AT commands over serial.
3

Wiring Diagram

ARDUINO NANO D2 (TRIG) ● D3 (ECHO) ● D4 (GSM TX) ● D5 (GSM RX) ● D6 (BUZZER) ● D7 (GREEN) ● D8 (YELLOW) ● D9 (RED) ● ● 5V ● GND ATmega328P MINI USB HC-SR04 Ultrasonic Sensor Tx Rx VCC ● GND ● ● TRIG ● ECHO SIM800 / SIM900 GSM Module SIM CARD VCC ● GND ● ● TX ● RX D4→GSM TX STATUS LEDs + BUZZER GREEN D7 YELLOW D8 RED D9 🔔 BUZZER — D6 POWER SYSTEM ☀️ Solar 6V 🔋 Li-ion ⚡ Buck Conv → 5V LEGEND Ultrasonic GSM serial LEDs Buzzer GND / Power

Pin Reference Table

ModuleModule PinArduino Nano PinNotes
HC-SR04VCC5V
HC-SR04GNDGND
HC-SR04TRIGD2Output from Arduino
HC-SR04ECHOD3Input to Arduino
GSM (SIM800/900)TXD4 (SoftSerial RX)GSM TX → Nano D4
GSM (SIM800/900)RXD5 (SoftSerial TX)Use voltage divider for 3.3V GSM
GSM (SIM800/900)VCC4V (external)SIM800 needs 3.7–4.2V, 2A — use separate regulator
Buzzer+D6Active buzzer
Green LED + 220ΩAnodeD7Cathode → GND
Yellow LED + 220ΩAnodeD8Cathode → GND
Red LED + 220ΩAnodeD9Cathode → GND
Buck Converter Out5V OUTVINPowers entire system
⚠️
GSM Power: SIM800/SIM900 draws up to 2A peak during transmission. Never power it from the Arduino's 5V pin — use a dedicated 3.7V–4.2V supply or buck converter output directly. Brownouts will cause resets.
4

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.

// 1. Distance measurement
duration = pulseIn(ECHO_PIN, HIGH);
distance = duration × 0.034 / 2; // cm

// 2. Fill % (0cm = full, binHeight = empty)
fillLevel = map(distance, 0, binHeight, 100, 0);

// binHeight = 30 cm (adjust for your actual bin)

Decision Flow

ConditionGreen LEDYellow LEDRed LEDBuzzerSMS
fillLevel ≤ 50✅ ON❌ OFF❌ OFF❌ OFF❌ No
fillLevel 51–79❌ OFF✅ ON❌ OFF❌ OFF❌ No
fillLevel ≥ 80❌ OFF❌ OFF✅ ON✅ ON✅ Sent!
⏱️
The loop runs a 60-second delay between readings to save power and prevent SMS flooding. For testing, reduce to delay(5000) temporarily.
5

Interactive Bin Simulator

🗑️ Drag the slider to simulate fill level

🔊
HC-SR04
30%
Fill Level30%
Distance (cm)21 cm
LED Status Green ON
BuzzerOFF
SMS AlertNo
Garbage fill level: 30%
📱 SMS Sent: "Bin is 80% full. Please empty." → +91xxxxxxxxxx
6

GSM SMS Alert Setup

The system sends SMS via AT commands over SoftwareSerial. Three commands are chained together:

AT+CMGF=1
Set SMS text mode (instead of PDU). Must be sent before every message session.
AT+CMGS="…"
Set the destination phone number. Replace +91xxxxxxxxxx with your real number in E.164 format.
gsm.write(26)
ASCII code 26 = Ctrl+Z — signals end of SMS body and triggers the send.

Step-by-Step: Configuring the GSM Module

#Action
1Insert an active SIM card (voice + data plan, SMS enabled) into the SIM800/SIM900 slot.
2Power GSM from a dedicated 4V / 2A supply — NOT from Arduino's 5V pin.
3Check for a steady 1-second blink on the module's NET LED — this confirms network registration.
4Replace +91xxxxxxxxxx in the code with your authority's phone number.
5Upload code and open Serial Monitor at 9600 baud — on startup you should see "Smart Waste Management System Initialized" and an SMS sent.
6Cover 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.
⚠️
The 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.
7

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.

☀️
Solar Panel
5V–6V · 1–3W
🔋
Li-ion Battery
3.7V · 18650
Buck Converter
Out: 5V · 2A
🔷
Arduino Nano
VIN · 5V rail
+
📡
GSM (4V tap)
Separate reg
💡
Add a TP4056 solar charging module between the solar panel and Li-ion battery for safe overcharge protection. This makes the system truly field-deployable.
8

Full Arduino Code

Update binHeight to your actual dustbin depth in centimetres, and replace the phone number with your authority's number before uploading.

Arduino / C++
#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);
}
The code above adds constrain() and a smsSent flag improvement over the original — prevents SMS spam if the bin stays full across multiple readings.
10

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 CirkitDesigner

Simulation Steps

#Step
1Go to Wokwi, start a new Arduino Nano project.
2Paste the diagram.json above to auto-add HC-SR04, 3 LEDs with resistors, and buzzer.
3Paste the code into sketch.ino. Change delay(60000) to delay(2000) for faster simulation.
4Click ▶ Start Simulation. Open Serial Monitor to see fill percentages.
5Click the HC-SR04 in the simulator and drag the distance slider. Set to 5 cm → bin reports ~83% full → Red LED + buzzer activate.
6Set distance to 20 cm → ~33% full → Green LED on. Set to 12 cm → ~60% → Yellow LED on.
7For CirkitDesigner: add SIM800 component for full GSM SMS simulation of the alert message.
11

Applications & Upgrades

🏙️Smart City bins
🏗️Construction sites
🏥Hospital waste
🚉Railway stations
🏠Apartments
🏫Smart campus
🏭Industrial bins
🎓Diploma projects

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.

© 2026 MakeMindz.com · Arduino, ESP32 & IoT Project Tutorials

Comments

try for free