Skip to content

#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.

Components

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
import utime

servo=PWM(Pin(21,Pin.OUT))
trigger = Pin(15, Pin.OUT)
echo = Pin(14, Pin.IN)

servo.freq(50)
servo.duty_u16(1920) #15 degree

def getDistance():
   trigger.low()
   utime.sleep_us(2)
   trigger.high()
   utime.sleep_us(5)
   trigger.low()
   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:
    utime.sleep(0.01)
    if int(getDistance())<=10:
        servo.duty_u16(4010) #70 degree
        utime.sleep(1)
    else:
        servo.duty_u16(1920)

GitHub Project Page

Arduino IDE Codes


#include <Servo.h>
#define trigPin 14
#define echoPin 15
Servo servo;
void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  servo.attach(21);
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1; 
  if (distance < 80) {
    Serial.print(distance);
    Serial.println(" cm");
    servo.write(179);
  }

  else if (distance<180) {
    Serial.print(distance);
    Serial.println(" cm");
    servo.write(100); 
  }
  

}
Prev Post
Next Post

Thanks for subscribing!

This email has been registered!

Shop the look
Choose Options

Edit Option

Back In Stock Notification

Compare

Product SKURatingDescription Collection Availability Product Type Other Details
this is just a warning
Login
Shopping Cart
0 items
Same Day Shipping No Extra Costs
Easy Returns Guarantee Return with Ease
Secure Checkout Secure Payment