corn_isamazing
Published

Smart trash can!

When you put trash in front of it, the lid opens on itself!

BeginnerShowcase (no instructions)1,762
Smart trash can!

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Arduino UNO
Arduino UNO
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
9V 1A Switching Wall Power Supply
9V 1A Switching Wall Power Supply
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Male/Male Jumper Wires
×1

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

A bad picture of the wiring

This is the wiring for the trash can the servo and the ultra sonic sensor are drawn from the breadboard and the pins go to the arduino.

Code

Trash can

C/C++
you put it in the IDE and read it to find what pins go where and such
#include <Servo.h>
Servo servo1;
int trigPin = 9;
int echoPin = 8;
long distance;
long duration;
 
void setup() 
{
servo1.attach(7); 
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);// put your setup code here, to run once:
}
 
void loop() {
  ultra();
  servo1.write(90);
  if(distance <= 10){
  servo1.write(90);
  delay(5000);
  }

  if(distance > 10){
    
    servo1.write(0);
  }
}
 
void ultra(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.034/2;
  }

Credits

corn_isamazing
0 projects • 0 followers

Comments