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] – emir-talha.fidan | amc:ss2025:group-t:start [2025/07/29 21:59] (current) – emir-talha.fidan | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | Great, I’ll prepare a concise scientific-style writeup in English that mirrors the structure and length of the PDF examples you provided, and is based on your smart bin monitoring project with ESP32, VL53L0X, and OLED display. | + | ====== Smart Trash Bin Monitoring System ====== |
- | I’ll let you know as soon as it’s ready. | + | |
+ | **Emir Talha Fidan (32780)** | ||
+ | **Ilker Bakikol (31706)** | ||
- | # 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 | ||
- | ## Introduction | ||
- | Efficient waste management often requires knowing when a trash bin is nearing capacity to prevent overflow and optimize collection schedules. This project implements a smart trash bin fill-level monitoring system using an ESP32-S3-DevKitC-1 microcontroller and a Time-of-Flight (ToF) distance sensor. The system continuously measures the distance from the bin’s lid to the top of the trash and calculates the fill percentage of a waste bin (internal dimensions \~41×35×60 cm). An OLED display provides real-time readouts of the distance and fill level, and an onboard LED gives a visual alert when the bin is almost full. Additionally, | ||
- | ## Materials | + | This document walks through each step—hardware assembly (breadboard layout), Arduino IDE firmware, Node-RED flow, Telegram-bot config, |
- | *Hardware Components: | + | ---- |
- | * *ESP32-S3-DevKitC-1 Microcontroller: | + | ====== |
- | * *Time-of-Flight Distance Sensor (VL53L0X or VL53L1X):* Short-range LiDAR module used to measure the distance from the bin’s lid to the trash surface. The VL53L0X can measure distances up to \~2 m, while the VL53L1X extends to \~4 m – both easily covering the \~0.6 m bin height. The sensor is mounted at the top of the bin pointing downward. It communicates via I²C to provide high-resolution distance readings in millimeters. | + | '' |
- | * *SH1106 OLED Display (128×64 pixels, I²C):* Used to show the current distance reading (in cm) and the calculated fill percentage on a compact screen. This provides immediate visual feedback to users on site. | + | |
- | * *Bin and Casing:* A standard trash bin (\~41 cm × 35 cm base, 60 cm tall) is used as the container. The electronics are mounted such that the ToF sensor protrudes inside the lid, and the OLED is visible externally for easy reading. The ESP32 board and sensor are powered via USB or a 5 V supply. | + | |
- | *Wiring and Assembly:* The circuit is straightforward since most components use the I²C bus. The VL53L0X/ | + | ==== 2.1. Hardware Components ==== |
+ | ^ Component | ||
+ | | ESP32-S3-DevKitC-1 | ||
+ | | VL53L0X | ||
+ | | SH1106 | ||
+ | | LED (GPIO 2) | Visual “almost full” warning | ||
+ | | Powerbank (5 V USB) | Supplies 5 V to ESP32 for portable operation | ||
+ | | Wires, breadboard, connectors | ||
- | *Software and Libraries:* The firmware is written in C++ using the Arduino framework. Development and testing were done via the Arduino IDE. Several standard libraries facilitate the functionality: | + | {{:amc:ss2025: |
- | * *Wire.h:* I²C communication library used to interface with the ToF sensor and OLED display. | + | ---- |
- | * *Adafruit\_VL53L0X.h: | + | |
- | * *U8g2lib.h: | + | |
- | * *WiFi.h:* ESP32 Wi-Fi library to connect the device to a local wireless network (providing internet/ | + | |
- | * *HTTPClient.h: | + | |
- | * *UniversalTelegramBot.h: | + | |
- | * (Other core Arduino libraries like \< | + | |
- | After programming, | + | ==== 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 | ||
- | ## Results | + | ---- |
- | Once deployed, the smart bin monitoring system performed continuous measurement and successfully provided both local and remote feedback on the bin’s status. *Distance and Fill Readout:* The OLED display updates in real-time with the current distance from the sensor to the trash. For instance, if the trash is 45 cm below the lid, the display might show “Distance: | + | ====== 3. Hardware Assembly ====== |
+ | '' | ||
- | *Visual and Remote Alerts:* A key feature is the automatic alert when the bin is nearly full. The system defines “nearly full” as ≥80% capacity | + | ==== 3.1. Breadboard Layout ==== |
+ | * **ESP32**: VIN ← 5 V (from powerbank USB→5 V regulator), GND ← GND, SDA ← GPIO 8, SCL ← GPIO 9. | ||
+ | | ||
+ | * **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, | ||
+ | * 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. | ||
+ | {{: | ||
- | Overall, the system proved capable of accurately monitoring the bin’s fill level. In a simple test, placing objects inside to different heights yielded the expected distance readings and corresponding fill percentages. The 80% full LED trigger worked as intended, and remote notifications were successfully delivered, demonstrating the viability of the design. | + | ---- |
- | ## Code Summary | + | ====== 4. Arduino IDE Firmware ====== |
+ | '' | ||
+ | Below is the main sketch. **Please replace** `YOUR_SSID`, | ||
- | The firmware follows a typical Arduino structure with setup and loop functions, utilizing the aforementioned libraries to implement the logic. The pseudocode of the system is outlined below: | + | <code cpp> |
+ | #include <Wire.h> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
- | 1. *Initialization (setup):* The ESP32 initializes serial communication for debugging and configures the I²C bus. The ToF sensor is started (e.g., using lox.begin() and possibly set to continuous ranging mode). The SH1106 display is initialized via U8g2 and a splash or initial message may be shown. Wi-Fi connectivity is then established using the stored SSID/ | + | #define I2C_SDA 8 |
- | 2. *Main Loop (continuous operation): | + | #define I2C_SCL 9 |
- | 3. *Display Update:* The OLED is refreshed with the new values each cycle. The code clears the display buffer and prints the distance (in centimeters, | + | #define LED_PIN |
- | 4. *LED Alert Logic:* The program compares the fill percentage against the predefined threshold (80%). If fill_percent >= 80% and the LED is not already on, the onboard LED is activated (e.g., set to HIGH or in case of an RGB LED, set to a solid color). If the fill drops below the threshold (e.g., after emptying the bin) the LED is turned off. This hysteresis prevents flicker around the threshold boundary. | + | |
- | 5. *Networking – Node-RED Update:* The loop periodically (e.g. every fixed interval like 30 seconds, or each significant change) sends an HTTP POST request to the Node-RED server with the latest data. This is done using the HTTPClient library: the bin’s status (distance, fill%, maybe a timestamp) is formatted (often as a JSON string) and posted to a known URL endpoint where Node-RED is listening. The code checks the HTTP response to ensure the data was received. | + | |
- | 6. *Networking – Telegram Notifications: | + | |
- | 7. *Error Handling and Loop Delay:* If the distance sensor returns an error (e.g., no valid reading), the code can retry a few times or output an error state for that cycle, ensuring the rest of the loop continues. A short delay or timer is used at the end of each loop iteration to regulate the measurement frequency and avoid flooding the network with too many requests. In practice, readings and updates might be done, for example, once every few seconds for local display and perhaps every minute for remote updates, which is sufficient for a trash bin scenario. | + | |
- | This logical structure ensures that the device remains responsive and up-to-date, providing both local feedback via display/LED and remote feedback via network. The code is modular, with separate functions handling sensor reading, display output, and network communication, | + | #define BIN_HEIGHT_CM 60.0 |
+ | #define DISTANCE_OFFSET_CM | ||
- | ## Discussion | + | // Wi-Fi |
+ | const char* ssid = " | ||
+ | const char* password | ||
+ | // Node-RED endpoint | ||
+ | const char* alert_url | ||
- | This smart bin monitoring system demonstrates a practical Internet-of-Things solution for waste management, but there are some limitations and opportunities for improvement. One limitation is that the ToF sensor measures distance at a single point directly below it. If trash is unevenly distributed (e.g. piled higher on one side away from the sensor), the measured distance might not reflect the true highest fill level. In such cases, the bin could be slightly fuller than reported. A possible improvement would be to use multiple sensors or a scanning mechanism (like a servo-mounted sensor) to sample distances at various points, giving a more holistic measurement of fill level. Another limitation is the reliance on Wi-Fi connectivity: | + | // Telegram |
+ | const char* telegram_token = " | ||
+ | String chat_id = " | ||
- | There is also room for feature enhancements. For example, adding a weight | + | 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, I2C_SCL); | ||
+ | // Initialize display | ||
+ | display.begin(); | ||
+ | display.clearBuffer(); | ||
+ | display.setFont(u8g2_font_ncenB08_tr); | ||
+ | display.drawStr(0, | ||
+ | display.sendBuffer(); | ||
+ | // Initialize | ||
+ | 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 | ||
+ | - Initialize HTTPClient & Telegram bot | ||
+ | - On failure (sensor or Wi-Fi), print/ | ||
+ | |||
+ | 2. **Main Loop** | ||
+ | - Ranging | ||
+ | - If valid, calculate | ||
+ | `fill % = ((BIN_HEIGHT_CM − distance_cm) / BIN_HEIGHT_CM) × 100` | ||
+ | - Update | ||
+ | - 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 | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== 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 | ||
+ | * /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 | ||
+ | < | ||
+ | * 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; | ||
+ | * **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 | ||
+ | * **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 | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== 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> | ||
- | Despite these limitations, |
amc/ss2025/group-t/start.1753743920.txt.gz · Last modified: 2025/07/29 01:05 by emir-talha.fidan