What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
A Raspberry Pi smart dustbin can open its lid when it detects a nearby hand, then close it after the hand moves away. The simplest build uses an ultrasonic sensor, a servo, and a Raspberry Pi Zero 2 W. The key safety details are easy to miss: protect the Pi from the standard HC-SR04’s 5 V ECHO signal, and power the servo from a suitable supply rather than a GPIO pin.
This design is a touchless lid, not automatically a connected waste-monitoring system. Add a second sensor for an estimated fill level or Wi-Fi software for alerts only if you need those features.
What the smart dustbin does
An ultrasonic sensor measures the distance to an object near the bin. The Raspberry Pi checks that reading and signals a servo to move the lid. After the hand leaves the detection area, the program closes the lid.
Hand approaches → sensor measures distance → Pi validates reading → servo opens lid → hand leaves → servo closes lid
The basic version works locally and does not need an internet connection. A bin becomes networked when it sends readings or events to another device or service. A servo-operated lid alone does not measure how full the bin is, send alerts, or classify waste.
#1 Best Overall
- Multiple Functions: This car has four drive wheels, the rotatable head has a camera and an ultrasonic distance sensor (Assembly required) (Raspberry Pi and Battery NOT included)
- Detailed Tutorial: Provides step-by-step assembly guide and complete Python code (The download link can be found on the product box) (No paper tutorial)
- Compatible Models: Raspberry Pi 5 / 4B / 3B+ / 3B / 3A+ (2B / 1B+ / 1A+ / Zero 2 W / Zero W / Zero 1.3 is also compatible but needs extra parts) (NOT included in this kit)
- Control Methods: Controlled wirelessly by your Android phone or tablet, iPhone (with Freenove App) and computer (run Windows, macOS or Raspberry Pi OS)
- Battery NOT Included: Please refer to the downloaded tutorial to buy
Choose the controller
Raspberry Pi Zero 2 W is a sensible default for a lid, one or two sensors, and simple Wi-Fi notifications. It has a quad-core 1 GHz processor, 512 MB RAM, Wi-Fi and Bluetooth, in a 65 × 30 mm board. The standard board may not have its 40-pin header fitted, so check whether you need a header-equipped version or can solder one.
A Pi 4 is a reasonable choice if you already own one or want more room for a local dashboard. A Raspberry Pi 5 is unnecessary for a single sensor and servo; consider it for camera-based recognition, heavier local services, or multiple computer-vision tasks. Pi 5 needs an appropriate USB-C supply; Raspberry Pi recommends 5 V, 5 A. Its suitability does not remove the need to power the servo correctly.
If the project only needs to operate a sensor and servo, a Pico, Arduino, or ESP32 may be a better fit: microcontrollers generally start quickly and use less power. A Pi makes more sense when you want Linux, Python libraries, a camera, storage, or a conventional web interface.
Free tools Windows power users keep installed
One-click scans. No signup required.
Parts for a basic build
| Part | Purpose and selection notes |
|---|---|
| Raspberry Pi Zero 2 W or another GPIO-equipped Pi | Runs the control program. Confirm the GPIO header is installed. |
| MicroSD card and suitable Pi power supply | Holds Raspberry Pi OS and powers the board. The Zero family uses micro-USB power. |
| HC-SR04 ultrasonic sensor or a verified 3.3 V-tolerant equivalent | Detects a hand. A standard 5 V HC-SR04 needs a voltage divider on ECHO. |
| SG90-compatible micro-servo | Moves a lightweight lid. Check torque and stall-current specifications, not just the size label. |
| Regulated 5 V servo supply, wires, and breadboard | Supplies the servo current; grounds must be shared with the Pi. |
| Hinge, bracket, linkage, and lightweight lid | Transfers the servo movement. Friction and lid weight often cause more trouble than the code. |
| Two resistors for a divider, if using standard HC-SR04 | Reduces ECHO voltage to a safe GPIO level. |
Prices and stock depend on country and reseller. The Zero 2 W has an official $15 price signal, but that is not a promise of local availability or final checkout cost. The Pi 5 pricing announcement lists model-specific prices, but a basic lid project does not justify buying one on that basis alone.
Wire it safely
Important: Raspberry Pi GPIO uses 3.3 V logic. Do not connect a standard HC-SR04 powered at 5 V directly to a Pi GPIO on its ECHO output. Do not connect the servo’s power lead to a GPIO pin. Keep the electronics away from liquid, wet waste, and cleaning chemicals.
Rank #2
- This intelligent robot car kit utilizes a Raspberry Pi as its main controller, equipped with various sensors and functional modules, providing users with a rich interactive experience. Through a multi-platform client app (supporting Windows, macOS, iOS, and Android), you can easily control the car's various functions, including movement control, RGB light adjustment, and horn sound output.
- The kit is equipped with a multi-functional sensor system, including an ultrasonic module, photoresistor, and line-following module. These sensors enable the car to perform three intelligent modes: line following, light tracking, and ultrasonic obstacle avoidance. Additionally, the Windows client supports advanced face recognition and tracking features, adding more possibilities to your project.
- The camera module allows you to view the car's surroundings in real-time, enhancing the precision and enjoyment of remote control. Whether used for education, entertainment, or development projects, this multifunctional robot car can meet your needs.
- To ensure users can fully utilize all features of this kit, we provide comprehensive learning resources. In addition to detailed assembly videos and software user manuals, we also offer online documentation tutorials. These resources cover various aspects from basic setup to advanced programming techniques, allowing you to gradually master robotics technology and customize and extend your project according to your needs.
- Whether you're a programming novice or an experienced developer, this kit can bring you rich learning and innovation opportunities. Our online tutorials and video resources are regularly updated to ensure you always have access to the latest techniques and applications.
The following pin assignments use BCM GPIO numbers, not physical header pin numbers:
| Connection | BCM GPIO | Physical header pin |
|---|---|---|
| Ultrasonic TRIG | GPIO17 | 11 |
| Ultrasonic ECHO, through divider | GPIO18 | 12 |
| Servo control signal | GPIO12 | 32 |
| Sensor VCC, if the module requires 5 V | — | 5 V rail, pin 2 or 4 |
| Ground | — | For example, pin 6 |
For a standard HC-SR04, connect GND to Pi ground, VCC to the module’s required supply, and TRIG to GPIO17. Put a resistor divider between ECHO and GPIO18: GPIO Zero documents a 330 Ω resistor between ECHO and the GPIO-side junction and a 470 Ω resistor from that junction to ground. This reduces the signal before it reaches the Pi. An HC-SR04P or other module explicitly rated for 3.3 V logic may avoid the divider; verify the exact module’s specifications rather than relying on its name alone. See the GPIO Zero DistanceSensor wiring guidance.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Connect the servo’s signal wire to GPIO12. Servo wire colours vary, but red is often positive and brown or black often ground; check the device documentation. Supply servo power from a separate regulated 5 V source or a properly rated rail. Connect that supply’s ground to the Pi’s ground so the control signal has a common reference. The servo’s positive lead must not go to a GPIO pin.
Servos can draw a brief current surge when moving or meeting resistance. An inadequate supply can make the Pi reboot, make readings erratic, or cause servo jitter. For a loaded lid or multiple servos, use a separate supply and consider a dedicated servo driver such as a PCA9685; it does not replace the need for suitable servo power.
Prepare Raspberry Pi OS
Install a current Raspberry Pi OS release appropriate to your Pi, configure the network if needed, and boot the board. Raspberry Pi 5 requires a supported OS version: its product documentation lists current Trixie and legacy Bookworm support and says releases older than Bookworm do not support Pi 5. Do not apply that Pi 5 qualification indiscriminately to every model.
Rank #3
- The Raspberry Pi Raphael Starter Kit for Beginners: The kit offers a rich learning experience for beginners aged 10+. With 337+ components, 161 projects, and 70+ expert-led video lessons, this kit makes learning Raspberry Pi programming and IoT engaging and accessible. Compatible with Raspberry Pi 5/4B/3B+/3B/Zero 2 W /400, RoHS Compliant
- Expert-Guided Video Lessons: The Raspberry Pi Kit includes 70+ video tutorials by the renowned educator, Paul McWhorter. His engaging style simplifies complex concepts, ensuring an effective learning experience in Raspberry Pi programming
- Wide Range of Hardware: The Raspberry Pi 5 Kit includes a diverse array of components like Camera, Speaker, sensors, actuators, LEDs, LCDs, and more, enabling you to experiment and create a variety of projects with the Raspberry Pi
- Supports Multiple Languages: The Raspberry Pi 4 Kit offers versatility with support for 5 programming languages - Python, C, Java, Node.js and Scratch, providing a diverse programming learning experience
- Dedicated Support: Benefit from our ongoing assistance, including a community forum and timely technical help for a seamless learning experience
On Raspberry Pi OS, update the system and install GPIO Zero and its GPIO backend:
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemssudo apt update
sudo apt full-upgrade -y
sudo apt install -y python3-gpiozero python3-lgpio
mkdir -p ~/smart-dustbin
cd ~/smart-dustbin
nano smart_dustbin.py
Use pinout to check the board’s header layout and GPIO labels. If the GPIO package installation or access fails, check the OS version and current GPIO Zero installation guidance rather than assuming every image has identical packages or permissions.
Test the ultrasonic sensor first
Leave the servo disconnected while checking the sensor. Save this as a temporary test script or run it from a Python file:
from gpiozero import DistanceSensor
from time import sleep
sensor = DistanceSensor(echo=18, trigger=17, max_distance=2)
try:
while True:
print(f"Distance: {sensor.distance * 100:.1f} cm")
sleep(1)
except KeyboardInterrupt:
pass
finally:
sensor.close()
The reading should change as you move an object in front of the sensor. GPIO Zero expresses sensor.distance as a normalized value; multiplying by 100 gives centimetres for this example’s 2 m maximum distance.
If the output is implausible, check common ground, VCC, TRIG and ECHO orientation, BCM numbering, and the ECHO divider. Then check that the sensor is not pointed at a nearby wall, curved lid, or flexible surface. Ultrasonic readings can be unreliable for angled, soft, absorbent, or irregular targets. Keep the servo disconnected until the sensor test is stable.
Rank #4
- Two Working Modes: Video mode (with camera) and Radar mode (with ultrasonic distance sensor) (Assembly required) (Raspberry Pi and Battery NOT included)
- Detailed Tutorial: Provide step-by-step assembly guide and complete Python code (The download link can be found on the product box) (No paper tutorial)
- Compatible Models: Raspberry Pi 5 / 4B / 3B+ / 3B / 3A+ (2B / B+ is also compatible but needs extra parts) (NOT included in this kit)
- Control Methods: Controlled wirelessly by your Android phone or tablet, iPhone and computer (run Windows or Raspberry Pi OS)
- Battery NOT Included: Please refer to the downloaded tutorial to buy
Test and calibrate the servo before attaching the lid
With the servo powered appropriately and its ground tied to Pi ground, test small movements before connecting the linkage. A servo’s endpoints are not universal: min() and max() are not guaranteed to mean safe closed and open positions. Start with conservative positions, confirm the mechanism moves freely, and adjust in small increments. Stop if the servo buzzes against a hard stop or the lid binds; a stalled servo can draw excessive current.
Run a basic automatic-lid program
This example opens when a hand is within 25 cm, keeps the lid open while it continues to detect a nearby object, then closes it and waits briefly before another trigger. It is a starting point, not a guarantee that the pulse range or timing will suit every servo and mechanism.
from gpiozero import DistanceSensor, Servo
from time import sleep
TRIGGER_DISTANCE_CM = 25
OPEN_TIME_SECONDS = 3
COOLDOWN_SECONDS = 1
sensor = DistanceSensor(echo=18, trigger=17, max_distance=2)
servo = Servo(12, min_pulse_width=0.0005, max_pulse_width=0.0025)
# Calibrate these positions for your servo and linkage.
CLOSED_POSITION = -1
OPEN_POSITION = 1
try:
servo.value = CLOSED_POSITION
sleep(0.8)
while True:
distance_cm = sensor.distance * 100
if distance_cm <= TRIGGER_DISTANCE_CM:
servo.value = OPEN_POSITION
sleep(0.8)
elapsed = 0.0
while elapsed < OPEN_TIME_SECONDS:
if sensor.distance * 100 <= TRIGGER_DISTANCE_CM:
elapsed = 0.0
else:
elapsed += 0.1
sleep(0.1)
servo.value = CLOSED_POSITION
sleep(0.8)
sleep(COOLDOWN_SECONDS)
sleep(0.1)
except KeyboardInterrupt:
pass
finally:
servo.value = CLOSED_POSITION
sleep(0.5)
sensor.close()
servo.close()
In HTML, the less-than operators in the code are shown escaped as <; they become normal operators when displayed. In an actual Python file, write < as the ordinary less-than character in both comparisons.
Adjust the trigger distance, pulse widths, open and closed positions, and movement delays for the sensor placement and mechanism. This simple loop assumes the servo reached its commanded position; a typical hobby servo does not provide the Pi with position feedback. To know whether the lid actually moved, add a limit switch or another feedback sensor.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Improve detection so the lid behaves predictably
A single distance reading near one threshold can fluctuate and cause repeated opening and closing. A more robust design should:
Best Value
- Multiple Functions: Crawler chassis, liftable clamp, camera and ultrasonic distance sensor (Assembly required) (Raspberry Pi and Battery NOT included)
- Detailed Tutorial: Provides step-by-step assembly guide and complete Python code (The download link can be found on the product box) (No paper tutorial)
- Compatible Models: Raspberry Pi 5 / 4B / 3B+ / 3B / 3A+ (2B / 1B+ / 1A+ / Zero 2 W / Zero W / Zero 1.3 is also compatible but needs extra parts) (NOT included in this kit)
- Control Methods: Controlled wirelessly by your Android phone or tablet, iPhone (with Freenove App) and computer (run Windows, macOS or Raspberry Pi OS)
- Battery NOT Included: Please refer to the downloaded tutorial to buy
- Use hysteresis: open below one threshold, such as 25 cm, but consider the hand gone only after it remains beyond a separate threshold, such as 30 cm.
- Filter readings: require several consistent readings before opening. A median of recent readings can reduce the effect of occasional outliers.
- Use explicit states: track
CLOSED,OPENING,OPEN,CLOSING, and, if needed,FAULT. This makes it easier to avoid conflicting commands. - Keep the lid open for presence: close only after the hand has left for a defined interval, with a maximum-open timeout so a persistent false reading cannot leave it open indefinitely.
- Use a cooldown: briefly ignore a new trigger after closing and prevent the sensor from mistaking the moving lid for a hand.
Mount the outward-facing sensor so it sees an approaching hand before the lid moves, not the lid itself. Test the sensor with the mechanism at rest and through its full travel.
Build the mechanism around the lid
Begin with a lightweight lid, a low-friction hinge, and a servo bracket fixed firmly to the bin. Align the linkage so the servo is not forced sideways and does not need to push through a hard stop. A servo that can move an unloaded arm may still struggle with a lid that is heavy, stiff, or poorly balanced.
Keep wires clear of the hinge and linkage. Add strain relief where a cable moves with the lid, keep the Pi and connections in a ventilated enclosure outside the waste compartment, and leave access to a power switch or manual override. Check for pinch points and test the lid without fingers near the mechanism.
Estimate fill level with a second sensor
For a rough fill estimate, mount another distance sensor pointing downward into the bin. Calibrate the empty distance and the distance that represents “full.” Let empty_cm be the sensor-to-bottom distance when empty, full_cm the distance to the waste surface at the chosen full threshold, and current_cm the present reading:
fill_percent = 100 * (empty_cm - current_cm) / (empty_cm - full_cm)
fill_percent = max(0, min(100, fill_percent))
In code:
def fill_percentage(current_cm, empty_cm, full_cm):
usable_height = empty_cm - full_cm
if usable_height <= 0:
raise ValueError("Calibration values are invalid")
value = 100 * (empty_cm - current_cm) / usable_height
return max(0, min(100, value))
This is an estimated fill percentage based on distance to a surface, not a precise measurement of volume. Waste piles unevenly; bags, paper, angled packaging, bin walls, moisture, or internal supports can alter echoes. The sensor may also be blocked or need recalibration after the bin is emptied. Multiple sensors at different angles, a time-of-flight sensor, or a load cell with an ADC can improve the estimate, but each adds wiring, calibration, and cost.
Add network features only if you need them
A Zero 2 W can use Wi-Fi to send a fill estimate or maintenance alert, or host a small local dashboard. Possible additions include MQTT, Home Assistant, a Flask or FastAPI page, or SQLite event logging. The core lid should still work without a cloud service: local control avoids making a basic household mechanism depend on a network connection or paid account. If you add a network service, decide what data to retain and how the program recovers after a reboot.
For a continuously used installation, run the program as a service so it can start at boot, record useful errors, and recover cleanly. Test behavior after power loss. Do not treat software startup as a substitute for a safe mechanical resting position or an accessible power switch.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchQuick Recap
Troubleshooting
| Symptom | Likely causes | What to check |
|---|---|---|
| Pi reboots when servo moves | Servo surge, weak supply, loose ground, or overloaded linkage | Disconnect the servo and check Pi stability; use a separate regulated servo supply with common ground, reduce lid load, and limit travel. |
| Servo jitters | Noisy supply, loose ground, unsuitable pulse range, repeated commands, or mechanical resistance | Secure wiring, separate servo power, calibrate endpoints, reduce conflicting commands, and make sure the lid moves freely. |
| Sensor always sees something nearby | It faces the lid or wall, TRIG/ECHO are reversed, divider is missing, or wires are noisy | Test with the servo disconnected, print readings, verify BCM pins and divider, and reposition the sensor. |
| Lid cycles repeatedly | Threshold jitter, no cooldown, or sensor sees the moving lid | Add hysteresis and filtered readings, ignore readings during movement, add cooldown, and adjust mounting angle. |
| GPIO permission error | User lacks GPIO access or software setup differs | Check the current OS and GPIO Zero guidance. Raspberry Pi documents adding a user with sudo usermod -a -G gpio <username>; log out and back in for group membership to take effect. |
| Pi 5 limits peripherals or has power trouble | USB-C supply is not adequate for the board and attached peripherals | Use a suitable supply; Raspberry Pi recommends 5 V, 5 A for Pi 5. Power the servo separately as required. |
Safety and durability checklist
- Never feed a standard 5 V HC-SR04 ECHO signal straight into a Pi GPIO; use a divider or a verified 3.3 V-tolerant sensor.
- Never use a GPIO pin to supply servo power; provide suitable regulated power and common ground.
- Keep the board and wiring away from liquid, wet waste, condensation, and cleaning chemicals.
- Secure cables against movement, and keep them clear of hinges and pinch points.
- Test safe lid travel and provide an accessible power switch or manual override.
- Do not rely on the bin for hazardous, medical, biohazard, or industrial waste.
- Describe touchless operation accurately: it reduces hand contact with the lid, but does not sterilize the bin or establish infection prevention.
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