Introduction: Garbage Can
In this project, we took 2 components and made them work together. This project will use an Ultrasonic sensor(distance sensor) and a servo motor. The Ultrasonic sensor will be used alongside with a servo motor to create an automatic opening and closing garbage can. The Ultrasonic sensor calculated the distance and if there is an object within 50 cm of the sensor then it will trigger the servo sensor function. Afterwards, the servo will turn 180 degrees and since it is tied to the cardboard by the string it will lift the lid open. The servo has a 2-second delay on it and then it will close afterwards.
Hot Glue Stick
Hot Glue Gun
Jumper Wires (Both Male to Male and Female to Female)
Step 1: Code
#include //servo library
int trigPin = 5;
int echoPin = 6;
int servoPin = 7;
int led= 10;
long duration, dist, average;
long aver; //array for average
servo.write(0); //close cap on power on
duration = pulseIn(echoPin, HIGH);
dist = (duration/2) / 29.1; //obtain distance
for (int i=0;i<=2;i++) //average distance
delay(10); //delay between measurements
if ( dist<50 ) //Change distance as per your need
Step 2: Making the Can
First, you need to create the lid of the garbage can. You can do this with cardboard. Firstly you need to take a piece of cardboard bigger than the top of the bin. Next, place the bin upside down to trace a circle on the cardboard. Cut the Cardboard out and then cut it in half. After cutting the cardboard in half tape it back together.
Step 3: Wiring and the Placing the Sensors
Now Wire the Servo Motor according to the given Diagram and you have complete the project.