AI/ML ESP32 IoT Robotics Web Development
Garbage Classifier Demo

Project Overview

An automated waste segregation system developed during SPARC (St. Xavier's Prototyping, Automation and Robotics Club) Hackathon that uses ESP32, ultrasonic sensors, and servo motors to classify and sort waste items into appropriate bins.

Completed: July 2024
Status: Completed
Event: SPARC Fest 2025

Project Description

The Garbage Classifier is a comprehensive AI-powered waste segregation system that combines computer vision, machine learning, and robotics to automatically classify and sort waste items. The complete system consists of three main components:

  1. Mobile Web Interface: Users can capture photos of waste items using their phone's camera
  2. AI Server: Processes uploaded images using a trained machine learning model
  3. ESP32 Hardware: Controls the physical sorting mechanism based on AI classification

The system creates a seamless workflow where users simply take a photo of waste items, the AI model classifies them as Bio or Non-Bio, and the ESP32 automatically sorts them into appropriate bins using servo-controlled mechanisms.

Technical Implementation

The system integrates multiple technologies to create a seamless waste classification experience:

System Components:

  • Mobile Web Interface: Camera-enabled web application for photo capture and upload
  • AI Server (Laptop): Runs the trained machine learning model and handles image processing
  • Custom AI Model: Trained machine learning model for waste classification
  • ESP32 Microcontroller: Handles sensor input, network communication, and servo control
  • Ultrasonic Sensor (HC-SR04): Detects object presence and distance
  • Servo Motor: Controls sorting mechanism for bin direction
  • Wi-Fi Module: Enables network connectivity for data fetching
  • Sorting Bins: Bio and Non-Bio waste containers

System Architecture:

The complete system implements a three-tier architecture with the following workflow:

  1. Image Capture: Mobile web interface allows users to capture photos of waste items
  2. Image Upload: Photos are sent to the AI server via HTTP requests
  3. AI Processing: Trained machine learning model classifies the image as Bio (0) or Non-Bio (1)
  4. Result Storage: Classification result is written to a text file on the server
  5. Hardware Control: ESP32 reads the text file and controls servo for sorting
  6. Physical Sorting: Servo motor directs items to appropriate bins
garbage_classifier.ino
Copied to clipboard!
12345 678910 1112131415 1617181920 2122232425 2627282930 3132333435 3637383940 4142434445 4647484950 5152535455 5657585960 6162636465 6667686970 7172737475 7677787980 8182838485 8687888990 9192939495 96979899100

#include <ESP32Servo.h>

#include <WiFi.h>

#include <HTTPClient.h>

// Wi-Fi credentials

const char* ssid = "YOUR_SSID";

const char* password = "YOUR_PASSWORD";

// URL to fetch the value

const String url = "http://172.16.2.88:8000/display.txt";

// Servo setup

Servo myServo;

const int servoPin = 13;

// Ultrasonic sensor pins

#define TRIG_PIN 4

#define ECHO_PIN 2

void setup() {

Serial.begin(115200);

// Servo initialization

myServo.attach(servoPin);

myServo.write(90);

Serial.println("Servo initialized to 90 degrees");

// Ultrasonic sensor pin setup

pinMode(TRIG_PIN, OUTPUT);

pinMode(ECHO_PIN, INPUT);

// Wi-Fi connection

WiFi.begin(ssid, password);

Serial.print("Connecting to WiFi");

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

}

Serial.println("\nWiFi connected");

Serial.print("ESP32 IP: ");

Serial.println(WiFi.localIP());

}

float readDistanceCM() {

digitalWrite(TRIG_PIN, LOW);

delayMicroseconds(2);

digitalWrite(TRIG_PIN, HIGH);

delayMicroseconds(10);

digitalWrite(TRIG_PIN, LOW);

long duration = pulseIn(ECHO_PIN, HIGH, 30000);

float distance = duration * 0.034 / 2;

if (duration == 0) {

Serial.println("Ultrasonic timeout");

return 999;

}

return distance;

}

