Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Magicbit
Published

Smart Sanitizer with Magicbit

In this tutorial we will learn about how to make a automatic sanitizer with additional features using Magicbit

BeginnerProtip397
Smart Sanitizer with Magicbit

Things used in this project

Hardware components

Magicbit
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
MG945 metal Servo
×1
Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
DFRobot Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Arduino code of smart sanitizer

Arduino
refer it
#include <NewPing.h>
#include <ESP32Servo.h>
#define TRIGGER_PIN  21
#define ECHO_PIN     22
#define MAX_DISTANCE 200
#define SENSOR 32;


NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
int output_value ;
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);
   pinMode(32,INPUT);//moisture sensor attached pin
   pinMode(25,OUTPUT);// buzzer attached pin 
}
void loop() {
    output_value= analogRead(SENSOR);
    if(output_value<2530){//change this value after calibration
 distance = sonar.ping_cm();
  if( distance>0 && distance<=30  && Open==false){


  for(int i=130;i>=90;i--){  //push head
  Servo.write(i);
  delay(5);
  }
  count=0;
 
Open=true;}

  else if(  (distance>60 || distance==0) && Open==true){
  
   for(int i=90;i<=130;i++){  //release head
  Servo.write(i);
    delay(5);
  }
  Open=false;
 
}}
else{
  tone( 25 ,4186,500); //C Note
   delay(1000);
}

delay(500);
}

Credits

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

Comments

Please log in or sign up to comment.