Society dustbin full-level reporter
Build it step by step
0 of 7 doneTest the sensor
Print the distance in the serial monitor.
Calibrate
Note the empty and full distances.
Report over Wi-Fi
Send the percentage to a test page.
Add deep sleep
Wake every 30 minutes.
Run the collector
Show all bins in one table.
Add the battery
TP4056, cell and regulator.
Mount it
Under the lid in a sealed box.
How do you build a society dustbin full-level reporter?
An ultrasonic sensor in a building's dustbin reports how full it is, so the housekeeping team empties it before it overflows. You need ESP32 DevKit V1, HC-SR04 Ultrasonic Sensor, 18650 cell 2600 mAh (branded), Battery holder 18650 single, TP4056 module with protection (USB-C), HT7333 low quiescent LDO, Resistor 1 kΩ, Resistor 4.7 kΩ and Electrolytic Capacitor 100 µF. It takes 7 steps and about 150 minutes.
- Level
- Intermediate
- Time
- About 150 min
- Parts
- 9
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuy
- BatteriesBuy
- PowerBuy
- PowerBuy
- Power
- PassivesBuyResistor 1 kΩ × 1
- PassivesBuyResistor 4.7 kΩ × 1
- PassivesBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| 18650 cell | Holder, then TP4056 B+ and B− | Charge and protect (use a protected cell) |
| TP4056 OUT+ and OUT− | HT7333 input and GND | Battery supply |
| HT7333 output | ESP32 3V3 pin | 3.3 V supply (see the note on current) |
| 100 µF capacitor | Across the HT7333 output and GND | Smooths radio bursts |
| HC-SR04 VCC | TP4056 OUT+ (battery 3.7 V works for most modules) | Sensor power (check yours) |
| HC-SR04 TRIG | ESP32 GPIO5 | Trigger |
| HC-SR04 ECHO | 1 kΩ to GPIO18, 4.7 kΩ from GPIO18 to GND | Divider for the echo pulse |
Code
The ESP32 wakes every 30 minutes, measures the distance to the rubbish with the ultrasonic sensor under the lid, sends a percentage to a small collector page and goes back to deep sleep, so a cell can last months. Measure the distance when the bin is empty and when full and set the two constants. The HT7333 regulator can supply only about 250 mA, and the ESP32's Wi-Fi bursts can briefly pull more, which may cause resets; the 100 µF capacitor helps, but a regulator rated for 500 mA or more is a safer choice. The HC-SR04 may not read well on 3.7 V, so use a 3.3 V ultrasonic module (such as the HC-SR04P) if yours is unreliable. Put the sensor under the lid in a sealed box, away from wet waste, and keep the cell and charger board in a dry compartment away from heat. The collector has no password, so keep it on the building's private network. Fill in the Wi-Fi placeholders yourself. Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module".
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Dustbin level reporter: wake, measure, send, sleep. Board: ESP32 Dev Module. No extra libraries.
#include <WiFi.h>
#include <HTTPClient.h>
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const char* SERVER = "http://192.168.1.50:5000/report"; // your collector, see the notes
const char* BIN_NAME = "Block-A-ground";
const int EMPTY_CM = 80, FULL_CM = 12; // distance to the bottom when empty and to the lid when full (measure yours)
const int TRIG = 5, ECHO = 18;
#define SLEEP_MIN 30
float readCm() {
float best = 0; int ok = 0, total = 0;
for (int i = 0; i < 5; i++) { // take five readings and average the good ones
digitalWrite(TRIG, LOW); delayMicroseconds(2);
digitalWrite(TRIG, HIGH); delayMicroseconds(10); digitalWrite(TRIG, LOW);
long us = pulseIn(ECHO, HIGH, 30000);
if (us > 0) { best += us / 58.0; ok++; }
total++; delay(60);
}
return ok ? best / ok : -1;
}
void setup() {
pinMode(TRIG, OUTPUT); pinMode(ECHO, INPUT);
float cm = readCm();
int percent = -1;
if (cm > 0) percent = constrain((int)(100.0 * (EMPTY_CM - cm) / (EMPTY_CM - FULL_CM)), 0, 100);
WiFi.begin(WIFI_SSID, WIFI_PASS);
unsigned long t0 = millis();
while (WiFi.status() != WL_CONNECTED && millis() - t0 < 10000) delay(200);
if (WiFi.status() == WL_CONNECTED && percent >= 0) {
HTTPClient http;
http.begin(String(SERVER) + "?bin=" + BIN_NAME + "&percent=" + percent);
http.GET();
http.end();
}
WiFi.disconnect(true);
esp_sleep_enable_timer_wakeup((uint64_t)SLEEP_MIN * 60ULL * 1000000ULL);
esp_deep_sleep_start(); // sleep until the next reading
}
void loop() {}
/* A tiny collector for your home computer or Pi. Save as collector.py, run: python3 collector.py
Install first: pip install flask
from flask import Flask, request, render_template_string
import time
app = Flask(__name__)
bins = {}
@app.route("/report")
def report():
bins[request.args["bin"]] = (int(request.args["percent"]), time.strftime("%H:%M"))
return "ok"
@app.route("/")
def show():
rows = "".join("<tr><td>%s</td><td style='color:%s'>%d%%</td><td>%s</td></tr>" % (n, "red" if p > 80 else "black", p, t) for n, (p, t) in sorted(bins.items()))
return "<table border=1><tr><th>Bin</th><th>Full</th><th>Updated</th></tr>" + rows + "</table>"
app.run(host="0.0.0.0", port=5000)
*/What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
[deep sleep for 30 min 0 s]
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Empty bin | Close to 0 percent |
| Full bin | Close to 100 percent |
| Table page | Shows the bin with the time |
| Above 80 percent | Number shows in red |
If it does not work
Reads always out of range
Check the echo divider and the supply voltage.
Resets while sending
Add capacitance or a stronger regulator.
Wrong percentage
Re-measure the empty and full distances.
No data on the page
Check the server address and that the PC is on the same network.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the society dustbin full-level reporter?
ESP32 DevKit V1, HC-SR04 Ultrasonic Sensor, 18650 cell 2600 mAh (branded), Battery holder 18650 single, TP4056 module with protection (USB-C), HT7333 low quiescent LDO, Resistor 1 kΩ, Resistor 4.7 kΩ and Electrolytic Capacitor 100 µF.
How long does the society dustbin full-level reporter take to build?
About 150 minutes for a intermediate maker, in 7 steps.
How do I know the society dustbin full-level reporter works?
Empty bin: Close to 0 percent. Full bin: Close to 100 percent. Table page: Shows the bin with the time.
Reads always out of range: what should I check?
Check the echo divider and the supply voltage.
Resets while sending: what should I check?
Add capacitance or a stronger regulator.
Wrong percentage: what should I check?
Re-measure the empty and full distances.
No data on the page: what should I check?
Check the server address and that the PC is on the same network.
