DIY Smart Dustbin Project

Have you ever wished your dustbin could open its lid automatically when you come near? In this DIY project, I’ll show you how to build a simple yet effective Smart Dustbin using an Arduino, ultrasonic sensor, and a servo motor.

This is a fun project for beginners and hobbyists that not only makes your home smarter but also teaches you about distance sensing and servo control.

Let’s get started! 👇

Component Required:

  • Bucket
  • Cardboad
  • Servo Motor
  • Arduino Uno
  • Ultrasonic sensor
  • 9v Battery
  • Jumper Wire

Circuit Diagram:

Connections:

ComponentArduino Pin
Ultrasonic TrigD5
Ultrasonic EchoD6
Servo SignalD3
LED (+)D10
LED (-)GND
Ultrasonic VCC5V
Ultrasonic GNDGND
Servo VCC5V
Servo GNDGND

How It Works

  • The ultrasonic sensor continuously measures the distance in front of the dustbin.
  • If it detects an object (like your hand) within 5 to 30 cm, the Arduino sends a signal to the servo motor to open the lid.
  • After 5 seconds, the lid automatically closes.
  • An optional LED lights up when the lid is open.

Code:

#include <Servo.h>

Servo servo;

int trigPin = 5;
int echoPin = 6;
int servoPin = 3;
int led = 10;

long duration, dist, aver[3];

bool isOpen = false;
unsigned long openTime = 0;

void setup() {
  Serial.begin(9600);
  servo.attach(servoPin);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);

  closeLid();  // Close lid on power up
}

void measure() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(15);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH, 30000); // 30ms timeout
  if (duration == 0) {
    dist = 500; // No object detected
  } else {
    dist = (duration / 2) / 29.1;
  }
}

void loop() {
  // Take average of 3 readings
  for (int i = 0; i <= 2; i++) {
    measure();
    aver[i] = dist;
    delay(10);
  }
  dist = (aver[0] + aver[1] + aver[2]) / 3;

  Serial.println(dist);

  // Open only if distance between 5cm and 30cm
  if (dist > 5 && dist < 30 && !isOpen) {
    openLid();
    openTime = millis();
    isOpen = true;
  }

  // Close after 5 seconds
  if (isOpen && (millis() - openTime > 5000)) {
    closeLid();
    isOpen = false;
  }

  delay(100);
}

void openLid() {
  digitalWrite(led, HIGH);
  servo.write(0);  // Adjust angle if needed
}

void closeLid() {
  digitalWrite(led, LOW);
  servo.write(150);  // Adjust angle if needed
}

More Projects

  • Obstacle Avoiding Smart Robot Car

    Obstacle Avoiding Smart Robot Car

    An obstacle avoiding robot car is a robotic vehicle designed to navigate its environment without colliding with obstacles. It uses sensors and microcontrollers to detect and avoid obstacles in its …

  • Proximity Sensor Circuit

    Proximity Sensor Circuit

    Proximity sensors are widely used in automation, security, and robotics to detect the presence of nearby objects without physical contact. While modern sensors use complex ICs or microcontrollers, you can …

  • Safely Building a 12v 36Ah Battery Pack – Step by Step!

    Safely Building a 12v 36Ah Battery Pack – Step by Step!

    Building an 4S (4 series) LiFePO4 battery pack using 32140 LiFePO4 cells and a Daly Battery Management System (BMS). If you’re planning your own DIY power storage project, this guide …