amc:ss2025:group-t:start
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| amc:ss2025:group-t:start [2025/07/29 01:05] – removed emir-talha.fidan | amc:ss2025:group-t:start [2025/07/29 21:59] (current) – emir-talha.fidan | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Smart Trash Bin Monitoring System ====== | ||
| + | |||
| + | **Emir Talha Fidan (32780)** | ||
| + | **Ilker Bakikol (31706)** | ||
| + | |||
| + | ====== 1. Introduction ====== | ||
| + | '' | ||
| + | Every year, inefficient waste-collection leads to unnecessary pickups, added CO₂ emissions, and overflowing public bins. Our **Smart Trash-Bin Fill-Level Monitoring System** uses a VL53L0X Time-of-Flight sensor mounted inside a 41 × 35 × 60 cm³ bin to measure the fill height, displays the percentage full on an SH1106 OLED, and—when a user-configurable threshold is exceeded—sends alerts via a Telegram bot. | ||
| + | |||
| + | |||
| + | |||
| + | This document walks through each step—hardware assembly (breadboard layout), Arduino IDE firmware, Node-RED flow, Telegram-bot config, and ESP32 simulation—so you can reproduce and extend the system today, then evolve it for outdoor use tomorrow. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ====== 2. Materials & System Overview ====== | ||
| + | '' | ||
| + | |||
| + | ==== 2.1. Hardware Components ==== | ||
| + | ^ Component | ||
| + | | ESP32-S3-DevKitC-1 | ||
| + | | VL53L0X ToF sensor | ||
| + | | SH1106 128×64 I²C OLED (U8g2 lib) | Displays distance (cm) & fill (%) | | ||
| + | | LED (GPIO 2) | Visual “almost full” warning | ||
| + | | Powerbank (5 V USB) | Supplies 5 V to ESP32 for portable operation | ||
| + | | Wires, breadboard, connectors | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 2.2. Software Components ==== | ||
| + | * **Arduino IDE** (v2.x) | ||
| + | * **Libraries** | ||
| + | ** * Adafruit_VL53L0X – Time-of-Flight sensor | ||
| + | ** * U8g2lib – SH1106 OLED driver | ||
| + | ** * WiFi.h / HTTPClient.h – Wi-Fi & HTTP POST | ||
| + | ** * UniversalTelegramBot.h – Telegram Bot API | ||
| + | * **Node-RED** (v3.x) on 192.168.10.50: | ||
| + | * **Telegram Bot** (“TrashAlertBot”) configured with token `xxxx:YYYY` and chat ID | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ====== 3. Hardware Assembly ====== | ||
| + | '' | ||
| + | |||
| + | ==== 3.1. Breadboard Layout ==== | ||
| + | * **ESP32**: VIN ← 5 V (from powerbank USB→5 V regulator), GND ← GND, SDA ← GPIO 8, SCL ← GPIO 9. | ||
| + | * **VL53L0X**: | ||
| + | * **OLED (SH1106)**: VCC ← 3.3 V, GND ← GND, SDA/SCL as belove. | ||
| + | * **LED**: Anode ← GPIO 2 (with 220 Ω resistor), Cathode ← GND. | ||
| + | *All I²C peripherals (ToF sensor, OLED) share ESP32’s **SDA**/ | ||
| + | * Secure ToF sensor at bin’s top interior, facing directly downward without obstruction. | ||
| + | * Mount OLED on exterior lid for clear visibility. | ||
| + | * Use onboard LED—no additional external LED wiring. | ||
| + | * ESP32 uses internal antenna for Wi-Fi; no extra antennas needed. | ||
| + | {{: | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ====== 4. Arduino IDE Firmware ====== | ||
| + | '' | ||
| + | Below is the main sketch. **Please replace** `YOUR_SSID`, | ||
| + | |||
| + | <code cpp> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | #define I2C_SDA 8 | ||
| + | #define I2C_SCL 9 | ||
| + | #define LED_PIN 2 | ||
| + | |||
| + | #define BIN_HEIGHT_CM 60.0 | ||
| + | #define DISTANCE_OFFSET_CM -3.0 | ||
| + | |||
| + | // Wi-Fi | ||
| + | const char* ssid = " | ||
| + | const char* password | ||
| + | // Node-RED endpoint | ||
| + | const char* alert_url | ||
| + | |||
| + | // Telegram | ||
| + | const char* telegram_token = " | ||
| + | String chat_id = " | ||
| + | |||
| + | U8G2_SH1106_128X64_NONAME_F_HW_I2C display(U8G2_R0, | ||
| + | Adafruit_VL53L0X lox = Adafruit_VL53L0X(); | ||
| + | WiFiClientSecure secured_client; | ||
| + | UniversalTelegramBot bot(telegram_token, | ||
| + | |||
| + | unsigned long lastAlertTime = 0, lastSignalTime = 0; | ||
| + | const unsigned long signalInterval = 30000; | ||
| + | float lastDistance = 0, lastPercentage = 0; | ||
| + | bool updatesEnabled = true; | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(115200); | ||
| + | Wire.begin(I2C_SDA, | ||
| + | // Initialize display | ||
| + | display.begin(); | ||
| + | display.clearBuffer(); | ||
| + | display.setFont(u8g2_font_ncenB08_tr); | ||
| + | display.drawStr(0, | ||
| + | display.sendBuffer(); | ||
| + | // Initialize sensor | ||
| + | if (!lox.begin()) while (1); | ||
| + | pinMode(LED_PIN, | ||
| + | // Connect Wi-Fi | ||
| + | WiFi.begin(ssid, | ||
| + | while (WiFi.status() != WL_CONNECTED) { | ||
| + | delay(500); | ||
| + | Serial.print(' | ||
| + | } | ||
| + | Serial.println(" | ||
| + | secured_client.setInsecure(); | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | VL53L0X_RangingMeasurementData_t m; | ||
| + | lox.rangingTest(& | ||
| + | if (m.RangeStatus != 4) { | ||
| + | float d = m.RangeMilliMeter/ | ||
| + | float p = constrain(100.0 - (d/ | ||
| + | lastDistance = d; lastPercentage = p; | ||
| + | // Update OLED | ||
| + | display.clearBuffer(); | ||
| + | display.setCursor(0, | ||
| + | display.print(" | ||
| + | display.setCursor(0, | ||
| + | display.print(" | ||
| + | int w = map((int)p, | ||
| + | display.drawFrame(0, | ||
| + | display.drawBox(0, | ||
| + | display.sendBuffer(); | ||
| + | // Alert on ≥80% | ||
| + | if (p >= 80.0) { | ||
| + | digitalWrite(LED_PIN, | ||
| + | if (millis() - lastAlertTime > 15000) { | ||
| + | sendWarning(d, | ||
| + | lastAlertTime = millis(); | ||
| + | } | ||
| + | } else { | ||
| + | digitalWrite(LED_PIN, | ||
| + | } | ||
| + | } | ||
| + | // Periodic update | ||
| + | if (millis() - lastSignalTime > signalInterval) { | ||
| + | if (updatesEnabled) sendRegularUpdate(lastDistance, | ||
| + | lastSignalTime = millis(); | ||
| + | } | ||
| + | // Telegram commands | ||
| + | static unsigned long lastBot = 0; | ||
| + | if (millis() - lastBot > 1000) { | ||
| + | int n = bot.getUpdates(bot.last_message_received + 1); | ||
| + | while (n) { | ||
| + | handleNewMessages(n); | ||
| + | n = bot.getUpdates(bot.last_message_received + 1); | ||
| + | } | ||
| + | lastBot = millis(); | ||
| + | } | ||
| + | delay(500); | ||
| + | } | ||
| + | |||
| + | // ... (sendWarning, | ||
| + | </ | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | |||
| + | ===== Code Summary ===== | ||
| + | |||
| + | 1. **Initialization (setup)** | ||
| + | - Serial debug +< | ||
| + | - < | ||
| + | - Connect to Wi-Fi (SSID/ | ||
| + | - Initialize HTTPClient & Telegram bot | ||
| + | - On failure (sensor or Wi-Fi), print/ | ||
| + | |||
| + | 2. **Main Loop** | ||
| + | - Ranging measurement via < | ||
| + | - If valid, calculate | ||
| + | `fill % = ((BIN_HEIGHT_CM − distance_cm) / BIN_HEIGHT_CM) × 100` | ||
| + | - Update OLED: distance, fill %, bar graph | ||
| + | - LED Alert: ON if ≥ 80 %, OFF if below (with hysteresis) | ||
| + | - HTTP POST to Node-RED every 30 s | ||
| + | - Telegram: one-time warning on threshold cross; optional periodic updates | ||
| + | - Handle Telegram commands (< | ||
| + | - Delay to regulate loop frequency | ||
| + | |||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | |||
| + | |||
| + | ====== 5. Node-RED Flow ====== | ||
| + | '' | ||
| + | Our Node-RED instance handles incoming HTTP POSTs at `/ | ||
| + | |||
| + | * Parses JSON (distance, fill_percentage) | ||
| + | * Switch: if `fill_percentage ≥ 80` → trigger email/SMS, else log | ||
| + | * Dashboard: updates a gauge node | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ====== 6. Telegram Bot Configuration ====== | ||
| + | '' | ||
| + | * Create bot with BotFather → get `BOT_TOKEN`. | ||
| + | * Invite to your group/ | ||
| + | * Grant it message-reading rights. | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| + | | ||
| + | {{: | ||
| + | |||
| + | |||
| + | **Commands**: | ||
| + | * /start - Start bot | ||
| + | * /status - Get current bin fill | ||
| + | * /stop - Stop regular update messages | ||
| + | * / | ||
| + | * /help - Show this message | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | ====== 7. Results ====== | ||
| + | '' | ||
| + | * **OLED display**: real-time distance & fill bar (tested up to 85%). | ||
| + | * **LED**: lights when fill ≥ 80%. | ||
| + | * **Telegram**: | ||
| + | * **Node-RED dashboard**: | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | * **Distance & Fill Readout** | ||
| + | - OLED updates in real time: | ||
| + | * “Distance: | ||
| + | * “Fill: 63 %” | ||
| + | - Fill percentage = ((60 cm − measured_distance) / 60 cm) × 100 %. | ||
| + | |||
| + | * **Visual & Remote Alerts** | ||
| + | - At ≥ 80 % capacity (trash within ~12 cm of lid): | ||
| + | * Onboard LED lights (e.g., red). | ||
| + | * Node-RED receives JSON payload: | ||
| + | < | ||
| + | * Telegram message: “⚠ Alert: The kitchen trash bin is 85 % full. Please empty it soon.” | ||
| + | - Regular status updates (e.g., every 30 s) are also sent. | ||
| + | - On sensor error, OLED shows “Sensor error” and that cycle’s data is skipped; an error flag can be forwarded. | ||
| + | |||
| + | |||
| + | ---- | ||
| + | {{ : | ||
| + | {{: | ||
| + | {{: | ||
| + | ---- | ||
| + | |||
| + | ====== 8. Discussion & Lessons Learned ====== | ||
| + | '' | ||
| + | * **Portable power**: using a USB powerbank delivers ~8 hrs runtime; for longer operation, a solar-powered Li-Po pack is recommended. | ||
| + | * **Connectivity**: | ||
| + | * **Enclosure**: | ||
| + | * **Sleep modes**: ESP32 deep-sleep between measurements can drastically reduce power draw. | ||
| + | * **Multi-sensor**: | ||
| + | * **Predictive analytics**: | ||
| + | * **Firmware OTA**: integrate over-the-air updates for remote code maintenance. | ||
| + | * **Scalability**: | ||
| + | |||
| + | * **Limitations** | ||
| + | * Single-point ToF measurement may miss uneven trash piles. | ||
| + | * Reliance on Wi-Fi: network outages disrupt remote updates. | ||
| + | * Continuous power requirement; | ||
| + | |||
| + | * **Improvements** | ||
| + | * Multiple sensors or servo-mounted scanning for holistic fill measurement. | ||
| + | * Offline data buffering and reconnection logic for network resilience. | ||
| + | * Deep-sleep between measurements for battery operation. | ||
| + | |||
| + | * **Future Enhancements** | ||
| + | * A GPS module (for geo-tagged alerts) | ||
| + | * A solar-rechargeable Li-Po power supply (with charge controller) | ||
| + | * A weatherproof 3D-printed enclosure | ||
| + | * Load cell weight sensor for complementary metrics. | ||
| + | * Audible buzzer for local full-bin alarms. | ||
| + | * Expanded Node-RED flows: email notifications, | ||
| + | * Interactive Telegram bot commands for on-demand status. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ====== 9. Conclusion ====== | ||
| + | '' | ||
| + | |||
| + | Deploying multiple units in smart buildings or campuses enables optimized waste collection scheduling, reduces overflow incidents, and contributes to smarter urban infrastructure by leveraging low-cost sensors and Wi-Fi connectivity. This project demonstrates a practical IoT solution for everyday problems, with clear pathways for scaling and enhancement. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ====== 10. References ====== | ||
| + | '' | ||
| + | * **STMicroelectronics VL53L0X Datasheet** | ||
| + | * **U8g2 SH1106 OLED driver** – https:// | ||
| + | * **UniversalTelegramBot Library** – https:// | ||
| + | * **Node-RED Documentation** – https:// | ||
| + | |||
| + | |||
| + | {{youtube> | ||
amc/ss2025/group-t/start.1753743955.txt.gz · Last modified: 2025/07/29 01:05 by emir-talha.fidan