{"id":39764290,"url":"https://github.com/brunobpinto/smart-trashcans","last_synced_at":"2026-01-18T11:43:39.200Z","repository":{"id":323265305,"uuid":"1091383279","full_name":"brunobpinto/smart-trashcans","owner":"brunobpinto","description":"A smart waste monitoring system for PUC-Rio, featuring sensor-equipped trash cans and a dashboard for tracking fill levels, cleaning history, and usage trends.","archived":false,"fork":false,"pushed_at":"2025-12-15T00:38:21.000Z","size":704,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-16T05:36:39.407Z","etag":null,"topics":["home-automation","iot","monitoring","smarthome","trash-management","trashcan"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brunobpinto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-07T00:11:30.000Z","updated_at":"2025-12-15T00:38:24.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/brunobpinto/smart-trashcans","commit_stats":null,"previous_names":["brunobpinto/smart-trashcans"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brunobpinto/smart-trashcans","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunobpinto%2Fsmart-trashcans","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunobpinto%2Fsmart-trashcans/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunobpinto%2Fsmart-trashcans/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunobpinto%2Fsmart-trashcans/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brunobpinto","download_url":"https://codeload.github.com/brunobpinto/smart-trashcans/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunobpinto%2Fsmart-trashcans/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28535177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T10:13:46.436Z","status":"ssl_error","status_checked_at":"2026-01-18T10:13:11.045Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["home-automation","iot","monitoring","smarthome","trash-management","trashcan"],"created_at":"2026-01-18T11:43:39.051Z","updated_at":"2026-01-18T11:43:39.165Z","avatar_url":"https://github.com/brunobpinto.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Smart-Trashcans-Banner](https://github.com/user-attachments/assets/1b873901-4a76-4f26-98c0-676b1c51de97)\n\n# Smart Trashcans\nThis project was developed as the final activity for the Internet of Things (IoT) Project class at PUC-Rio, Brazil. It presents a smart waste monitoring system for PUC-Rio’s campus bins. Each device tracks fill levels, cleaning history, and usage peaks, displaying the data on an interactive dashboard with a campus map. The system classifies bins by cleaning urgency using color indicators: green, yellow, and red.\n\u003cbr\u003e\u003cbr\u003e\n\n## Video\nWatch how we made this project in the video below:\n\nhttps://github.com/user-attachments/assets/5f297aff-46dd-469c-831e-9b2488daee38\n\n## Important Links\n- Entrepreneurship Presentation: [Google Slides](https://docs.google.com/presentation/d/1eFLQctskUMzdFxHRRN8Uq6AJgMyZpdaHZNqkaKqREag/edit?usp=sharing)\n- Final Project Video: [Youtube](https://youtu.be/zSX_mzMJ4nE)\n- 3D Modelling and Assembly: [OnShape](https://cad.onshape.com/documents/b87a7e99e19c62217d651890/w/9fb80a89a01454b3f9800e65/e/fb9532ab13b9a6d6421fd709?renderMode=0\u0026uiState=69321752dd5747af1b660e4b)\n- PCB Schematic: [EasyEDA Project.](https://bit.ly/smart-trashcans)\n\n## How It Works\nThe Smart Trashcans system combines IoT hardware, wireless communication, and a cloud-connected dashboard to monitor waste levels and cleaning activity across the PUC-Rio campus.\nBelow is an overview of how each component interacts to provide real-time insights.\n\n**1- Data Collection (ESP32-S3 Device)** \u003cbr\u003e\n\nEach trashcan is equipped with an ESP32-S3 microcontroller connected to multiple sensors: \u003cbr\u003e\n\n- **Fill Level Measurement**: \u003cbr\u003e\nThe HC-SR04 ultrasonic sensor measures the distance from the top of the bin to the waste.\nThe device calculates the fill percentage using: `Fill % = ((TrashcanDepth - MeasuredDistance) / TrashcanDepth) × 100`\n\n- **Motion Detection**: \u003cbr\u003e\nA PIR sensor detects when a worker approaches the bin.\nThe ESP32 wakes from deep sleep when motion is detected (GPIO 4 RTC interrupt), reducing energy consumption. \u003cbr\u003e\n\n- **Cleaning Validation (RFID)**: \u003cbr\u003e\nWorkers authenticate using an RFID tag (RC522 module).\nSuccessful scans log the cleaning event and identify the worker.\n\n- **Wireless Communication (LoRaWAN)**: \u003cbr\u003e\nThe device sends: \u003cbr\u003e\n-- fill level \u003cbr\u003e\n-- motion-triggered events \u003cbr\u003e\n-- cleaning confirmations \u003cbr\u003e\n-- Data is transmitted via the Radioenge LoRaMesh module to the gateway.\n\n**2- Local Access Control (On-Device SQLite)** \u003cbr\u003e\n\nThe ESP32 maintains a lightweight database using SQLite + LittleFS containing:\n- Authorized users\n- Roles (WORKER, ADMIN)\n- Cleaning and access logs\n- This allows the trashcan to operate even without Wi-Fi or cloud connectivity.\n\n**3- Data Transmission to Server** \u003cbr\u003e\n\nThe LoRaWAN gateway forwards packets to the backend, which decodes them and stores data in a centralized PostgreSQL database using Prisma ORM. The received payload typically includes:\n- trashcanId\n- fillLevel\n- timestamp\n- rfidTagId (optional)\n- motionDetected\n\n**4- Backend Processing** \u003cbr\u003e\n\nThe backend (Next.js API routes) performs tasks such as:\n- Storing fill levels\n- Updating cleaning history\n- Validating RFID access\n- Generating usage analytics\n- Serving data to the dashboard\n  \nAll routes are secured using NextAuth to ensure only authorized personnel can access the system.\n\n**5- Interactive Dashboard (Next.js + Tailwind)** \u003cbr\u003e\n\nThe web dashboard provides:\n\n- **Campus Map Visualization** \u003cbr\u003e\nEach trashcan appears as a marker with a color-coded status: \u003cbr\u003e\n-- 🟢 Green: Low fill level \u003cbr\u003e\n-- 🟡 Yellow: Approaching limit \u003cbr\u003e\n-- 🔴 Red: Needs immediate cleaning\n\n- **Real-Time Charts** \u003cbr\u003e\nFill level over time\nCleaning frequency\nWorker activity logs\nPeak usage periods\n\n- **Role-Based Interface** \u003cbr\u003e\n`Admins`: Can view analytics, manage users, and track logs\n`Workers`: See bins needing cleaning and validate actions via RFID\n\n**6- Energy Optimization** \u003cbr\u003e\n\nTo extend battery life, the ESP32 uses:\n- Deep sleep between measurement intervals\n- Wake-up on PIR motion or timed interval\n- Periodic LoRa transmissions instead of constant communication\n- This allows the device to operate for months on a single 18650 battery.\n\n**7- Full System Workflow Summary** \u003cbr\u003e\n\n- Sensors collect measurements\n- ESP32 stores data locally and sends key values via LoRa\n- Backend receives and stores information in PostgreSQL\n- Dashboard displays real-time bin status and alerts\n- Workers authenticate via RFID and perform cleaning\n- System updates history and analytics automatically\n\n## Getting Started\n\n### Hardware Requirements\n- ESP32-S3 N8R2 microcontroller\n- Ultrasound Distance Sensor\n- RFID Reader\n- LoRaWAN Modem\n- Motion Sensor\n- 18650 Battery\n\n### Software Requirements\n- Next.js with Typescript\n- Prisma\n- Tailwind CSS\n- NextAuth\n- Postgres Database\n\n\u003e [!IMPORTANT]\n\u003e It’s important to note that this application is designed to work with a PostgreSQL database. If you’re using a different database, a few minor adjustments will be required for proper functionality.\n\n### GPIO Pin Mapping\n**RFID Reader (RC522)**\n\n| Pin  | GPIO | Function             |\n| ---- | ---- | -------------------- |\n| SDA  | 46   | SPI Chip Select (SS) |\n| RST  | 17   | Reset                |\n| SCK  | 12   | SPI Clock            |\n| MISO | 13   | SPI Data Out         |\n| MOSI | 11   | SPI Data In          |\n| VCC  | 3.3V | Power                |\n| GND  | GND  | Ground               |\n\n**LoRaWAN Module (Radioenge LoRaMesh v4)**\n\n| Pin | GPIO | Function              |\n| --- | ---- | --------------------- |\n| TX  | 47   | Serial1 TX (ESP→LoRa) |\n| RX  | 48   | Serial1 RX (LoRa→ESP) |\n| VCC | 3.3V | Power                 |\n| GND | GND  | Ground                |\n\n- Baud Rate: 9600\n- Serial Mode: 8N1\n\n**PIR Motion Sensor (HC-SR501)**\n\n| Pin  | GPIO | Function                                 |\n| ---- | ---- | ---------------------------------------- |\n| DATA | 4    | Digital output (RTC-capable for wake-up) |\n| VCC  | 5V   | Power                                    |\n| GND  | GND  | Ground                                   |\n\n- GPIO 4 is RTC-capable, suitable for deep sleep wake-up interrupts\n- HC-SR501 requires ~60 seconds to calibrate on power-up\n- Output is HIGH when motion detected\n\n**Ultrasound Distance Sensor (HC-SR04)**\n\n| Pin  | GPIO | Function             |\n| ---- | ---- | -------------------- |\n| TRIG | 10   | Trigger (send pulse) |\n| ECHO | 9    | Echo (receive pulse) |\n| VCC  | 5V   | Power                |\n| GND  | GND  | Ground               |\n\n- `TRASHCAN_DEPTH_CM`: Distance from sensor to bottom when empty (default: 30 cm)\n- Measurement timeout: 30ms (max range ~5m)\n- Distance (cm) = (pulse duration × 0.0343) / 2\n- Fill % = ((TRASHCAN_DEPTH - measured distance) / TRASHCAN_DEPTH) × 100\n\n## Installation\nThis section explains how to set up the complete **Smart Trashcans** system, including the web application, database, and ESP32-S3 firmware.\n1. **Clone the Repository** \u003cbr\u003e\n`git clone https://github.com/brunobpinto/smart-trashcans.git` \u003cbr\u003e\n`cd smart-trashcans`\n\n2. **Web Application Setup (Next.js + TypeScript)**\n- Install dependencies using `npm install`\n- Configure environment variables\n- Create a file named: `.env.local`\n- Add the following: \u003cbr\u003e\n`DATABASE_URL=\"postgresql://user:password@localhost:5432/smarttrashcans\"` \u003cbr\u003e\n`NEXTAUTH_SECRET=\"your_secure_random_key\"` \u003cbr\u003e\n`NEXTAUTH_URL=\"http://localhost:3000\"`\n\n3. **Database Setup (PostgreSQL)**\n- Create the database: `createdb smarttrashcans`\n- Apply Prisma schema migrations: `npx prisma migrate dev`\n\n4. **Run the Web Application**\n- Run in terminal: `npm run dev`\n- Access the dashboard at your localhost\n\n5. **ESP32-S3 Firmware Setup**\n- Make sure you meet all the Hardware Requirements\n\n6. **ESP32 File System \u0026 Database Initialization**\n- On first boot, the firmware will automatically: \u003cbr\u003e\nMount LittleFS \u003cbr\u003e\nCreate `/littlefs/database.db` \u003cbr\u003e\nCreate the tables: `role`, `user`, `logs` \u003cbr\u003e\nInsert default roles: `WORKER`, `ADMIN`\n\n7. **Running the Entire System**\n- Start PostgreSQL\n- Start the web application: `npm run dev`\n- Power the ESP32-S3 and sensors\n\nThe dashboard will begin displaying data in real time\n\n## 3D Printed Files\nAll 3D-printed files can be found in the `/3D-FILES` directory.\n\n\u003e [!WARNING]\n\u003e While the 3D parts can be printed using various materials, it is recommended to use weather-resistant materials if the device will be installed outdoors. Materials such as PETG, ASA, or ABS are suitable for outdoor exposure, as they can withstand sunlight and moisture. PLA is not recommended, as it degrades quickly under heat and UV light.\n\u003cdiv\u003e‎\u003c/div\u003e\n\n## PCB Schematic\n![Smart-Trashcans-Schematic](https://github.com/user-attachments/assets/5d186018-6281-4e48-bf26-967ee84a0399)\n\n\u003e [!NOTE]\n\u003e The full circuit, including the schematic, PCB design, and 3D model, is available on the [EasyEDA Project.](https://bit.ly/smart-trashcans)\n\u003cdiv\u003e‎\u003c/div\u003e\n\n### Preview\n![Smart-Trashcans-3D-front](https://github.com/user-attachments/assets/ca759f75-0c94-48ff-9f42-e6d0d800fd6f)\n![Smart-Trashcans-3D-back](https://github.com/user-attachments/assets/d343ee3b-4378-44d8-96dd-5baa7ea02c32)\n\n## ESP32 Internal Database Schema \n- **Table: `role`** - Reference table for role integrity control.\n\n| Column      | Type | Constraints | Description     |\n| ----------- | ---- | ----------- | --------------- |\n| `role_code` | TEXT | PRIMARY KEY | Role identifier |\n\nPre-populated Data:\n`'WORKER'`\n`'ADMIN'`\n\n- **Table: `user`** - Stores registered users with their RFID tags and assigned roles.\n\n| Column        | Type    | Constraints                   | Description            |\n| ------------- | ------- | ----------------------------- | ---------------------- |\n| `id`          | INTEGER | PRIMARY KEY AUTOINCREMENT     | Unique user identifier |\n| `name`        | TEXT    | NOT NULL                      | User's full name       |\n| `rfid_tag_id` | TEXT    | NOT NULL, UNIQUE              | RFID tag identifier    |\n| `role`        | TEXT    | NOT NULL, FK → role.role_code | User's role            |\n\n- **Table: `logs`** - Logs all access attempts with timestamps.\n\n| Column        | Type    | Constraints               | Description                 |\n| ------------- | ------- | ------------------------- | --------------------------- |\n| `id`          | INTEGER | PRIMARY KEY AUTOINCREMENT | Unique log entry identifier |\n| `rfid_tag_id` | TEXT    | NOT NULL                  | RFID tag that was scanned   |\n| `datetime`    | TEXT    | NOT NULL                  | Timestamp (ISO8601 format)  |\n\n### Relationships\n- **Foreign Key Constraint:** `user.role` references `role.role_code`\n- **Enforcement:** Foreign key constraints are enabled via `PRAGMA foreign_keys = ON`\n\n### Database Configuration\n- **Location:** `/littlefs/database.db`\n- **Filesystem:** LittleFS (auto-formatted on first mount)\n- **Platform:** ESP32 S3 (N8R2)\n\n\u003e [!IMPORTANT]\n\u003e This project uses SQLite stored on the ESP32 S3's LittleFS filesystem for access control management.\n\n## Web-Server Screenshots\n\nhttps://github.com/user-attachments/assets/3d598d5b-c10e-4606-8ba2-fbc61875179e\n\n## Achievements\nEntrepreneurship Fair Winner – The Smart Trashcans project won an entrepreneurship fair held at PUC-Rio on December 5th, recognizing the project for its innovation, technical execution, and real-world impact.\n\n![Smart-Trashcans-trophy](https://github.com/user-attachments/assets/c0f2f933-056f-48d2-8aff-5d611bce9632)\n\n\n## Contributors\nWe would like to extend our heartfelt thanks to everyone who contributed to the development of this project. Your support, ideas, and dedication were essential in bringing this project to life.\n\n- [@aurorarichaud](https://github.com/aurorarichaud)\n- [@brunobpinto](https://github.com/brunobpinto)\n- [@bathwaterpizza](https://github.com/bathwaterpizza)\n\nThank you all for your hard work and collaboration!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunobpinto%2Fsmart-trashcans","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrunobpinto%2Fsmart-trashcans","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunobpinto%2Fsmart-trashcans/lists"}