CategoriesLed Raspberry Pi Pico Uncategorized

#21 Automatic Trash Bin Project with PicoBricks

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.

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.

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.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:
    sleep(0.01)
    if int(getDistance())<=10:
        servo.duty_u16(4010) #70 degree
        utime.sleep(0.3)
        servo.duty_u16(1920)
				
			

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);
  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); 
  }
  

}
				
			

Project Image

Project Proposal 💡

As in this project, where we automate a trash can in our house using sensors and motors, you can have a drawer or a cabinet door open automatically with the help of sensors and motors.

Leave a Reply

Your email address will not be published.