Waste Classification

Classify waste items in an image as biodegradable or non-biodegradable using AI. Designed for smart bins, recycling automation, and environmental IoT projects powered by ESP32-CAM or Raspberry Pi.

100 scans/monthView Docs

Get Started in Minutes

Start sending IoT notifications in just a few simple steps

1

Create Account

Sign up for free, no credit card required

2

Get API Key

Generate your API key from the dashboard

3

Upload Waste Image

POST an image to /api/v1/waste-detection/detect

4

Get Classification

Receive biodegradable/non-biodegradable breakdown per item

Try API
Test the Waste Classification directly from your browser
API Key:
cd_xxxxxxxxxxxxxxxxxxxx

Waste Image

Upload Image

Upload an image for analysis. Use a clear, well-lit photo for best results.

Click or drag & drop

JPG, PNG up to 5MB

All classes active (default)

40%

Min detection confidence

Result

No result yet

Upload an image and run the test to see the annotated output

1#include "esp_camera.h"
2#include <WiFi.h>
3#include <WiFiClientSecure.h>
4
5const char* WIFI_SSID = "YOUR_WIFI_SSID";
6const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
7const char* API_KEY = "YOUR_API_KEY";
8const char* serverName = "www.circuitdigest.cloud";
9const char* serverPath = "/api/v1/waste-detection/detect";
10const int serverPort = 443;
11
12#define TRIGGER_BTN 13
13unsigned long lastTriggerTime = 0;
14const unsigned long debounceDelay = 500;
15
16#define PWDN_GPIO_NUM 32
17#define RESET_GPIO_NUM -1
18#define XCLK_GPIO_NUM 0
19#define SIOD_GPIO_NUM 26
20#define SIOC_GPIO_NUM 27
21#define Y9_GPIO_NUM 35
22#define Y8_GPIO_NUM 34
23#define Y7_GPIO_NUM 39
24#define Y6_GPIO_NUM 36
25#define Y5_GPIO_NUM 21
26#define Y4_GPIO_NUM 19
27#define Y3_GPIO_NUM 18
28#define Y2_GPIO_NUM 5
29#define VSYNC_GPIO_NUM 25
30#define HREF_GPIO_NUM 23
31#define PCLK_GPIO_NUM 22
32
33WiFiClientSecure client;
34
35void initCamera() {
36  camera_config_t cfg = {};
37  cfg.ledc_channel = LEDC_CHANNEL_0; cfg.ledc_timer = LEDC_TIMER_0;
38  cfg.pin_d0 = Y2_GPIO_NUM; cfg.pin_d1 = Y3_GPIO_NUM;
39  cfg.pin_d2 = Y4_GPIO_NUM; cfg.pin_d3 = Y5_GPIO_NUM;
40  cfg.pin_d4 = Y6_GPIO_NUM; cfg.pin_d5 = Y7_GPIO_NUM;
41  cfg.pin_d6 = Y8_GPIO_NUM; cfg.pin_d7 = Y9_GPIO_NUM;
42  cfg.pin_xclk = XCLK_GPIO_NUM; cfg.pin_pclk = PCLK_GPIO_NUM;
43  cfg.pin_vsync = VSYNC_GPIO_NUM; cfg.pin_href = HREF_GPIO_NUM;
44  cfg.pin_sscb_sda = SIOD_GPIO_NUM; cfg.pin_sscb_scl = SIOC_GPIO_NUM;
45  cfg.pin_pwdn = PWDN_GPIO_NUM; cfg.pin_reset = RESET_GPIO_NUM;
46  cfg.xclk_freq_hz = 20000000;
47  cfg.pixel_format = PIXFORMAT_JPEG;
48  cfg.frame_size = FRAMESIZE_VGA;
49  cfg.jpeg_quality = 10;
50  cfg.fb_count = 1;
51
52  if (esp_camera_init(&cfg) != ESP_OK) {
53    Serial.println("Camera init failed!");
54    while (1) delay(1000);
55  }
56
57  sensor_t* s = esp_camera_sensor_get();
58  s->set_brightness(s, 1);
59  s->set_contrast(s, 1);
60  s->set_saturation(s, 0);
61  s->set_whitebal(s, 1);
62  s->set_exposure_ctrl(s, 1);
63  s->set_gain_ctrl(s, 1);
64  Serial.println("Camera initialized.");
65}
66
67String sendImageToAPI(camera_fb_t* fb) {
68  if (!client.connect(serverName, serverPort)) {
69    return "Connection failed";
70  }
71
72  String boundary = "----ESP32Boundary";
73  String head = "--" + boundary + "
74";
75  head += "Content-Disposition: form-data; name="imageFile"; filename="snap.jpg"
76";
77  head += "Content-Type: image/jpeg
78
79";
80  String tail = "
81--" + boundary + "--
82";
83  int contentLen = head.length() + fb->len + tail.length();
84
85  client.println("POST " + String(serverPath) + " HTTP/1.1");
86  client.println("Host: " + String(serverName));
87  client.println("X-API-Key: " + String(API_KEY));
88  client.println("Content-Type: multipart/form-data; boundary=" + boundary);
89  client.println("Content-Length: " + String(contentLen));
90  client.println("Connection: close");
91  client.println();
92  client.print(head);
93  client.write(fb->buf, fb->len);
94  client.print(tail);
95
96  long timeout = millis();
97  while (client.available() == 0) {
98    if (millis() - timeout > 15000) {
99      client.stop();
100      return "Timeout";
101    }
102  }
103
104  String response = "";
105  while (client.available()) {
106    response += (char)client.read();
107  }
108  client.stop();
109
110  int jsonStart = response.indexOf("
111
112");
113  return (jsonStart != -1) ? response.substring(jsonStart + 4) : response;
114}
115
116void classifyWaste() {
117  camera_fb_t* fb = esp_camera_fb_get();
118  esp_camera_fb_return(fb);
119  delay(200);
120  fb = esp_camera_fb_get();
121  if (!fb) { Serial.println("Capture failed"); return; }
122  Serial.println("Photo captured! Sending to API...");
123  String result = sendImageToAPI(fb);
124  esp_camera_fb_return(fb);
125  Serial.println("Response: " + result);
126}
127
128void setup() {
129  Serial.begin(115200);
130  pinMode(TRIGGER_BTN, INPUT_PULLUP);
131  initCamera();
132  WiFi.begin(WIFI_SSID, WIFI_PASS);
133  Serial.print("Connecting to WiFi");
134  while (WiFi.status() != WL_CONNECTED) {
135    delay(500);
136    Serial.print(".");
137  }
138  Serial.println("
139Connected: " + WiFi.localIP().toString());
140  client.setInsecure(); // Accept self-signed certs
141}
142
143void loop() {
144  if (digitalRead(TRIGGER_BTN) == LOW) {
145    unsigned long currentTime = millis();
146    if (currentTime - lastTriggerTime > debounceDelay) {
147      lastTriggerTime = currentTime;
148      Serial.println("Button pressed! Capturing image...");
149      classifyWaste();
150    }
151  }
152}