How srinath-13/nodemcu-ml-waste-classifier works
Project type and purpose
• This is a full‐stack, embedded + web + machine‐learning system that automates waste classification and sorting.
• Hardware modules (ESP32-CAM, ESP8266+ultrasonic sensor, servo motor) capture sensor data and actuate mechanical parts.
• A PHP server acts as an intermediary HTTP endpoint for image upload and result forwarding.
• A Flask server hosts a TensorFlow/ResNet50 model (final_model.h5) to classify images into recyclable vs. non-recyclable categories.
File structure
Top level:
• “ESP 8266” folder: Arduino sketch for ultrasonic sensor & servo logic.
• “ESP32 Cam” folder: Arduino sketch (CaptureAndClassify.ino) to capture images and POST to PHP.
• “Flask (Backend)/TARP”: Python code (main.py, test.py, tempCodeRunnerFile.py) and model file (final_model.h5).
• “PHP Server/ESP32CAM”: PHP frontend (index.php, upload_img.php, loader scripts) plus static assets & captured_images folder.
• Root scripts (main.py, test.py, etc.) appear duplicate—focus on Flask/TARP for ML.
README for workflow insights
• Ultrasonic sensor triggers image capture when object within 5–15 cm.
• ESP32-CAM captures JPEG, streams bytes to PHP server endpoints.
• PHP server forwards the image to Flask ML server via HTTP.
• The Flask model classifies into six waste classes and returns a binary recyclable/non-recyclable signal.
• PHP relays classification back to ESP32, which signals the ESP8266 to rotate a servo motor to sort waste.
Main components & interactions
a. Hardware Layer (Left side)
• Ultrasonic Sensor + ESP8266 (NodeMCU)
• ESP32-CAM module
• Servo Motor
b. Edge Communication Layer (Middle)
• PHP Server (HTTP endpoint)
– Endpoints: upload_img.php, CountImageFile.php, loadPhotos.php
• Flask ML Server (HTTP API)
– Endpoint: /predict in main.py loads final_model.h5
1. Ultrasonic sensor → ESP8266 (distance trigger)
2. ESP8266 → ESP32-CAM (trigger capture)
3. ESP32-CAM → PHP server (HTTP POST image bytes)
4. PHP server → Flask server (HTTP POST forwarding)
5. Flask server → PHP server (classification JSON response)
6. PHP server → ESP32-CAM (classification signal)
7. ESP32-CAM → ESP8266 (signal via Wi-Fi or digital line)
8. ESP8266 → Servo motor (PWM rotation command)
d. Data Stores
• captured_images/ directory on PHP server (temporary storage)
• final_model.h5 in Flask server
Architectural patterns & design principles
• Separation of concerns:
– Embedded code handles hardware I/O, network I/O.
– PHP acts as a thin middleware layer (web UI + HTTP relay).
– Flask hosts the ML microservice.
• RESTful service: Flask exposes a prediction API.
• Modular: Arduino sketches isolated per microcontroller.
• Stateless HTTP calls for image classify requests.