Skip to content
International Shipping
Wish Lists Cart
0 items

#21 Automatic Trash Bin Project With PicoBricks

04 Nov 2023
#21 Automatic Trash Bin Project With PicoBricks
An automatic opening and closing trash can greatly simplify the process of disposing of your garbage and waste. In this project, the trash can we are going to make seems to understand when you're about to throw something away; it opens its lid when you bring your hand close and closes when you move it away. For this, we are using a Raspberry Pi and an Ultrasonic sensor. Let's start working on the project.
The Covid 19 pandemic has changed people’s daily routines. In many areas, such as cleaning, working, shopping and social life, people were introduced to a series of new rules that they had to comply with. Covid-19 has LED to the development of new business areas as well as some products that stand out. At a time when hand hygiene was very important, no one wanted to touch the lid of the trash cans to throw away their garbage.


Trash bins that open automatically when approached, and when full, make bags ready to be thrown away, found buyers at prices far above their cost. In addition, automatic disinfectant machines provided contactless hygiene by pouring a certain amount of liquid into our palms when we held our hands under them. Automatic disinfectant machines took place on the shelves at prices well above their cost. These two products have similarities in terms of their working principles. In automatic disinfectant machines, a pump with an electric motor or a servo motor, dispenses the liquid. In automatic trash bins, a servo motor that opens the lid was used, and infrared or ultrasonic sensors were used to detect hand movement. 

In this project, you will make an automatic stylish trash bin for your room using an ultrasonic sensor and servo motor with PicoBricks.

Details and Algorithm

HC-SR04 ultrasonic distance sensor and SG90 servo motor will be used in this project. When the user puts his hand in front of the lid of the trash can, the distance sensor will detect the proximity and notify  the program. Your program will then open the lid of the garbage can by running a servo motor and will close it again after a short while.


1X PicoBricks
1X HC-SR04 Ultrasonic Sensor
1X Servo Motor
Jumper Cables
Easy Connection Cables

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

Construction Stages of the Project

You can download the 3D drawing files of the project from this link and get 3D printing.

1: Fix it by screwing it to the trash bin cover of the servo motor apparatus.

2: Fix the ultrasonic distance sensor on the lid of the trash bin with the hot glue.


Automatic Trash Bin Project

3: Pass the cables of the ultrasonic distance sensor through the hole in the box and connect them to the pins shown in the PicoBricks circuit diagram, make the servo motor and motor driver connections. 4: Fix the servo motor, PicoBricks and motor driver parts to the box with hot glue.

If everything went well, when you put your hand close to the garbage can, the lid of the bucket will open and it will close again after you throw the garbage away.



MicroBlocks Codes of the PicoBricks

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button.


Microblocks Run Tab

MicroPython Codes of the PicoBricks


from machine import Pin, PWM
from utime import sleep

servo = PWM(Pin(21, Pin.OUT))
trigger = Pin(15, Pin.OUT)
echo = Pin(14, Pin.IN)
servo.duty_u16(1920)  # 15 degree

def getDistance():
    while echo.value() == 0:
        signaloff = utime.ticks_us()
    while echo.value() == 1:
        signalon = utime.ticks_us()
    timepassed = signalon - signaloff
    distance = (timepassed * 0.0343) / 2
    print("The distance from object is ", distance, "cm")
    return distance

while True:
    if int(getDistance()) <= 10:
        servo.duty_u16(4010)  # 70 degree

Arduino C Codes of the PicoBricks


#include <Servo.h>
#define trigPin 14
#define echoPin 15
Servo servo;

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance < 80) {
    Serial.println(" cm");
  } else if (distance < 180) {
    Serial.println(" cm");

GitHub Project Page
Prev Post
Next Post

Thanks for subscribing!

This email has been registered!

Shop the look
Choose Options

Edit Option

Have Questions?

Back In Stock Notification


Product SKUDescription Collection Availability Product Type Other Details

Terms & Conditions

What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
this is just a warning
Shopping Cart
0 items