Ömer Beden
Published © GPL3+

Smart Trash

Smart Trash can be done with servo motors or stepper motors.

BeginnerShowcase (no instructions)1 hour31,655
Smart Trash

Things used in this project

Hardware components

servo motor
×1
Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
9V battery (generic)
9V battery (generic)
×1

Story

Read more

Schematics

circuit

Code

Untitled file

C/C++
#include<Servo.h>                //Adding the Servo library

Servo myservo;            //Define an object named MyServo
const int eko=8;        
const int trig=7;        
int mesafe;
int sure;

void setup() {
  myservo.attach(9);           //We introduced the ninth pin arduino to the servo motor
  pinMode(trig,OUTPUT);        
  pinMode(eko,INPUT);          
}

void loop() {
  myservo.write(0);       
  Serial.begin(9600);     
  
 
   
  digitalWrite(trig, LOW);         
  delayMicroseconds(10);
  digitalWrite(trig, HIGH);       
  delayMicroseconds(20);
  digitalWrite(trig, LOW);         
  sure = pulseIn(eko, HIGH);      
  mesafe= (sure/29.1)/2;  
  

  if(mesafe<=5){
    myservo.write(160);
    delay(5000);   
  }
  
   
  if(mesafe>200)
mesafe=200;
Serial.print("mesafe");
Serial.println(mesafe);
delay(500);
}

Credits

Ömer Beden

Ömer Beden

1 project • 14 followers
Computer Engineering at Dumlupınar University -Turkey

Comments