lakshyajhalani56
Published

Smart Dustbin using Arduino, Ultrasonic Sensor, Servo Motor

When person wants to throw a waste in Dustbin, Dustbin cap will automatically open without any physically touch.

IntermediateFull instructions provided32,637
Smart Dustbin using Arduino, Ultrasonic Sensor, Servo Motor

Things used in this project

Hardware components

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

Story

Read more

Schematics

Final Look

Code

Code of Smart Dustbin

C Header File
#include <Servo.h>

Servo servoMain; // Define our Servo

int trigpin = 10;

int echopin = 11;

int distance;

float duration;

float cm;

void setup()

{

servoMain.attach(9); // servo on digital pin 10

pinMode(trigpin, OUTPUT);

pinMode(echopin, INPUT);

}

void loop()

{

digitalWrite(trigpin, LOW);

delay(2);

digitalWrite(trigpin, HIGH);

delayMicroseconds(10);

digitalWrite(trigpin, LOW);

duration = pulseIn(echopin, HIGH);

cm = (duration/58.82);

distance = cm;

if(distance<30)

{

servoMain.write(180); // Turn Servo back to center position (90 degrees)

delay(3000);

}

else{

servoMain.write(0);

delay(50);

}

}

Credits

lakshyajhalani56

lakshyajhalani56

9 projects • 13 followers

Comments