User Tools

Site Tools


amc:ss2025:group-t:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
amc:ss2025:group-t:start [2025/07/29 01:04] – created emir-talha.fidanamc:ss2025:group-t:start [2025/07/29 21:59] (current) emir-talha.fidan
Line 1: Line 1:
-STDOUT/STDERR +====== Smart Trash Bin Monitoring System ======
-# 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. For outdoor deployment, we’ve upgraded the setup with:+
  
-- A different Wi-Fi server (Node-RED on 192.168.10.50  +**Emir Talha Fidan (32780)** 
-- A GPS module (for geo-tagged alerts  +**Ilker Bakikol (31706)**
-- A solar-rechargeable Li-Po power supply   +
-- A 3D-printed, weatherproof enclosure  +
  
-This document walks through each step—hardware assembly (breadboard layout)Arduino IDE firmware, Node-RED flowTelegram-bot config, and ESP32 simulationso you can reproduce and extend the system yourself.+====== 1. Introduction ======   
 +''By 32780'' 
 +Every yearinefficient waste-collection leads to unnecessary pickupsadded 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 
  
-# 2. Materials & System Overview 
  
-## 2.1. Hardware Components + 
-Component                         Purpose                                                                         +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 ======  
 +''By 32780'' 
 + 
 +==== 2.1. Hardware Components ==== 
 +Component                         Purpose                                                                         ^
 | ESP32-S3-DevKitC-1                | Main MCU, Wi-Fi, GPIOs                                                          | | ESP32-S3-DevKitC-1                | Main MCU, Wi-Fi, GPIOs                                                          |
 | VL53L0X ToF sensor                | Measures distance from bin top to contents                                      | | VL53L0X ToF sensor                | Measures distance from bin top to contents                                      |
 | SH1106 128×64 I²C OLED (U8g2 lib) | Displays distance (cm) & fill (%)                                               | | SH1106 128×64 I²C OLED (U8g2 lib) | Displays distance (cm) & fill (%)                                               |
 | LED (GPIO 2)                      | Visual “almost full” warning                                                    | | LED (GPIO 2)                      | Visual “almost full” warning                                                    |
-GPS module (e.g. NEO-6M         Provides latitude/longitude for outdoor alerts                                  | +Powerbank (5 V USB              Supplies 5 V to ESP32 for portable operation                                    |
-| Li-Po battery + solar charge IC   | Outdoor power source; charges from solar panel                                  | +
-| 3D-printed enclosure              | Weatherproof housing with mounting points for sensor, display, solar panel       |+
 | Wires, breadboard, connectors     | Prototyping and wiring                                                           | | Wires, breadboard, connectors     | Prototyping and wiring                                                           |
  
-*(ℹ️ Please confirm the GPS module part number and its RX/TX pin mapping so I can update the wiring diagram precisely.)*+{{:amc:ss2025:group-t:pxl_20250729_115627332.jpg?400|}} 
 + 
 +----
  
-## 2.2. Software Components +==== 2.2. Software Components ==== 
-**Arduino IDE** (v2.x)   +  **Arduino IDE** (v2.x)   
-**Libraries**  +  **Libraries**   
-  - `Adafruit_VL53L0X– Time-of-Flight sensor   +    **  Adafruit_VL53L0X – Time-of-Flight sensor   
-  - `U8g2lib– SH1106 OLED driver   +    **  U8g2lib – SH1106 OLED driver   
-  - `WiFi.h`HTTPClient.h– Wi-Fi & HTTP POST   +    **  WiFi.h / HTTPClient.h – Wi-Fi & HTTP POST   
-  - `TinyGPSPlus.h` – GPS parsing   +    **  UniversalTelegramBot.h – Telegram Bot API   
-  - `UniversalTelegramBot.h– Telegram Bot API   +  **Node-RED** (v3.x) on 192.168.10.50:1880 — receives HTTP alerts, dashboards fill percentage, logs events   
-**Node-RED** (v3.x) on 192.168.10.50:1880 — receives HTTP alerts, dashboards fill percentage, logs events   +  **Telegram Bot** (“TrashAlertBot”) configured with token `xxxx:YYYY` and chat ID 
-**Telegram Bot** (“TrashAlertBot”) configured with token `xxxx:YYYY` and chat ID `-1001234567890`+
  
-# 3. Hardware Assembly+----
  
-## 3.1. Breadboard Layout +====== 3. Hardware Assembly ======  
-1. **Power rails**: +5 V from Li-Po-Solar charger to 5 V rail; 3.3 V regulator feeding 3.3 V rail.   +''By 32780''
-2. **ESP32**: VIN ← 5 V, GND ← GND, SDA ← GPIO 8, SCL ← GPIO 9.   +
-3. **VL53L0X**: VCC ← 3.3 V, GND ← GND, SDA/SCL as above.   +
-4. **OLED (SH1106)**: VCC ← 3.3 V, GND ← GND, SDA/SCL as above.   +
-5. **GPS module**:   +
-   - VCC ← 5 V   +
-   - GND ← GND   +
-   - TX ← ESP32 RX (GPIO 16?)   +
-   - RX ← ESP32 TX (GPIO 17?)   +
-   *(ℹ️ Please verify which GPIOs you wired for GPS TX/RX.)*   +
-6. **LED**: Anode ← GPIO 2 (with 330 Ω resistor), Cathode ← GND.  +
  
-<figure>   +==== 3.1. Breadboard Layout ==== 
-  <img src="FIG1_Breadboard_Layout.png" alt="Breadboard layout diagram" /  +  * **ESP32**: VIN ← 5 V (from powerbank USB→5 V regulator), GND ← GND, SDA ← GPIO 8, SCL ← GPIO 9.   
-  <figcaption>Figure 1Breadboard layout schematic.</figcaption>   +  * **VL53L0X**: VCC ← 3.3 V (ESP32 3V3 pin), GND ← GND, SDA/SCL as belove.   
-</figure>+  * **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**/**SCL** pins and 3.3 V/GND rails. 
 +    * 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. 
 +{{:amc:ss2025:group-t:wokwi_arduino.png?400|}}
  
-# 4. Arduino IDE Firmware+----
  
 +====== 4. Arduino IDE Firmware ====== 
 +''By 32780''
 Below is the main sketch. **Please replace** `YOUR_SSID`, `YOUR_PASS`, `NODE_RED_URL`, and `BOT_TOKEN` with your actual credentials. Below is the main sketch. **Please replace** `YOUR_SSID`, `YOUR_PASS`, `NODE_RED_URL`, and `BOT_TOKEN` with your actual credentials.
  
-```cpp+<code cpp>
 #include <Wire.h> #include <Wire.h>
 #include <Adafruit_VL53L0X.h> #include <Adafruit_VL53L0X.h>
Line 67: Line 69:
 #include <WiFi.h> #include <WiFi.h>
 #include <HTTPClient.h> #include <HTTPClient.h>
-#include <TinyGPSPlus.h> 
 #include <UniversalTelegramBot.h> #include <UniversalTelegramBot.h>
  
Line 81: Line 82:
 const char* password   = "YOUR_PASS"; const char* password   = "YOUR_PASS";
 // Node-RED endpoint // Node-RED endpoint
-const char* alert_url  = "http://192.168.10.50:1880/bin-alert"+const char* alert_url  = "http://YOUR_IP_ADDRESS/bin-alert";
- +
-// GPS on Serial1 +
-HardwareSerial gpsSerial(1); +
-TinyGPSPlus gps;+
  
 // Telegram // Telegram
 const char* telegram_token = "BOT_TOKEN"; const char* telegram_token = "BOT_TOKEN";
-String chat_id = "-1001234567890";+String chat_id = "CHAT_ID"; 
  
-U8G2_SH1106_128X64_NONAME_F_HW_I2C display(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, I2C_SCL, I2C_SDA);+U8G2_SH1106_128X64_NONAME_F_HW_I2C display(U8G2_R0, U8X8_PIN_NONE, I2C_SCL, I2C_SDA);
 Adafruit_VL53L0X lox = Adafruit_VL53L0X(); Adafruit_VL53L0X lox = Adafruit_VL53L0X();
 WiFiClientSecure secured_client; WiFiClientSecure secured_client;
Line 98: Line 95:
 unsigned long lastAlertTime = 0, lastSignalTime = 0; unsigned long lastAlertTime = 0, lastSignalTime = 0;
 const unsigned long signalInterval = 30000; const unsigned long signalInterval = 30000;
- 
 float lastDistance = 0, lastPercentage = 0; float lastDistance = 0, lastPercentage = 0;
 bool updatesEnabled = true; bool updatesEnabled = true;
Line 105: Line 101:
   Serial.begin(115200);   Serial.begin(115200);
   Wire.begin(I2C_SDA, I2C_SCL);   Wire.begin(I2C_SDA, I2C_SCL);
 +  // Initialize display
   display.begin();   display.begin();
-  display.clearBuffer(); display.setFont(u8g2_font_ncenB08_tr); +  display.clearBuffer(); 
-  display.drawStr(0,10,"Init Display"); display.sendBuffer(); +  display.setFont(u8g2_font_ncenB08_tr); 
-  if (!lox.begin()) while(1); }+  display.drawStr(0,10,"Init Display"); 
 +  display.sendBuffer(); 
 +  // Initialize sensor 
 +  if (!lox.begin()) while (1);
   pinMode(LED_PIN, OUTPUT);   pinMode(LED_PIN, OUTPUT);
-  gpsSerial.begin(9600, SERIAL_8N1, /*RX*/16, /*TX*/17);+  // Connect Wi-Fi
   WiFi.begin(ssid, password);   WiFi.begin(ssid, password);
-  while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print('.');+  while (WiFi.status() != WL_CONNECTED) { 
-  Serial.println(" +    delay(500); 
-WiFi OK");+    Serial.print('.'); 
 +  
 +  Serial.println("\\nWiFi OK");
   secured_client.setInsecure();   secured_client.setInsecure();
 } }
  
 void loop() { void loop() {
-  while (gpsSerial.available()) gps.encode(gpsSerial.read()); 
   VL53L0X_RangingMeasurementData_t m;   VL53L0X_RangingMeasurementData_t m;
   lox.rangingTest(&m, false);   lox.rangingTest(&m, false);
Line 126: Line 127:
     float p = constrain(100.0 - (d/BIN_HEIGHT_CM)*100.0, 0.0, 100.0);     float p = constrain(100.0 - (d/BIN_HEIGHT_CM)*100.0, 0.0, 100.0);
     lastDistance = d; lastPercentage = p;     lastDistance = d; lastPercentage = p;
 +    // Update OLED
     display.clearBuffer();     display.clearBuffer();
     display.setCursor(0,12);     display.setCursor(0,12);
Line 135: Line 137:
     display.drawBox(0,45,w,10);     display.drawBox(0,45,w,10);
     display.sendBuffer();     display.sendBuffer();
 +    // Alert on ≥80%
     if (p >= 80.0) {     if (p >= 80.0) {
       digitalWrite(LED_PIN, HIGH);       digitalWrite(LED_PIN, HIGH);
Line 145: Line 148:
     }     }
   }   }
 +  // Periodic update
   if (millis() - lastSignalTime > signalInterval) {   if (millis() - lastSignalTime > signalInterval) {
     if (updatesEnabled) sendRegularUpdate(lastDistance, lastPercentage);     if (updatesEnabled) sendRegularUpdate(lastDistance, lastPercentage);
     lastSignalTime = millis();     lastSignalTime = millis();
   }   }
-  static unsigned long lastBot=0; +  // Telegram commands 
-  if (millis()-lastBot>1000) { +  static unsigned long lastBot = 0; 
-    int n = bot.getUpdates(bot.last_message_received+1); +  if (millis() - lastBot > 1000) { 
-    while (n) { handleNewMessages(n); n = bot.getUpdates(bot.last_message_received+1); }+    int n = bot.getUpdates(bot.last_message_received + 1); 
 +    while (n) { 
 +      handleNewMessages(n); 
 +      n = bot.getUpdates(bot.last_message_received + 1); 
 +    }
     lastBot = millis();     lastBot = millis();
   }   }
Line 159: Line 167:
  
 // ... (sendWarning, sendRegularUpdate, handleNewMessages functions) // ... (sendWarning, sendRegularUpdate, handleNewMessages functions)
-``` +</code>
-(ℹ️ Please verify your GPS-serial pins (16/17 above) and your Node-RED URL.)+
  
-# 5. Node-RED Flow 
-Our Node-RED instance (on 192.168.10.50:1880) handles incoming HTTP POSTs at `/bin-alert` and: 
  
-1. Parses JSON (distance, fill_percentage, lat, lng)   +----
-2. Conditions: if `fill_percentage ≥ 80` → send email or SMS, else just log   +
-3. Dashboard: updates a gauge & map node  +
  
-<figure>   
-  <img src="FIG2_NodeRED_Flow.png" alt="Node-RED flow screenshot" />   
-  <figcaption>Figure 2. Node-RED flow (HTTP In → JSON → switch → dashboard).</figcaption>   
-</figure> 
  
-*(ℹ️ Could you share the JSON of your function node or the exact switch thresholds?)*+===== Code Summary =====
  
-6. Telegram Bot Configuration +1. **Initialization (setup)** 
-1. Create bot with BotFather → get `BOT_TOKEN`.   +   - Serial debug +<code>Wire.begin()</code>for I²C 
-2. Invite to your group/channel → note the `chat_id`.   +   - <code>lox.begin()</code> for ToF sensor and OLED splash 
-3. Grant it message-reading rights.  +   - Connect to Wi-Fi (SSID/password) 
 +   - Initialize HTTPClient & Telegram bot 
 +   - On failure (sensor or Wi-Fi), print/display error 
 + 
 +2. **Main Loop** 
 +   - Ranging measurement via <code>lox.rangingTest()</code> 
 +   - 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 (<code>/start</code>,<code>/status</code>,<code>/stop</code>, etc.) 
 +   - Delay to regulate loop frequency 
 + 
 + 
 + 
 +---- 
 + 
 + 
 + 
 +====== 5. Node-RED Flow ======  
 +''By 32780'' 
 +Our Node-RED instance handles incoming HTTP POSTs at `/bin-alert` and: 
 + 
 +  * Parses JSON (distance, fill_percentage)   
 +  * Switch: if `fill_percentage ≥ 80` → trigger email/SMS, else log   
 +  * Dashboard: updates a gauge node   
 + 
 +{{:amc:ss2025:group-t:screenshot_2025-07-29_132917.png?500|}} 
 + 
 +---- 
 + 
 +====== 6. Telegram Bot Configuration ======  
 +''By 32780'' 
 +  * Create bot with BotFather → get `BOT_TOKEN`.   
 +  Invite to your group/channel → note the `chat_id`.   
 +  Grant it message-reading rights.   
 +  * [[http://t.me/Trashbinalertbot|External Link]] Trash Bin alert bot 
 +  * [[http://t.me/klajf0239j2390d|External Link]] Trash Bin Channel 
 +   
 +{{:amc:ss2025:group-t:telegram_page.png?500|}}
  
-<figure>   
-  <img src="FIG3_Telegram_Interface.png" alt="Telegram chat screenshot" />   
-  <figcaption>Figure 3. Telegram alerts when fill ≥ 80%.</figcaption>   
-</figure> 
  
 **Commands**: **Commands**:
-`/status` — current distance & fill   +  * /start Start bot 
-`/stop` `/start` — disable/enable periodic updates   +  * /status - Get current bin fill 
-`/help` — list commands  +  * /stop - Stop regular update messages 
 +  * /startupdates - Resume regular updates 
 +  * /help - Show this message 
 + 
 + 
 +---- 
 + 
 +====== 7. Results ======  
 +''By 31706'' 
 +  * **OLED display**: real-time distance & fill bar (tested up to 85%).   
 +  * **LED**: lights when fill ≥ 80%.   
 +  * **Telegram**: immediate alert with bin status.   
 +  * **Node-RED dashboard**: gauge plotting fill percentage.   
 + 
 + 
 + 
 + 
 +  * **Distance & Fill Readout**   
 +    - OLED updates in real time:   
 +      * “Distance: 21.8 cm”   
 +      * “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:   
 +        <code>{"bin":"Kitchen","fill":85,"status":"Nearly Full"}</code>   
 +       * 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. 
 + 
 + 
 +---- 
 +{{ :amc:ss2025:group-t:screenshot_2025-07-29_160455.png?200|}} 
 +{{:amc:ss2025:group-t:pxl_20250729_093131148.jpg?200 |}} 
 +{{:amc:ss2025:group-t:pxl_20250729_093110023.jpg?200|}} 
 +---- 
 + 
 +====== 8. Discussion & Lessons Learned ======  
 +''By 31706'' 
 +  * **Portable power**: using a USB powerbank delivers ~8 hrs runtime; for longer operation, a solar-powered Li-Po pack is recommended.   
 +  * **Connectivity**: outdoors Wi-Fi drops; consider fallback via GSM/LTE or LoRaWAN.   
 +  * **Enclosure**: no weatherproof housing yetfuture 3D-printed case should protect electronics from dust and moisture.   
 +  * **Sleep modes**: ESP32 deep-sleep between measurements can drastically reduce power draw.   
 +  * **Multi-sensor**: adding ambient temperature/humidity could enable smarter waste-decomposition predictions.   
 +  * **Predictive analytics**: log historical fill data (via MQTT or cloud DB) to forecast optimal pickup schedules.   
 +  * **Firmware OTA**: integrate over-the-air updates for remote code maintenance.   
 +  * **Scalability**: mesh-network multiple bins to central server for fleet management.   
 + 
 +* **Limitations**   
 +    * Single-point ToF measurement may miss uneven trash piles.   
 +    * Reliance on Wi-Fi: network outages disrupt remote updates.   
 +    * Continuous power requirement; no battery or power-saving implemented. 
 + 
 +  * **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.
  
-# 7ESP32 Simulation+  * **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, historical logging/analytics.   
 +    * Interactive Telegram bot commands for on-demand status.
  
-We used Wokwi ESP32 simulator to validate I²C wiring and basic code logic before hardware prototyping.+----
  
-<figure>   +====== 9Conclusion ======  
-  <img src="FIG4_ESP32_Simulation.png" alt="ESP32 Wokwi simulation" />   +''By 31706''
-  <figcaption>Figure 4ESP32 & VL53L0X simulated in Wokwi.</figcaption>   +
-</figure>+
  
-*(ℹ️ Do you want me to include the `.wokwi` project JSON?)*+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 connectivityThis project demonstrates a practical IoT solution for everyday problems, with clear pathways for scaling and enhancement.
  
-# 8. Results +----
-**OLED display** shows real-time distance & fill bar (tested up to 85%).   +
-**LED** lights when fill ≥ 80%.   +
-**Telegram**: immediate alert with geo-coordinates.   +
-- **Node-RED dashboard**: gauge & live map plotting bin position.  +
  
-# 9Discussion & Lessons Learned +====== 10References ======  
-**GPS accuracy** under canopy dropped to ±10 m; consider adding GLONASS support.   +''By 31706'' 
-**Power management**: Li-Po lasted only ~2 days without solar; MPPT charge controller recommended.   +  * **STMicroelectronics VL53L0X Datasheet**   
-**Network dropouts** outdoors; a fallback to GSM/LTE or LoRaWAN could improve reliability.   +  **U8g2 SH1106 OLED driver** – https://github.com/olikraus/u8g2   
-**Sensor placement**: VL53L0X needs a clear line of sight; condensation inside enclosure can scatter photons.  +  * **UniversalTelegramBot Library** – https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot   
 +  * **Node-RED Documentation** – https://nodered.org/docs/  
  
-**Potential improvements**: 
-- Solar panel + MPPT for true off-grid operation   
-- Adaptive sleep (ESP32 deep sleep between readings)   
-- Multiple bins: multiplex sensors or use mesh networking   
-- Smart analytics: predict fill times & schedule pickups   
  
-# 10. Conclusion +{{youtube>2MH0t_iPs9k?}}
-This project demonstrates an end-to-end IoT solution for smart waste monitoring: from hardware (ESP32, ToF, GPS, OLED) through firmware (Arduino IDE) to cloud dashboards (Node-RED) and user alerts (Telegram). With a weatherproof 3D-printed enclosure and solar power, it can operate outdoors, helping cities optimize waste collection and reduce emissions.+
  
-# 11. References 
-1. **STMicroelectronics VL53L0X Datasheet**   
-2. **U8g2 SH1106 OLED driver** – https://github.com/olikraus/u8g2   
-3. **TinyGPSPlus Library** – https://github.com/mikalhart/TinyGPSPlus   
-4. **UniversalTelegramBot Library** – https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot   
-5. **Node-RED Documentation** – https://nodered.org/docs/   
amc/ss2025/group-t/start.1753743842.txt.gz · Last modified: 2025/07/29 01:04 by emir-talha.fidan