ashraf_minhaj
Published © LGPL

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

An automatic trash-bot that opens its lid if it sees any trash and closes after a certain delay.

EasyFull instructions provided2,426
Arduino Trash-Bot (Auto-Open/Close Trash Bin)

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Servos (Tower Pro MG996R)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

arduino trash-bot

Trash bot rn2jhmaxrg

arduino trash-bot code

Code

arduino trash-bot code

C/C++
#include<Servo.h>
Servo servo;
int const trigPin = 6;
int const echoPin = 5;
void setup()
{
pinMode(trigPin, OUTPUT); 
pinMode(echoPin, INPUT); 
    servo.attach(3);
}
void loop()
{       int duration, distance;
digitalWrite(trigPin, HIGH); 
delay(1);
digitalWrite(trigPin, LOW);
// Measure the pulse input in echo pin
duration = pulseIn(echoPin, HIGH);
// Distance is half the duration devided by 29.1 (from datasheet)
distance = (duration/2) / 29.1;
// if distance less than 0.5 meter and more than 0 (0 or less means over range) 
if (distance <= 50 && distance >= 0) {
	servo.write(50);
    delay(3000);
} else {
	
	servo.write(160);
}
// Waiting 60 ms won't hurt any one
delay(60);
}

Credits

ashraf_minhaj

ashraf_minhaj

1 project • 11 followers

Comments