← All Projects

Smart Dustbin with Auto-Open Lid

157 viewsFebruary 10, 2026
ArduinoServoHC-SR04UltrasonicAutomation

Build an automatic dustbin that opens its lid when it detects someone approaching. Uses an HC-SR04 ultrasonic sensor to detect proximity and a servo motor to control the lid. Perfect for touchless hygiene.

Components & Supplies

×1Arduino Uno R3
×1HC-SR04 Ultrasonic Sensor
×1SG90 Servo Motor
×1Breadboard
×6Jumper Wires (M-M)

Circuit Connections

ComponentPinPinComponent
ArduinoD9TRIGHC-SR04
ArduinoD10ECHOHC-SR04
Arduino5VVCCHC-SR04
ArduinoGNDGNDHC-SR04
ArduinoD6SignalServo
Arduino5VVCCServo
ArduinoGNDGNDServo

Overview

This smart dustbin uses an ultrasonic sensor mounted on the front to detect when a hand or object is within 30cm. When triggered, a servo motor rotates to lift the lid open. After 3 seconds of no detection, the lid closes automatically.

This project is a great introduction to servo control, proximity sensing, and simple state machines on the Arduino platform.

Assembly Guide

Assembly steps:

  • Mount the HC-SR04 sensor on the front panel of the dustbin, facing outward.
  • Attach the servo motor to the lid hinge so that a 90° rotation lifts the lid open.
  • Wire everything to the Arduino and power via USB or a 9V battery.
  • Upload the sketch and test the detection range by adjusting the threshold.
arduinoSmart Dustbin Sketch
#include <Servo.h>

Servo lidServo;
const int trigPin = 9;
const int echoPin = 10;
const int servoPin = 6;
const int threshold = 30; // cm

void setup() {
  Serial.begin(9600);
  lidServo.attach(servoPin);
  lidServo.write(0);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

float getDistance() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  long duration = pulseIn(echoPin, HIGH);
  return (duration * 0.0343) / 2.0;
}

void loop() {
  float dist = getDistance();
  Serial.print("Distance: ");
  Serial.print(dist);
  Serial.println(" cm");

  if (dist > 0 && dist < threshold) {
    lidServo.write(90);
    delay(3000);
  } else {
    lidServo.write(0);
  }
  delay(200);
}