aakash jaiswal
Published

Automatic hand sanitizer using arduino

Hello guys today we will make " automatic hand sanitizer" using ultrasonics sensor, arduino and servo motor... so lets get started

IntermediateFull instructions provided20,234
Automatic hand sanitizer using arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Story

Read more

Schematics

Circuit Diagram

Code

Code

Arduino
 
 #include <Servo.h>
#define trigPin 3
#define echoPin 2
Servo servo;
int sound = 250;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.attach(4);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 5) {
Serial.println("the distance is less than 5");
servo.write(90);
}
else {
servo.write(0);
}
if (distance > 60 || distance <= 0){
Serial.println("The distance is more than 60");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}

Credits

aakash jaiswal

aakash jaiswal

17 projects • 26 followers

Comments