Smart waste segregation system

Automated waste segregation using Arduino, sensors, and servo motors to sort wet/dry waste, reduce labor, and improve urban sanitation.

IntermediateWork in progress12 hours170
Smart waste segregation system

Things used in this project

Story

Read more

Schematics

whatsapp_image_2025-08-31_at_20_51_30_3aba55f2_Z1Hxk8Jb0h.jpg

Code

Untitled file

C/C++
#include <Servo.h>

Servo servo1;

#define IR_PIN 5
#define BUZZER 12
#define MOISTURE_PIN A0
#define TRIG_PIN 2
#define ECHO_PIN 3
#define LED_PIN 13

int soil = 0;
int fsoil = 0;
long duration;
long distance;

void setup() {
  Serial.begin(9600);
  pinMode(IR_PIN, INPUT);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER, OUTPUT);
  pinMode(LED_PIN, OUTPUT);

  servo1.attach(7);
  servo1.write(90);
  delay(1000);
}

void loop() {
  fsoil = 0;

  if (digitalRead(IR_PIN) == 0) {
    tone(BUZZER, 1000, 300);
    delay(350);  // wait until tone finishes

    for (int i = 0; i < 3; i++) {
      soil = analogRead(MOISTURE_PIN);
      Serial.print("Raw moisture reading: ");
      Serial.println(soil);
      fsoil += soil;
      delay(75);
    }

    fsoil = fsoil / 3;
    Serial.print("Average moisture reading: ");
    Serial.println(fsoil);

    if (fsoil < 500) {
      Serial.println("Wet waste detected → rotating to 30°");
      servo1.write(30);
    } else {
      Serial.println("Dry waste detected → rotating to 150°");
      servo1.write(150);
    }
    delay(1000);

    Serial.println("Returning to center (90°)");
    servo1.write(90);
    delay(1000);
  }

  // Ultrasonic sensor
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  duration = pulseIn(ECHO_PIN, HIGH);
  distance = duration * 0.034 / 2;
  Serial.print("Bin distance: ");
  Serial.println(distance);

  if (distance < 10) {
    Serial.println("Bin is full! LED ON");
    digitalWrite(LED_PIN, HIGH);
    tone(BUZZER, 2000, 500);
    delay(600);  // ensure tone duration
  } else {
    digitalWrite(LED_PIN, LOW);
  }

  delay(500);
}

Credits

SREERAJ K N
1 project • 2 followers
Sivapriya Ashok
1 project • 2 followers
Nihal Nasar
1 project • 3 followers
MALAVIKA SHAJI
1 project • 2 followers

Comments