하누리gledel김민철김태현김민수
Published

Auto-Opening Trash Can

This is trash can uses an ultrasonic sensor to open the cap automatically.

BeginnerProtip5 hours909
Auto-Opening Trash Can

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Jumper wires (generic)
Jumper wires (generic)
×11
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Servos (Tower Pro MG996R)
×1
9V battery (generic)
9V battery (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Schematics

12002-01_wBqOjt2vIH.jpg

Code

Auto-Opening Trash can

Arduino
It is a trash can for handicapped. It opens when distance from things to trash can is lower than 8mm.
#include <Servo.h>
Servo cover;
const int trigPin=3;
const int echoPin=2;
long dist;
long dura;
void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  cover.attach(7);
  cover.write(0);
  Serial.begin(9600);
}
void loop(){
  ultra();
  opening();
}
void ultra() {

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  dura = pulseIn(echoPin, HIGH);
  dist = dura*0.034/2;
  Serial.println("distance="+String(dist));
}
void opening(){
  if(dist < 8){
    cover.write(110);
  }
  else{
    cover.write(0);
  }
}

Credits

하누리
2 projects • 0 followers
gledel
100 projects • 117 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"
김민철
0 projects • 0 followers
김태현
0 projects • 0 followers
김민수
0 projects • 0 followers

Comments