Automatic Dustbin open and close using Ultrasonic sensor and Arduino

Introduction:

In this tutorial, we are going to solve a small problem related to garbage management. Let's make an automated bin using ultrasonic sensor and Arduino that will open automatically when any one is in front of it. And when he is done the bin gets automatically closed and vice versa.

Components required:

  1. A foot operated dustbin
  2. HC-SR04 Ultrasonic sensor
  3. 5 volt servo motor
  4. An Arduino UNO
Circuit Diagram:

Connect the wires to the respective components as shown in figure below:

(Note: first upload the code given below to the Arduino then only do the wiring to avoid short circuit from already stored program  in Arduino.)



Arduino Codes:

Copy and paste the codes given below to arduino IDE and upload it to arduino.

#include <Servo.h> 

Servo s1;

const int servo_pin = 2;

const int trig_pin = 3;

const int echo_pin = 4;

const int inter_time = 200;

int time = 0;

void setup() 

{

  Serial.begin(9600);

  s1.attach(servo_pin, 500, 2400);

  s1.write(90);

  pinMode (trig_pin, OUTPUT);

  pinMode (echo_pin, INPUT);

  delay(3000);

void loop() 

{

  float duration, distance;

  digitalWrite(trig_pin, HIGH);

  delayMicroseconds(1000);

  digitalWrite(trig_pin, LOW);

  duration = pulseIn (echo_pin, HIGH);

  distance = (duration/2)/29;

  Serial.print(distance);

  Serial.println(" cm");

  time = time + inter_time;

  delay(inter_time);

  if (distance < 10)

  {

    for(int i = 1500; i >= 1100; i-=25){

      s1.writeMicroseconds(i);

      Serial.println("2");

      delay(100);

    }

    delay(1000);

    for(int i = 1100; i <= 1500; i+=25){

      s1.writeMicroseconds(i);

      Serial.println("1");

      delay(100);

    }

  }

}

Now you are done with your code and circuit diagram and you can make your own modification if you want to.

Applications:

  1. People don't feel uncomfortable to put garbage in.
  2. Will make us a distance away from germs attached with the dustbin.
  3. City will have smart bin automation.
  4. A healthy and neat environment can be created.

Post a Comment

0 Comments