0

Trash bin Automation Arduino DIY

5 sao

sorry we are not native speakers, so the content may not be clear. We just want to share with you!

Nowadays, there are more and more types of automatic trash bin, especially smart trash bin of famous brands like Xiaomi with extremely features and designs. Since then espitek has also made its own automatic trash can, with just a regular trash can and a few components, we will have a self-opening trash can right away.

smart trash bin
smart trash bin

Read more:

Components used for homemade trash bin automation:

  • Arduino board
  • Servo
  • SRF05 sensor
  • 5V adv power
  • Glue Guns

Working principle of self-closing trash bin

A regular trash bin we often use will have a pedal under the foot to open the lid. We will use this type of trash to make a smart trash can together.

regular trash bin
regular trash bin

Instead of having to step on the trash can, we will use a servo to do this, taking advantage of the fact that the servo can rotate with custom angles, we will let it rotate at the right angle that can pull the pedal of the trash can. down. The link from the top of the servo to the pedal uses a wire, after the proximity sensor detects it, it will trigger the servo to rotate at an angle (the pedal is pulled down to help the trash can lid open automatically), after a period of time 5s will rotate the servo to the original angle (the lid always tends to close, so when it is returned to the old state, the trash can lid will automatically close).

Servo simulator use for smart trash bin
Servo simulator use for smart trash bin
  1. To connect between Arduino and Servo, we connect according to the following diagram:
Connect arduino and servo
Connect arduino and servo

Read more how to control servo use arduino

  1. Next, to automatically detect an object or person approaching, we will use the proximity sensor SRF05.
Connect arduino and SRF05 sensor

Programming to build smart trash bin

#include <Servo.h>
#define TRIG_PIN_SS 12
#define ECHO_PIN_SS 11
#define TIME_OUT 5000
#define Servo_SS 3

Servo myservoSS;       
float GetDistanceSS()
{
  long durationSS, distanceCmSS;
   
  digitalWrite(TRIG_PIN_SS, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN_SS, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN_SS, LOW);
  
  durationSS = pulseIn(ECHO_PIN_SS, HIGH, TIME_OUT);
 
  // convert to distance
  distanceCmSS = durationSS / 29.1 / 2;
  
  return distanceCmSS;
}

void setup() {  
  //Serial.begin(9600);
  myservoSS.attach(Servo_SS); 
  pinMode(TRIG_PIN_SS, OUTPUT);
  pinMode(ECHO_PIN_SS, INPUT);
  myservoSS.write(0);
}
 
void loop() {
  long distanceSS = GetDistanceSS();
  
  if (distanceSS >= 20)
  {
    myservoSS.write(90);
  }
  else
  {   
    myservoSS.write(0);
  }
  delay(5000);
}

Explain

float GetDistanceSS()
{
  long durationSS, distanceCmSS;
   
  digitalWrite(TRIG_PIN_SS, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN_SS, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN_SS, LOW);
  
  durationSS = pulseIn(ECHO_PIN_SS, HIGH, TIME_OUT);
 
  // convert to distance
  distanceCmSS = durationSS / 29.1 / 2;
  
  return distanceCmSS;
}

We declare the variables and include the Servo library (available in the arduino ide) as usual, next we will write a function that calculates the distance returned by the proximity sensor.

void loop() {
  long distanceSS = GetDistanceSS();
  
  if (distanceSS >= 20)
  {
    myservoSS.write(90);
  }
  else
  {   
    myservoSS.write(0);
  }
  delay(5000);
}

In the loop, we will proceed to receive the distance value returned by the function above and then compare if < 20cm, then we will proceed to let the servo rotate at an angle of 90 degrees (this angle can be adjusted accordingly. with my application so that the servo can rotate the angle that causes the pedal of the trash can to be pulled down just enough). Then wait 5s, it will return the servo to an angle of 0 degrees (this angle can also be customized so that the trash can closes the lid by itself).

Done, hope the article helps you create a smart trash can for your personal use

Leave a Reply

Your email address will not be published.