Magicbit
Published

Smart Dustbin from Magicbit

In this tutorial we learn about how to make a Smart dustbin using Magicbit with Arduino

BeginnerFull instructions provided574
Smart Dustbin from Magicbit

Things used in this project

Hardware components

Magicbit
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit

Code

Arduino code of smart dustbin based on Magicbit

Arduino
#include <NewPing.h>
#define TRIGGER_PIN  21
#define ECHO_PIN     22
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
#include <ESP32Servo.h>//include servo library
int distance;
int count=0;
bool Open=false;
Servo Servo; 
void setup() {
 
  Serial.begin(115200);
  Servo.attach(26); // Defines on which pin is the servo motor attached
  delay(3000);
}
void loop() {
 distance = sonar.ping_cm();
  if( distance>0 && distance<=60  && Open==false){


  for(int i=125;i>=0;i--){  
  Servo.write(i);
  delay(5);
  }
  count=0;
 
Open=true;}

  else if(  (distance>60 || distance==0) && Open==true){
  
   for(int i=0;i<=125;i++){  
  Servo.write(i);
    delay(5);
  }
  Open=false;
 
}

delay(500);
}

Credits

Magicbit
57 projects • 35 followers
Magicbit is an integrated development platform based on ESP32 for learning, prototyping, coding, electronics, robotics, IoT and more.

Comments