hrsajjad844
Published © MIT

Smart Bin

This bin will work automatically. You can drop dust without a touch. It can be kept in a small space likely a comfort zone.

AdvancedShowcase (no instructions)477
Smart Bin

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×10
USB Cable For Arduino Uno
×1
A Basket
×1
A Carton
×1
9V battery (generic)
9V battery (generic)
×2
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Story

Read more

Schematics

Power Supply

Here is the power supply system.

Code

Code

C/C++
Here is the project code.
#include <Servo.h>

Servo servo;

int trigPin = 5;
int echoPin = 6;
int servoPin = 7;
long duration, dist, average;
long aver[3];

void setup(){


  Serial.begin(9600);
  servo.attach(servoPin);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  servo.write(0);
  delay(100);
  servo.attach();
  

}


void measure(){

  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(15);
  digitalWrite(trigPin, LOW);
  pinMode(echoPin,INPUT);
  duration = pulseIn(echoPin, HIGH);
  dist = (duration/2)/ 29.1;
  
}

void loop(){


  for(int i=0; i<=2; i++){
    measure();
    aver[i]=dist;
    delay(10);
  }

  dist = (aver[0]+aver[1]+[2])/3;

  if(dist<50){

    servo.attach(servoPin);
    delay(1);
    servo.write(0);
    delay(3000);
    servo.write(150);
    delay(1000);
    servo.detach();
    
  }
  Serial.print(dist);
}

Credits

hrsajjad844

hrsajjad844

1 project • 16 followers

Comments