Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
The Arduino Trash-Bot is a hands-free bin-lid project: an ultrasonic sensor detects a nearby object, an Arduino commands a servo to open the lid, and the servo closes it again after a delay. It does not recognize trash or sort waste; a hand, bag, wall, or person can trigger it. The original build is a useful learning project, but reliable operation depends on careful mechanical calibration, suitable servo power, and code that handles missing sensor echoes.
What the original Trash-Bot does
Ashraf Minhaj’s 2018 Hackster.io Trash-Bot project uses an HC-SR04 ultrasonic sensor, an Arduino Uno, and a hobby servo attached to a bin lid with a simple arm or linkage. In the published sketch, an object within about 50 cm causes the servo to move to 50 degrees; the program waits three seconds, then commands 160 degrees when the sensor no longer reports an object within range.
Those are the original sketch’s settings, not guaranteed performance figures. The sensor detects proximity, not rubbish specifically. This build does not measure how full the bin is, identify materials, sanitize the container, or connect to the internet. Its straightforward behavior makes it a good classroom or maker demonstration, not a finished household appliance.
Recommended Free Tools
Parts and servo choice
- Arduino Uno or compatible board
- HC-SR04 ultrasonic distance sensor
- Hobby servo and matching servo horn
- Bin with a hinged, movable lid
- Lightweight linkage material, such as a stick or stiff cardboard
- Jumper wires; a breadboard is optional
- USB cable or appropriate power supplies
- Mechanical fasteners or adhesive suitable for the bin and linkage
The Hackster page’s parts list names a Tower Pro MG996R, while its construction text says the author used an SG90 micro-servo. That inconsistency matters: an SG90 may suit a very light craft lid, while an MG996R-class servo needs more current and a sturdier power arrangement. Choose according to the lid’s weight and hinge resistance, not the project name. A similar Arduino Project Hub cardboard-bin build also uses an Uno, SG90, HC-SR04, and simple craft materials.
#1 Best Overall
- Premium Motion Sensor Trash Can or Recycling Bin - Experience the smoothest, most seamless lid opening and closing with this EKO hands-free trash can or recycling bin, delivering effortless, hygienic, and touch-free waste disposal.
- Ultimate Fingerprint Resistance - Say goodbye to smudges and hello to a clean flawless exterior that stays immaculate. The anti-fingerprint stainless steel finish keeps your space clean and stylish.
- Sleek and Durable Finish - Meticulously crafted with a stainless steel finish, this stylish touchless trash can offers a cool and smooth texture that’s durable and visually appealing for any home decor style.
- 25% More Capacity - No liner design maximizes capacity by offering 25% more room to dispose of the trash.
- Long-lasting Power - Use with AA alkaline batteries and can last up to 8 months of use, making our kitchen garbage can eco-friendly and your wallet happy.
Wiring
The original pin assignments are shown below. They are not mandatory: if you change a signal pin, change the corresponding pin number in the sketch too.
| Part | Connection |
|---|---|
| Servo signal | Arduino digital pin 3 |
| Servo VCC | Suitable servo supply; the original project uses Arduino 5 V |
| Servo ground | Ground; connect external supply ground to Arduino GND if using separate power |
| HC-SR04 TRIG | Arduino digital pin 6 |
| HC-SR04 ECHO | Arduino digital pin 5 |
| HC-SR04 VCC | Arduino 5 V |
| HC-SR04 GND | Arduino GND |
For a light SG90 prototype, Arduino 5 V may work, but do not assume the board’s 5 V rail can power every servo. Servos draw current in bursts, especially when starting or pushing against a load. A larger servo or heavy lid can cause resets, twitching, erratic readings, or USB disconnects. Use a regulated supply rated for the servo’s voltage and current; keep the grounds common. Never connect a servo directly to an arbitrary 9 V battery. Arduino’s Smart Trash Can example likewise shows separate supplies for the board and servo.
Rank #2
- Customer Notice: The 2.2-gallon bathroom trash can is highly suitable for use in relatively narrow spaces, with dimensions of 7.64"L x 5.12"W x 12.2"H, it doesn't look very big, and customers will need to install 2 AA batteries (not included)
- Motion Sensor Trash Can: This touchless bathroom trash can utilizes advanced infrared sensing technology, 0.1 seconds of sensing automatically open the lid, and automatically close the lid if no object movement is detected within 5 seconds
- Manual Normally Open: If you need to keep the trash can open for an extended period, you can manually press the up-arrow button. After use, simply press the down-arrow button to close the lid of the trash can
- Prevents Spreading of Odors: The smart trash can with lid and a one-piece barrel design, ensures a fully sealed enclosure that effectively isolates odors from garbage, maintaining a fresh and pleasant indoor environment
- Waterproof & Moisture-Proof: This automatic trash can is made of high-quality ABS material, robust, and the bottom is non-slip. With an IPX5 waterproof rating, adapt to the bathroom splash environment, to ensure a long time use
Mount and calibrate the mechanism
- Place the sensor. Aim it toward the approach area without pointing at the floor, bin rim, or a nearby wall. Leave room for the lid to move without blocking the sensor.
- Test the servo unloaded. Before attaching the linkage or lid, command small movements and confirm the horn can move freely.
- Find safe endpoints. The original uses 50 degrees to open and 160 degrees to close, but your mounting orientation may reverse those directions. Start with conservative values and expand travel gradually.
- Attach the linkage loosely at first. Align the servo horn and lid so the servo moves the lid through its natural range rather than pushing it into a hard stop.
- Check the load by hand. With power disconnected, move the lid through its travel. Correct hinge friction or binding before asking the servo to lift it.
- Test actual detection distance. Place a hand where a user would approach and adjust the threshold to suit the installation. The original 50 cm threshold is a software setting, not a promise that every object will be detected at that distance.
The Arduino Servo library controls ordinary positional hobby servos, but usable travel varies by servo and mechanism. Never force a shaft against a mechanical stop; a stalled servo can draw excessive current and heat up.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →The published sketch and its limitations
The original sketch is compact and illustrates the basic idea:
Rank #3
- [TOUCH-FREE CONVENIENCE] Messy hands? No problem. A quick wave opens the lid instantly, keeping your hands clean and your cooking flow completely uninterrupted.
- [MADE FOR YOUR SPACE] Big on capacity, smart on space. The 13-gallon size easily handles bulky takeout boxes, while the rectangular profile sits perfectly flush against your kitchen islands or walls.
- [KEEP IT SMELLING FRESH] Say goodbye to lingering food smells. The precision-fit lid closes softly and securely, automatically sealing stubborn odors inside.
- [LOOKS GOOD, STAYS CLEAN] Spend less time wiping things down. The all-silver, fingerprint-resistant stainless steel stays looking clean, while a removable liner ring makes for easy bag changes and keeps messy edges completely out of sight.
- [EVERYDAY PEACE OF MIND] We build essentials meant to last. Enjoy up to 9 months of reliable power on 2 D-batteries (not included), plus a friendly two-year support program to keep your home running smoothly.
#include <Servo.h>
Servo servo;
int const trigPin = 6;
int const echoPin = 5;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.attach(3);
}
void loop()
{
int duration, distance;
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
if (distance <= 50 && distance >= 0)
{
servo.write(50);
delay(3000);
}
else
{
servo.write(160);
}
delay(60);
}
The sensor emits an ultrasonic pulse and measures the time for its echo to return. The original expression estimates centimeters from the round-trip duration. It is suitable only as a rough proximity trigger, not a precision measurement. The sketch also has three practical weaknesses: its trigger pulse is longer than necessary, pulseIn() has no explicit timeout, and delay(3000) stops the program from checking the sensor while it waits. If someone remains in range, the lid may repeatedly receive an opening command or fail to close as expected.
A more robust starter sketch
This version uses a 10-microsecond trigger pulse, rejects missing echoes, tracks whether the lid is open, uses a non-blocking timer, and separates opening and closing thresholds to reduce rapid toggling. It is an improved example, not the original author’s code. It still needs mechanical calibration and does not include averaging or a safety sensor for an obstructed lid.
Rank #4
- [TOUCH-FREE CONVENIENCE] Messy hands? No problem. A quick wave opens the lid instantly, or just tap the button to keep it resting open for those bigger kitchen cleanups.
- [MADE FOR YOUR SPACE] Big on capacity, smart on space. The 13-gallon size features a wide oval opening for bulky waste, while the smooth profile tucks nicely against cabinets.
- [KEEP IT SMELLING FRESH] Say goodbye to lingering food smells. The precision-fit lid closes softly and securely, automatically sealing stubborn odors inside.
- [LOOKS GOOD, STAYS CLEAN] Spend less time wiping things down. The fingerprint-resistant stainless steel stays looking clean, while a removable liner ring makes for easy bag changes and keeps messy edges completely out of sight.
- [EVERYDAY PEACE OF MIND] We build essentials meant to last. Enjoy up to 9 months of reliable power on 3 C-batteries (not included), plus a friendly two-year support program to keep your home running smoothly.
#include <Servo.h>
Servo lidServo;
const byte SERVO_PIN = 3;
const byte TRIG_PIN = 6;
const byte ECHO_PIN = 5;
const int OPEN_ANGLE = 50;
const int CLOSED_ANGLE = 160;
const unsigned long OPEN_TIME = 3000;
const int OPEN_DISTANCE_CM = 50;
const int CLOSE_DISTANCE_CM = 60;
bool lidOpen = false;
unsigned long openedAt = 0;
long readDistanceCm()
{
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
unsigned long duration = pulseIn(ECHO_PIN, HIGH, 30000UL);
if (duration == 0) {
return -1; // no valid echo
}
return duration / 58; // approximate centimeters
}
void setup()
{
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
lidServo.attach(SERVO_PIN);
lidServo.write(CLOSED_ANGLE);
}
void loop()
{
long distance = readDistanceCm();
unsigned long now = millis();
if (!lidOpen && distance >= 0 && distance <= OPEN_DISTANCE_CM) {
lidServo.write(OPEN_ANGLE);
lidOpen = true;
openedAt = now;
}
if (lidOpen &&
now - openedAt >= OPEN_TIME &&
(distance < 0 || distance >= CLOSE_DISTANCE_CM)) {
lidServo.write(CLOSED_ANGLE);
lidOpen = false;
}
delay(60);
}
Change OPEN_ANGLE and CLOSED_ANGLE to match your installation. Adjust the opening threshold and closing threshold to create a gap: here, the lid opens at 50 cm or nearer, then can close only once the reading is at least 60 cm (or there is no valid echo) and the open time has elapsed. Treating a missing echo as clear space is a design choice, not an obstruction-safety guarantee; if the lid could injure someone or damage something, use a safer mechanism and control strategy rather than relying on this example.
The HC-SR04 library documentation and SimpleUltrasonic documentation describe library-based alternatives for distance readings. Libraries do not remove the need to choose appropriate filtering, timeout, and failure behavior.
Best Value
- Smart Sensor - Featuring infrared motion sensing, this automatic trash can offers a hands-free experience. Simply wave your hand above the sensor, and the lid opens automatically within 0.3 seconds. After 5 seconds of inactivity, the lid softly closes to conserve battery life. Please use 2 AA batteries(Excluded)
- IPX5 Waterproof - This sensor trash bin is perfectly suited for humid environments like bathrooms. It resists water splashes and prevents moisture from affecting the mechanism of lid. A quick wipe keeps it clean, with no water stains left behind.
- Space-Saving Design - The slim and compact shape of this hands-free trash can makes it perfect for narrow spaces. Its 2-gallon capacity is ideal for bathrooms, bedrooms, kitchens, and offices, providing adequate storage while maximizing space utilization. The packaging features a nested protective design. (10.1L*5.4W*11.38H Inch)
- Trash Bag Fixed Ring - The removable inner ring securely holds trash bags in place and keeps them discreetly hidden for a clean, organized look. It ensures that the bag does not slip off, even when disposing of heavier waste, making trash disposal more convenient and tidy.
- Multi-Scenario Applications - This motion sensor garbage can is suitable for various spaces—bathrooms, kitchens, bedrooms, offices, dorms, RVs, and more. Its modern and practical design blends seamlessly with any room décor while providing efficient waste management.
Troubleshooting by symptom
| Symptom | Likely cause | What to check |
|---|---|---|
| Lid opens but stays open | Object remains inside the threshold; linkage binds; servo stalls; or the sketch is waiting through its blocking delay | Clear the sensor area, check free lid travel, verify angle assignments, and use state-based timing with a close threshold farther away than the open threshold. |
| Servo jitters or Arduino resets | Servo current spikes, weak supply, long thin wires, or mechanical resistance | Test with the lid disconnected; use a suitable separate regulated servo supply and common ground; check the linkage for binding. |
| False openings | Sensor sees the bin, floor, a person, or reflections; soft or angled objects return weak echoes | Reposition the sensor, shorten the threshold, and require repeated near readings before opening. Keep the servo’s electrical noise away from sensor wiring where practical. |
Program appears stuck at pulseIn() |
No timeout in the original call means it may wait a long time for an echo | Use the timeout form and treat a returned duration of zero as no valid echo. |
| Servo moves the wrong way or strains | Mounting orientation or linkage geometry differs from the example | Reverse the open/closed assignments if needed, test without the lid, and reduce travel until the mechanism clears its stops. |
| Lid will not lift | Servo lacks torque, lid is heavy, or hinge friction is high | Lighten the lid, improve leverage and hinge alignment, or select a suitable stronger servo with an adequate power supply. |
For a no-opening fault, isolate components: first confirm the Arduino is powered and the sketch uses the same pins as the wiring; then test the servo by itself; then test sensor readings without the servo attached. That sequence helps distinguish code, sensor placement, power, and mechanical problems. Provide a manual way to open the bin and disconnect power if the lid jams.
Reliability and safety
- Keep electronics and wiring away from liquid and waste. Protect the sensor face from dirt and moisture; contamination or condensation can make readings unreliable.
- Guard the linkage and hinge against pinching fingers, clothing, or pets. Do not let the servo force a blocked lid.
- Use a regulated supply that matches the servo specification. Secure batteries and wiring, and do not leave an improvised hot-glued mechanism unattended near wet waste or combustible material.
- Keep wires clear of the lid’s path and mount the servo firmly. A loose mount changes the linkage geometry and can lead to binding.
- Remember that ultrasonic readings depend on placement and the target surface. A soft, angled, or irregular object may not produce a dependable echo.
For a compact installation, a smaller Arduino-compatible board can reduce the enclosure size, but check its logic voltage, pin behavior, regulator limits, and Servo library compatibility before connecting an HC-SR04 or servo. A time-of-flight sensor may be a cleaner sensing upgrade, while PIR detects movement rather than distance. Networked boards add monitoring possibilities, but are unnecessary if the only goal is to move a lid; Arduino’s connected smart-trash-can concept is a separate upgrade path.
Verdict: The Trash-Bot is a worthwhile educational build for a light lid and low-duty-cycle use. For dependable operation, prioritize safe servo power, free-moving linkage, calibrated angles, sensor timeout handling, and state-based control. It should not be treated as a sealed commercial bin or a safety-rated mechanism.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.


Leave a Reply