lucas_fernando_maker
Published © GPL3+

How To Make An Automatic Trash Bin Using Cardboard

Learn how to build an automatic trash bin using the ultrasonic sensor, a servo motor, and cardboard.

BeginnerFull instructions provided793
How To Make An Automatic Trash Bin Using Cardboard

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Scissor, Electrician
Scissor, Electrician
Cardboard
Barbecue skewers

Story

Read more

Schematics

Trash bin schematics

The sensor is supplied by 5V and the servo is connected to 3.3V pin.

Code

Trash bin code

Arduino
This is the code I wrote for this project. You need to install the Servo library if you don't have it on your Arduino IDE. Modify the openCloseDelay value to make the lid open and close faster or slower.
#include <Servo.h>

int servo = 7 ;
int trigger = 8;
int echo = 9;
int angle = 90;
int servoDelay = 2;
int sensorDelay = 10;
int openCloseDelay = 2000;
long duration = 0;
float distance = 0;

Servo myServo;

void setup() {
  Serial.begin(9600);
  pinMode(trigger, OUTPUT);
  pinMode(echo, INPUT);

  digitalWrite(servo, LOW);
  digitalWrite(trigger, LOW);

  myServo.attach(servo);
  myServo.write(angle);
}

void loop() {
  delay(sensorDelay);
  digitalWrite(trigger, HIGH);
  delay(sensorDelay);
  digitalWrite(trigger, LOW);
  duration = pulseIn(echo, HIGH);
  distance = duration * 0.034 / 2;
  Serial.println(distance);

  if (distance <= 50.0) {
    angle = 0;
    myServo.write(angle);
    delay(openCloseDelay);  
  } else {
    angle = 90;
    myServo.write(angle);
    delay(openCloseDelay);  
  }
}

Credits

lucas_fernando_maker

lucas_fernando_maker

3 projects • 3 followers

Comments