Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
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.

BeginnerFull instructions provided79,821
Arduino Trash-Bot (Auto-Open/Close Trash Bin)

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Servos (Tower Pro MG996R)
×1
UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

arduino trash-bot

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

5 projects • 82 followers
Love to kill Soft things with Python and C++, Hard things with Soldering Iron.

Comments