void loop() {

float distance = readDistanceCM();

Serial.print("Distance: ");

Serial.print(distance);

Serial.println(" cm");

if (distance < 50.0) {

if (WiFi.status() == WL_CONNECTED) {

WiFiClient client;

HTTPClient http;

http.begin(client, url);

http.addHeader("User-Agent", "ESP32");

int httpResponseCode = http.GET();

if (httpResponseCode == 200) {

String value = http.getString();

value.trim();

Serial.print("Received value: ");

Serial.println(value);

if (value == "0") {

myServo.write(70);

Serial.println("Servo set to 0 degrees");

delay(1000);

myServo.write(90);

} else if (value == "1") {

myServo.write(150);

Serial.println("Servo set to 180 degrees");

delay(1000);

myServo.write(90);

} else {

Serial.println("Invalid value in text file");

}

} else {

Serial.print("HTTP error: ");

Serial.println(httpResponseCode);

}

http.end();

} else {

Serial.println("WiFi not connected.");

}

delay(2000);

}

delay(500);

}

Project Hardware

The system uses a combination of sensors and actuators to create an automated waste classification system:

SPARC Demo Setup

Live demonstration at SPARC Fest 2025 showing the automated waste segregation system in action

SPARC Prize

Team "Built diff" receiving the SPARC Fest 2025 Category Winner award for Environmental Sustainability

Key Features

  • AI-Powered Classification: Custom trained machine learning model for accurate waste classification
  • Mobile Web Interface: User-friendly camera interface for easy photo capture and upload
  • Real-time Object Detection: Ultrasonic sensor continuously monitors for objects within 50cm range
  • Server-based Processing: Centralized AI server handles image processing and classification
  • Automated Sorting: Servo motor controls sorting mechanism to direct items to appropriate bins
  • Wi-Fi Connectivity: Seamless communication between mobile, server, and ESP32 hardware
  • Error Handling: Robust timeout and error detection for all system components

Development Process

The project was developed during the SPARC Fest 2025 event with limited time constraints:

  1. AI Model Training: Developed and trained a custom machine learning model for waste classification
  2. Server Development: Created web server to handle image uploads and run AI inference
  3. Mobile Interface: Built camera-enabled web application for photo capture and upload
  4. Hardware Setup: Assembled ESP32, ultrasonic sensor, servo motor, and sorting bins
  5. System Integration: Connected mobile interface, AI server, and ESP32 hardware
  6. Testing & Demo: Conducted live demonstration at SPARC Fest 2025

Challenges & Solutions

  • Challenge: Limited development time during SPARC Fest
    Solution: Focused on core functionality and reliable demonstration
  • Challenge: Training accurate AI model with limited dataset
    Solution: Used data augmentation and transfer learning techniques
  • Challenge: Real-time image processing and classification
    Solution: Optimized server architecture for fast inference
  • Challenge: Network dependency for classification
    Solution: Implemented robust error handling and timeout mechanisms
  • Challenge: Precise servo control for accurate sorting
    Solution: Calibrated servo angles and added delay for stable movement

Results & Impact

The Garbage Classifier project successfully demonstrated the potential of AI, IoT, and robotics in environmental sustainability. The complete system was able to:

  • Win the SPARC Fest 2025 Category Winner award for Environmental Sustainability
  • Successfully implement AI-powered waste classification with custom trained model
  • Create user-friendly mobile interface for seamless photo capture and upload
  • Develop robust server architecture for real-time image processing
  • Showcase practical application of ESP32, AI, and sensor integration
  • Inspire further development in automated waste management systems
  • Earn recognition for innovative use of AI and robotics in environmental conservation

Future Improvements

  • Enhance AI model with larger dataset and advanced architectures
  • Implement edge computing for local AI processing on ESP32
  • Add multiple sensors (camera, weight sensor) for better accuracy
  • Develop mobile app with offline capabilities
  • Scale up for industrial waste management applications
  • Integrate cloud-based AI services for enhanced classification

Go Back