Automatic Hand Sanitizer

Automatic Hand Sanitizer plays an important in this pandemic situation because it helps in killing the corona virus ( COVID-19 ).

IntermediateFull instructions providedOver 1 day1
Automatic Hand Sanitizer

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
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit

Code

Source Code

C/C++
const int servo = 8;     //define Servo Signal Pin
const int trigPin = 11;  //define Trigger Pin
const int echoPin = 10;  //define Echo Pin

long duration;
int distance;

#include <Servo.h>

Servo myservo;    // create servo object to control a servo

int pos = 0;    // variable to store the servo position

void setup() {
  pinMode(trigPin, OUTPUT);    // Sets the trigPin as an Output
  pinMode(echoPin, INPUT);    // Sets the echoPin as an Input
  myservo.attach(servo);     // attaches the servo on pin 9 to the servo object  
  myservo.write(0);         // Sets Servo to initially 0 degrees 
  Serial.begin(9600);      // Starts the serial communication
}

void loop() {
   
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    
    duration = pulseIn(echoPin, HIGH);
   
    distance= duration*0.034/2;
    
    // Prints the distance on the Serial Monitor
    Serial.print("Distance: ");
    Serial.println(distance);
    
    if(distance<10)
    { //Check distance is less than 10cm 
       myservo.write(45); 
       delay(100);
       myservo.write(90);
       delay(100);
        myservo.write(135);
       delay(100);
       myservo.write(120); 
       delay(1000);
       myservo.write(00); // Reset the servo to 0 Degrees
       delay(2500);   //Delay the next time someone can get soap
    }                 
}

Credits

Krishna Chaitanya Subbarao Kedarisetty

Krishna Chaitanya Subbarao Kedarisetty

1 project • 0 followers

Comments