Projects / Touchless smart dustbin

Touchless smart dustbin

Beginner1 hGuided buildReviewed

Build it step by step

0 of 5 done
  1. UNO146 cm

    Fix the sensor

    Mount the HC-SR04 on the front of the lid, facing up and out, so a hand above the bin is seen.

  2. UNO32°

    Fix the servo

    Mount the servo at the hinge so its horn pushes the lid up. Tie the horn to the lid with stiff wire or a 3D-printed arm.

  3. UNO

    Wire the sensor

    VCC, GND, TRIG to D9, ECHO to D10.

  4. UNO32°

    Wire the servo

    Signal to D6. Power it from the 4 × AA pack with the 100 µF capacitor across it, and join the pack's minus to Uno GND.

  5. UNO

    Upload and tune

    Upload, open the serial monitor and wave your hand. Change OPEN until the lid opens fully without straining.

In short

How do you build a touchless smart dustbin?

An ultrasonic sensor sees a hand over the bin and a servo lifts the lid, then closes it after three seconds. You need Arduino Uno R3, HC-SR04 Ultrasonic Sensor, MG90S metal gear micro servo, Electrolytic Capacitor 100 µF, Battery holder 4 × AA with switch, AA alkaline battery × 4 and Jumper wires male to female (40 pcs). It takes 5 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
HC-SR04 VCC / GNDUno 5V / GNDSensor power
HC-SR04 TRIGUno D9Start a measurement
HC-SR04 ECHOUno D10Echo pulse width = distance
Servo signal (orange)Uno D6Lid angle
Servo red / brown4 × AA pack + / −Servo power, separate from the Uno
4 × AA −Uno GNDShared ground
100 µF capacitorAcross servo + and −Smooths current spikes

Code

Arduino IDE, board "Arduino Uno". Servo library is built in.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Servo.h>

const int TRIG = 9, ECHO = 10;
const int OPEN = 100, CLOSED = 0;   // adjust for your lid hinge
Servo lid;
unsigned long openedAt = 0;
bool isOpen = false;

long distanceCm() {
  digitalWrite(TRIG, LOW); delayMicroseconds(2);
  digitalWrite(TRIG, HIGH); delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  long us = pulseIn(ECHO, HIGH, 30000);   // time out after 30 ms (about 5 m)
  return us ? us / 58 : 999;
}

void setup() {
  pinMode(TRIG, OUTPUT); pinMode(ECHO, INPUT);
  lid.attach(6); lid.write(CLOSED);
  Serial.begin(9600);
}

void loop() {
  long d = distanceCm();
  Serial.println(d);
  if (d < 20) { lid.write(OPEN); isOpen = true; openedAt = millis(); }
  if (isOpen && millis() - openedAt > 3000) { lid.write(CLOSED); isOpen = false; }
  delay(100);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

80

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
No handSerial shows the distance to the ceiling or 999; lid stays closed
Hand at 10 cmLid opens within about 0.2 s
Hand removedLid closes about 3 s later
Servo current while moving150 to 400 mA from the AA pack

If it does not work

The lid opens by itself

The sensor sees the bin rim or a wall. Tilt it outwards or lower the 20 cm limit.

The servo buzzes when closed

CLOSED pushes past the stop. Raise it from 0 to 5 or 10.

The Uno resets when the lid moves

The servo is powered from the Uno. Use the separate AA pack with a shared ground.

Distance always 999

TRIG and ECHO swapped, or ECHO not on D10.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the touchless smart dustbin?

Arduino Uno R3, HC-SR04 Ultrasonic Sensor, MG90S metal gear micro servo, Electrolytic Capacitor 100 µF, Battery holder 4 × AA with switch, AA alkaline battery × 4 and Jumper wires male to female (40 pcs). MG90S metal gear micro servo: Metal gears last longer on a lid.

How long does the touchless smart dustbin take to build?

About 60 minutes for a beginner maker, in 5 steps.

How do I know the touchless smart dustbin works?

No hand: Serial shows the distance to the ceiling or 999; lid stays closed. Hand at 10 cm: Lid opens within about 0.2 s. Hand removed: Lid closes about 3 s later.

The lid opens by itself: what should I check?

The sensor sees the bin rim or a wall. Tilt it outwards or lower the 20 cm limit.

The servo buzzes when closed: what should I check?

CLOSED pushes past the stop. Raise it from 0 to 5 or 10.

The Uno resets when the lid moves: what should I check?

The servo is powered from the Uno. Use the separate AA pack with a shared ground.

Distance always 999: what should I check?

TRIG and ECHO swapped, or ECHO not on D10.