November 2, 2021/Posted byshreyans001/0
Introduction:
The working principle of the automatic sanitizer dispenser is to actuate the servo to press the sanitizer tap whenever the sensor observes a low distance reading due to an obstruction in its line-of-sight. When a person’s hand comes below the sanitizer and obstructs the sensor line-of-sight, the Arduino board receives a low distance reading and instructs the servo motor to actuate and dispense the sanitizer.
Component Required:
Arduino Uno
Uno cable
Ultrasonic sensor
Small breadboard
SG90 Micro-Servo motor
Jumper Wire
9V battery
Battery snapper connector
Circuit Diagram
Connections:
Connect sensor VCC pin to VCC
Connect sensor Trig pin to Arduino pin 3
Connect sensor Echo pin to Arduino pin 2
Connect sensor GND pin to GND
Connect motor VCC pin to VCC
Connect motor GND pin to GND
Connect motor Signal pin to Arduino pin 4
Code for Automatic hand sanitizer dispenser:
#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); } If you have any query please write us at [email protected] Hope you understand the project well and if you are facing any errors do inform us in the comments section below. |