Skip to content

Robotron2/wasteAI--ML--ESP32-CAM

Repository files navigation

RoboBin Hardware Documentation

Overview

RoboBin is an automated waste classification and sorting system built using two ESP32-based microcontrollers:

  1. Node32s (ESP32 Board) – Handles sensing (ultrasonic), actuation (servo), display (I2C LCD), and WebSocket communication with the FastAPI server.
  2. ESP32-CAM – Captures waste images upon trigger, sends them to the FastAPI server for classification, and receives acknowledgment.

Both devices communicate with the FastAPI backend using WebSockets for real-time synchronization.


System Architecture Summary

Component Role Communication Notes
Node32s (ESP32) Detects object via ultrasonic sensor, controls servo, updates LCD, communicates with server WebSocket /ws/sensor Triggers image capture, receives classification
ESP32-CAM Captures waste image and sends it to the FastAPI server WebSocket /ws/image Receives capture signal from Node32s via server
FastAPI Server Central logic hub that runs ML classification and coordinates both devices WebSocket + HTTP Classifies images and returns results

Node32s (ESP32) – Sensing & Actuation Unit

Purpose

The Node32s serves as the main control board.
It detects nearby waste using the ultrasonic sensor, triggers classification when necessary, and drives a servo to open/close the bin based on classification.

Functions

  • Ultrasonic object detection
  • Sends "object_detected" event to server
  • Receives classification results ("0" or "1")
  • Controls servo motor accordingly
  • Displays feedback via I2C LCD
  • Supports OTA (Over-the-Air) firmware updates

Pin Connections

Pin Component Function
GPIO 4 Ultrasonic Sensor TRIG
GPIO 5 Ultrasonic Sensor ECHO
GPIO 13 Servo Motor PWM Signal
GPIO 21 I2C LCD SDA
GPIO 22 I2C LCD SCL

Required Libraries

  • WiFi.h
  • WebSocketsClient.h
  • ESP32Servo.h
  • LiquidCrystal_I2C.h
  • ArduinoOTA.h (for OTA updates)

ESP32-CAM – Image Capture Unit

Purpose

The ESP32-CAM handles image acquisition.
When triggered by the Node32s (via the FastAPI server), it captures an image and sends it to the server for machine learning classification.

Functions

  • Waits for "capture" command from the FastAPI server.
  • Captures an image using the onboard camera.
  • Sends binary image data to /ws/image endpoint.
  • Receives classification feedback for confirmation.
  • Can also support OTA updates for remote reprogramming.

Pin Notes

Most pins are pre-assigned internally to the OV2640 camera, but ensure:

  • GPIO 0 → GND (for flashing only; remove after upload)
  • GPIO 4 → LED (optional indicator)
  • 5V → VIN
  • GND → GND

Communication Flow

  1. Detection: Node32s detects an object within 20 cm and sends "object_detected" via WebSocket /ws/sensor.
  2. Trigger: The FastAPI server forwards "capture" command to the ESP32-CAM via /ws/image.
  3. Capture: ESP32-CAM captures and uploads an image to the FastAPI server.
  4. Classification: Server runs the ML model and determines the class:
    • "0" → Biodegradable
    • "1" → Non-biodegradable
  5. Action: Server sends classification back to Node32s.
  6. Servo Response: Node32s moves the servo to the appropriate bin.
  7. Resume: Server signals "resume_sensing" to Node32s to restart detection.

OTA (Over-The-Air) Updates

Both ESP32 boards support OTA updates using the ArduinoOTA library.

Steps:

  1. Connect your PC and the board to the same Wi-Fi network.
  2. In Arduino IDE:
    • Go to Tools → Port → Network Ports
    • Select the device (e.g. RoboBin_Node32s or RoboBin_CAM)
  3. Click Upload — no USB needed!

Example OTA Configuration

ArduinoOTA.setHostname("RoboBin_Node32s");
ArduinoOTA.setPassword("yourpassword");

About

Esp32-cam code client to the fastAPI websocket server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors