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:07] – created emir-talha.fidan | amc:ss2025:group-t:start [2025/07/29 21:59] (current) – emir-talha.fidan | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | 1. Introduction | + | ====== |
- | Every year, inefficient waste-collection leads to unnecessary pickups, added CO₂ emissions, and overflowing public bins. Our Smart Trash-Bin Fill-Level | + | |
- | A different Wi-Fi server | + | **Emir Talha Fidan (32780)** |
+ | **Ilker Bakikol (31706)** | ||
- | A GPS module (for geo-tagged | + | ====== 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 | ||
- | 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 flow, Telegram-bot config, and ESP32 simulation—so you can reproduce and extend the system | + | 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 |
- | 2. Materials & System Overview | + | ---- |
- | 2.1. Hardware Components | + | |
- | Component Purpose | + | |
- | ESP32-S3-DevKitC-1 Main MCU, Wi-Fi, GPIOs | + | |
- | VL53L0X ToF sensor Measures distance from bin top to contents | + | |
- | SH1106 128×64 I²C OLED (U8g2 lib) Displays distance (cm) & fill (%) | + | |
- | LED (GPIO 2) Visual “almost full” warning | + | |
- | GPS module (e.g. NEO-6M) Provides latitude/ | + | |
- | 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 | + | |
- | (ℹ️ Please confirm the GPS module part number and its RX/TX pin mapping so I can update the wiring diagram precisely.) | + | ====== 2. Materials & System Overview ====== |
+ | '' | ||
- | 2.2. Software | + | ==== 2.1. Hardware |
- | Arduino IDE (v2.x) | + | ^ 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 | ||
- | Libraries: | + | {{:amc: |
- | Adafruit_VL53L0X – Time-of-Flight sensor | + | ---- |
- | U8g2lib – SH1106 OLED driver | + | ==== 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 | ||
- | WiFi.h / HTTPClient.h – Wi-Fi & HTTP POST | + | ---- |
- | TinyGPSPlus.h – GPS parsing | + | ====== 3. Hardware Assembly ====== |
+ | '' | ||
- | UniversalTelegramBot.h – Telegram Bot API | + | ==== 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. | ||
+ | {{: | ||
- | Node-RED (v3.x) on 192.168.10.50: | + | ---- |
- | Telegram Bot (“TrashAlertBot”) configured with token xxxx: | + | ====== 4. Arduino IDE Firmware ====== |
+ | '' | ||
+ | Below is the main sketch. **Please replace** `YOUR_SSID`, | ||
- | 3. Hardware Assembly | + | <code cpp> |
- | 3.1. Breadboard Layout | + | |
- | Power rails: +5 V from Li-Po-Solar charger to 5 V rail; 3.3 V regulator feeding 3.3 V rail. | + | |
- | + | ||
- | ESP32: VIN ← 5 V, GND ← GND, SDA ← GPIO 8, SCL ← GPIO 9. | + | |
- | + | ||
- | VL53L0X: VCC ← 3.3 V, GND ← GND, SDA/SCL as above. | + | |
- | + | ||
- | OLED (SH1106): VCC ← 3.3 V, GND ← GND, SDA/SCL as above. | + | |
- | + | ||
- | 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.) | + | |
- | + | ||
- | LED: Anode ← GPIO 2 (with 330 Ω resistor), Cathode ← GND. | + | |
- | + | ||
- | <figure> <img src=" | + | |
- | 4. Arduino IDE Firmware | + | |
- | Below is the main sketch. Please replace YOUR_SSID, YOUR_PASS, NODE_RED_URL, | + | |
- | + | ||
- | cpp | + | |
- | Kopyala | + | |
- | Düzenle | + | |
#include < | #include < | ||
#include < | #include < | ||
Line 80: | Line 69: | ||
#include < | #include < | ||
#include < | #include < | ||
- | #include < | ||
#include < | #include < | ||
Line 94: | Line 82: | ||
const char* password | const char* password | ||
// Node-RED endpoint | // Node-RED endpoint | ||
- | const char* alert_url | + | const char* alert_url |
- | + | ||
- | // GPS on Serial1 | + | |
- | HardwareSerial gpsSerial(1); | + | |
- | TinyGPSPlus gps; | + | |
// Telegram | // Telegram | ||
const char* telegram_token = " | const char* telegram_token = " | ||
- | String chat_id = "-1001234567890"; | + | String chat_id = "CHAT_ID"; |
- | U8G2_SH1106_128X64_NONAME_F_HW_I2C display(U8G2_R0, | + | U8G2_SH1106_128X64_NONAME_F_HW_I2C display(U8G2_R0, |
Adafruit_VL53L0X lox = Adafruit_VL53L0X(); | Adafruit_VL53L0X lox = Adafruit_VL53L0X(); | ||
WiFiClientSecure secured_client; | WiFiClientSecure secured_client; | ||
Line 111: | 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 118: | Line 101: | ||
Serial.begin(115200); | Serial.begin(115200); | ||
Wire.begin(I2C_SDA, | Wire.begin(I2C_SDA, | ||
- | // Display | + | // Initialize display |
display.begin(); | display.begin(); | ||
- | display.clearBuffer(); | + | display.clearBuffer(); |
- | display.drawStr(0, | + | |
- | // Sensor | + | display.drawStr(0, |
- | if (!lox.begin()) | + | |
+ | // Initialize sensor | ||
+ | if (!lox.begin()) while (1); | ||
pinMode(LED_PIN, | pinMode(LED_PIN, | ||
- | // GPS | + | // Connect |
- | gpsSerial.begin(9600, | + | |
- | + | ||
- | // Wi-Fi | + | |
WiFi.begin(ssid, | WiFi.begin(ssid, | ||
- | while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print(' | + | while (WiFi.status() != WL_CONNECTED) { |
- | Serial.println(" | + | |
- | // Telegram | + | |
+ | | ||
+ | Serial.println(" | ||
secured_client.setInsecure(); | secured_client.setInsecure(); | ||
} | } | ||
void loop() { | void loop() { | ||
- | // Read GPS | ||
- | while (gpsSerial.available()) gps.encode(gpsSerial.read()); | ||
- | |||
- | // Measure distance | ||
VL53L0X_RangingMeasurementData_t m; | VL53L0X_RangingMeasurementData_t m; | ||
lox.rangingTest(& | lox.rangingTest(& | ||
if (m.RangeStatus != 4) { | if (m.RangeStatus != 4) { | ||
- | float distance_cm | + | float d = m.RangeMilliMeter/ |
- | float fill_pct | + | float p = constrain(100.0 - (d/ |
- | lastDistance = distance_cm; lastPercentage = fill_pct; | + | lastDistance = d; lastPercentage = p; |
// Update OLED | // Update OLED | ||
display.clearBuffer(); | display.clearBuffer(); | ||
display.setCursor(0, | display.setCursor(0, | ||
- | display.print(" | + | display.print(" |
display.setCursor(0, | display.setCursor(0, | ||
- | display.print(" | + | display.print(" |
- | // Bar | + | int w = map((int)p, |
- | int w = map((int)fill_pct, | + | |
display.drawFrame(0, | display.drawFrame(0, | ||
display.drawBox(0, | display.drawBox(0, | ||
display.sendBuffer(); | display.sendBuffer(); | ||
- | + | | |
- | | + | if (p >= 80.0) { |
- | if (fill_pct | + | |
digitalWrite(LED_PIN, | digitalWrite(LED_PIN, | ||
if (millis() - lastAlertTime > 15000) { | if (millis() - lastAlertTime > 15000) { | ||
- | sendWarning(distance_cm, fill_pct); | + | sendWarning(d, p); |
lastAlertTime = millis(); | lastAlertTime = millis(); | ||
} | } | ||
Line 171: | Line 148: | ||
} | } | ||
} | } | ||
- | |||
// Periodic update | // Periodic update | ||
if (millis() - lastSignalTime > signalInterval) { | if (millis() - lastSignalTime > signalInterval) { | ||
Line 177: | Line 153: | ||
lastSignalTime = millis(); | lastSignalTime = millis(); | ||
} | } | ||
- | |||
// Telegram commands | // Telegram commands | ||
- | static unsigned long lastBot=0; | + | static unsigned long lastBot = 0; |
- | if (millis()-lastBot> | + | if (millis() - lastBot > 1000) { |
- | int n = bot.getUpdates(bot.last_message_received+1); | + | int n = bot.getUpdates(bot.last_message_received + 1); |
- | while (n) { handleNewMessages(n); | + | while (n) { |
+ | | ||
+ | | ||
+ | | ||
lastBot = millis(); | lastBot = millis(); | ||
} | } | ||
Line 188: | Line 166: | ||
} | } | ||
- | void sendWarning(float d, float p) { | + | // ... (sendWarning, sendRegularUpdate, handleNewMessages functions) |
- | | + | </code> |
- | WiFiClient client; HTTPClient http; | + | |
- | String payload = " | + | |
- | +String(d, | + | |
- | +", | + | |
- | +", | + | |
- | if (http.begin(client, alert_url)) { | + | |
- | | + | |
- | http.POST(payload); | + | |
- | } | + | |
- | // Telegram | + | |
- | String msg = " | + | |
- | "📏 " | + | |
- | "📊 " | + | |
- | "📍 " | + | |
- | +String(gps.location.lng(), | + | |
- | bot.sendMessage(chat_id, | + | |
- | } | + | |
- | void sendRegularUpdate(float d, float p) { | ||
- | // identical to sendWarning, | ||
- | // ... | ||
- | } | ||
- | void handleNewMessages(int n) { | + | ---- |
- | for (int i=0; | + | |
- | | + | |
- | txt = bot.messages[i].text, | + | ===== Code Summary ===== |
- | name= bot.messages[i].from_name; | + | |
- | if (txt=="/ | + | 1. **Initialization |
- | bot.sendMessage(id, | + | - Serial debug +< |
- | " | + | - < |
- | } else if (txt=="/stop") { | + | - Connect to Wi-Fi (SSID/password) |
- | | + | - Initialize HTTPClient & Telegram |
- | } else if (txt=="/start") { | + | - On failure |
- | | + | |
- | } else { | + | 2. **Main Loop** |
- | bot.sendMessage(id,"❓ Unknown. Use / | + | - Ranging measurement via < |
- | } | + | - If valid, calculate |
- | } | + | `fill % = ((BIN_HEIGHT_CM − distance_cm) |
- | } | + | - Update OLED: distance, fill %, bar graph |
- | (ℹ️ Please verify your GPS-serial pins (16/17 above) and your Node-RED URL.) | + | - 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 (on 192.168.10.50: | ||
- | Parses JSON (distance, fill_percentage, | + | ---- |
- | Conditions: if fill_percentage ≥ 80 → send email or SMS, else just log | ||
- | Dashboard: updates a gauge & map node | ||
- | < | + | ====== 5. Node-RED |
- | (ℹ️ Could you share the JSON of your function node or the exact switch thresholds? | + | '' |
+ | Our Node-RED | ||
- | 6. Telegram Bot Configuration | + | * Parses JSON (distance, fill_percentage) |
- | Create bot with BotFather | + | * Switch: if `fill_percentage ≥ 80` → trigger email/SMS, else log |
+ | * Dashboard: updates a gauge node | ||
- | Invite to your group/channel → note the chat_id. | + | {{: |
- | Grant it message-reading rights. | + | ---- |
- | < | + | ====== 6. Telegram |
- | Commands: | + | '' |
+ | * Create bot with BotFather → get `BOT_TOKEN`. | ||
+ | * Invite to your group/channel → note the `chat_id`. | ||
+ | * Grant it message-reading rights. | ||
+ | * [[http://t.me/ | ||
+ | * [[http:// | ||
+ | |||
+ | {{: | ||
- | /status: current distance & fill | ||
- | /stop & /start: disable/enable periodic | + | **Commands**: |
+ | * / | ||
+ | * /status - Get current bin fill | ||
+ | * /stop - Stop regular update messages | ||
+ | * / | ||
+ | * /help - Show this message | ||
- | /help: list commands | ||
- | 7. ESP32 Simulation | + | ---- |
- | We used Wokwi ESP32 simulator to validate I²C wiring and basic code logic before hardware prototyping. | + | |
- | < | + | ====== 7. Results ====== |
- | (ℹ️ Do you want me to include the .wokwi project JSON?) | + | '' |
+ | * **OLED display**: real-time distance & fill bar (tested up to 85%). | ||
+ | * **LED**: lights when fill ≥ 80%. | ||
+ | * **Telegram**: | ||
+ | * **Node-RED dashboard**: | ||
- | 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. | + | * **Distance & Fill Readout** |
+ | | ||
+ | * “Distance: | ||
+ | * “Fill: 63 %” | ||
+ | - Fill percentage = ((60 cm − measured_distance) / 60 cm) × 100 %. | ||
- | 9. Discussion | + | * **Visual |
- | GPS accuracy under canopy dropped to ±10 m; consider adding GLONASS support. | + | - 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. | ||
- | Power management: Li-Po lasted only ~2 days without solar; MPPT charge controller recommended. | ||
- | Network dropouts outdoors; a fallback to GSM/LTE or LoRaWAN could improve reliability. | + | ---- |
+ | {{ : | ||
+ | {{: | ||
+ | {{: | ||
+ | ---- | ||
- | Sensor placement: VL53L0X needs a clear line of sight; condensation inside enclosure | + | ====== 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 | ||
+ | * **Multi-sensor**: | ||
+ | * **Predictive analytics**: | ||
+ | * **Firmware OTA**: integrate over-the-air updates for remote code maintenance. | ||
+ | * **Scalability**: | ||
- | Potential improvements: | + | * **Limitations** |
+ | * Single-point ToF measurement may miss uneven trash piles. | ||
+ | * Reliance on Wi-Fi: network outages disrupt remote updates. | ||
+ | * Continuous power requirement; | ||
- | Solar panel + MPPT for true off-grid operation | + | * **Improvements** |
+ | * Multiple sensors or servo-mounted scanning | ||
+ | * Offline data buffering and reconnection logic for network resilience. | ||
+ | * Deep-sleep between measurements for battery | ||
- | Adaptive sleep (ESP32 deep sleep between readings) | + | * **Future Enhancements** |
+ | * A GPS module | ||
+ | * 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. | ||
- | Multiple bins: multiplex sensors or use mesh networking | + | ---- |
- | Smart analytics: predict fill times & schedule pickups | + | ====== 9. Conclusion ====== |
+ | '' | ||
- | 10. Conclusion | + | Deploying multiple units in smart buildings or campuses enables optimized |
- | 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 | + | |
- | 11. References | + | ---- |
- | VL53L0X Datasheet, STMicroelectronics. | + | |
- | SH1106 OLED driver, U8g2 library: | + | ====== 10. References ====== |
+ | '' | ||
+ | * **STMicroelectronics VL53L0X Datasheet** | ||
+ | * **U8g2 | ||
+ | * **UniversalTelegramBot Library** – https:// | ||
+ | * **Node-RED Documentation** – https:// | ||
- | TinyGPSPlus, | ||
- | UniversalTelegramBot, | + | {{youtube> |
- | Node-RED Documentation, |
amc/ss2025/group-t/start.1753744034.txt.gz · Last modified: 2025/07/29 01:07 by emir-talha.fidan