Home > Industry Insights >Gear Motor
TECHNICAL SUPPORT

Product Support

How to Control a Trash Can Lid Opening and Closing Using a Servo Motor

Published 2026-04-10

This guide provides a practical, step-by-step method to automatically open and close a trash can lid using a standardservomotor. By following these instructions, you will build a reliable hands-free lid control system suitable for kitchens, workshops, or offices. All examples are based on common household scenarios, using widely available components without any brand-specific references.

01Core Principle: How aservoMotor Moves the Lid

Aservomotor rotates its arm to a precise angle based on electrical pulses (PWM). For a trash can lid:

Closed position: Servo arm at 0° (or 90°, depending on mounting)

Open position: Servo arm at 90° (or 180°)

The motor attaches to the lid via a simple linkage or lever. When the servo rotates, it pushes or pulls the lid open; rotating back lets gravity or the servo close it.

02Required Components (No Brand Names)

1 standard micro servo (e.g., SG90-size or larger, 5V compatible)

1 microcontroller (Arduino Nano/Uno or any 5V logic board)

1 momentary push button or an HC-SR04 ultrasonic sensor (for hands-free trigger)

1 breadboard and jumper wires

1 battery holder with 4×AA batteries (or 5V USB power bank)

1 small trash can with a hinged lid (metal or plastic)

Mechanical parts: 2 small screws, a popsicle stick or metal bracket, and strong double-sided tape

03Step-by-Step Wiring (5 Minutes)

Common case:You have a typical kitchen trash can with a flat lid surface.

Connect the servo’sbrown/black wire(ground) to microcontroller GND.

Connect the servo’sred wire(power) to microcontroller 5V pin. (For continuous use, use external 5V battery pack to avoid overloading the board.)

Connect the servo’sorange/yellow wire(signal) to digital pin 9.

For trigger: attach a push button between digital pin 2 and GND (internal pullup enabled). Or for hands-free: connect HC-SR04 VCC to 5V, GND to GND, Trig to pin 3, Echo to pin 4.

04Programming the Servo (Copy-Ready Code)

Upload this code to your microcontroller. It uses the standard Servo library. The example below opens the lid when you press the button, holds it for 2 seconds, then closes.

#includeServo lidServo; const int servoPin = 9; const int buttonPin = 2; int buttonState = 0; bool lidOpen = false; void setup() { lidServo.attach(servoPin); pinMode(buttonPin, INPUT_PULLUP); // Start with lid closed lidServo.write(0); // Closed angle delay(500); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == LOW && !lidOpen) { // Open lid lidServo.write(90); // Open angle lidOpen = true; delay(2000); // Keep open for 2 seconds // Close lid lidServo.write(0); lidOpen = false; delay(300); // Debounce } }

For ultrasonic sensor (hands-free):

Replace the loop with distance measurement. When an object is within 10 cm, open the lid for 2 seconds.

05Mechanical Attachment – Real-World Examples

Case 1 – Plastic lid with flat front:

Use double-sided tape to attach the servo body to the can’s outer wall near the hinge. Glue a small lever (popsicle stick) onto the lid’s edge. Connect the servo arm to the lever with a stiff wire or zip tie. When the servo rotates, it pushes the lever upward – lid opens.

Case 2 – Metal lid with curved surface:

Screw a small L-bracket onto the lid. Attach a metal linkage rod from the servo arm to the bracket. Use a spring on the hinge to assist closing.

Important angles:Test your physical setup. You may need to changelidServo.write(0)andlidServo.write(90)to different values like 20° and 110° to achieve full open/close without jamming.

06Power Requirements and Common Mistakes

如何用舵机控制垃圾桶盖_如何用舵机控制垃圾桶盖开关门_自动开关垃圾桶原理

Symptom:Servo twitches but does not move the lid.

Cause:Insufficient current. Solution: Use separate 5V/2A power supply for servo; do not draw from microcontroller’s 5V pin.

Symptom:Lid closes too slowly or gets stuck.

Cause:Friction at the hinge. Solution: Lubricate hinge with vegetable oil or reduce the lever arm length.

Symptom:Servo buzzes continuously.

Cause:Mechanical obstruction. Solution: Adjust the closed/open angles in code until the servo stops fighting the lid.

07Testing and Calibration Procedure

1. Without attaching to the lid, run the code. Confirm servo rotates from 0° to 90° smoothly.

2. Manually move the lid – it should swing freely with little force.

3. Temporarily tape the servo arm to the lid linkage. Test with code: Does the lid fully open? If not, increase the open angle up to 180°.

4. Adjust the delay(2000) to your preference (e.g., 1 second for quick use, 5 seconds for sorting waste).

08Expanding to Automatic Touchless Operation

The same principle works with any trigger:

Infrared proximity sensor – wave hand to open.

Foot pedal switch – wired parallel to the button.

Voice module – say “open trash” (requires advanced programming).

For a common smart kitchen scenario: mount an ultrasonic sensor at the front of the lid. Set detection distance to 15 cm. When you approach with waste,the lid opens automatically and closes after you step away. This is identical to expensive commercial bins but built for under $10.

09Core Principle Restated

To control a trash can lid with a servo motor, you must:

1. Mount the servo so its rotation axis aligns with the lid’s hinge direction.

2. Use a rigid linkage to convert rotary motion into lifting force.

3. Write a simple servo sweep (0°→90°→0°) triggered by a sensor or button.

4. Provide adequate 5V power (≥1A for standard servos).

No brand-specific parts or proprietary software are required. Every household trash can can be upgraded using this method.

10Actionable Recommendations

Start with a small, lightweight lid (e.g., a 2-gallon step can) to avoid overloading the servo.

Always test the mechanical linkage by hand first – if you cannot lift the lid easily with your finger, the servo will fail.

Use a 180° servo for maximum angular flexibility. If using a 360° continuous rotation servo, you need a different approach (limit switches).

For daily use, add a manual override: a simple toggle switch that cuts servo power, letting you use the lid normally.

Document your angles – write down the exact write() values that achieve full open and full close. Keep them in the code comment.

By following this guide, you will have a working automatic trash can lid within one hour. The same circuit can control drawers, pet food containers, or recycling bins. Remember: the servo only needs two positions (open/closed) – no complex PID or feedback required. Start with the basic button version, then upgrade to sensor-based hands‑free operation.

Update Time:2026-04-10

Powering The Future

Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.

Mail to Kpower
Submit Inquiry
+86 0769 8399 3238
 
kpowerMap