Project showcase
Touchless Automatic Motion Sensor Trash Can

Touchless Automatic Motion Sensor Trash Can © CC BY

A touchless automatic motion sensor trash can.

  • 74,356 views
  • 44 comments
  • 127 respects

Components and supplies

Necessary tools and machines

Hy gluegun
Hot glue gun (generic)

Apps and online services

About this project

Video

Code

AutoTrashCan.inoArduino
#include <Servo.h> 

Servo myservo;
const int servo_pin = 2;
const int trig_pin = 3;
const int echo_pin = 4;
const int inter_time = 200;
int time = 0;

void setup() 
{
  Serial.begin(9600);
  myservo.attach(servo_pin, 500, 2400);
  myservo.write(90);
  pinMode (trig_pin, OUTPUT);
  pinMode (echo_pin, INPUT);
  delay(3000);
} 

void loop() 
{
  float duration, distance;
  digitalWrite(trig_pin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trig_pin, LOW);
  duration = pulseIn (echo_pin, HIGH);
  distance = (duration/2)/29;
  Serial.print(distance);
  Serial.println(" cm");
  time = time + inter_time;
  delay(inter_time);
  if (distance < 10)
  {
    for(int i = 1500; i >= 1100; i-=25){
      myservo.writeMicroseconds(i);
      Serial.println("2");
      delay(100);
    }
    delay(1000);
    for(int i = 1100; i <= 1500; i+=25){
      myservo.writeMicroseconds(i);
      Serial.println("1");
      delay(100);
    }
  }
}

Schematics

Comments

Similar projects you might like

Distance Sensor and OLED

Project tutorial by javier muñoz sáez

  • 51,139 views
  • 25 comments
  • 110 respects

Make an Autonomous "Follow Me" Cooler

Project tutorial by Hacker Shack

  • 247,586 views
  • 305 comments
  • 755 respects

Complete Digital Clock Including Alarm and Motion Sensor

Project showcase by LAGSILVA

  • 31,590 views
  • 37 comments
  • 97 respects

Automatic Fan with PIR Sensor and LM35 Sensor

by Jamaluddin

  • 15,389 views
  • 6 comments
  • 20 respects

Easy Motion and Gesture Detection by PIR Sensor & Arduino

Project tutorial by ElectroPeak

  • 93,070 views
  • 14 comments
  • 375 respects

Arduino Trash-Bot (Auto-Open/Close Trash Bin)

Project tutorial by ashraf_minhaj

  • 44,629 views
  • 7 comments
  • 37 respects
Add projectSign up / Login