Video Tutorial
........Loading...................
Description
Hai friends, in this project we are going to make an automatic hand sanitiser which dispenses sanitiser without touching it. only you need to do show your hand towards the sanitiser box. it will detect you and spray sanitiser.
Components Required
1. | Arduino UNO | * 1 |
2. | servo motor | * 1 |
3. | Ultrasonic sensor | * 1 |
4. | Jumper Wires | |
5. | Bread Board | *1 |
6. | sanitiser | |
Circuit Diagram
Servo: Red wire - 5V, brown wire - GND, Yellow wire - pin 9
Sensor: VCC - 5V, GND-GND, Trig- 11, Echo- 12
Program
Complete your coding with the help of the Arduino ide. Upload program to your Arduino board makes sure that the Arduino port selection option is perfect. Avoid chance to get an error during uploading program to board
Click here to learn: "How to Upload your code to Arduino boards Without Error"
#include <Servo.h>
Servo servosweep;
float pos = 0.0;
void setup()
{
servosweep.attach(9);
Serial.begin (9600);
pinMode(11,OUTPUT);
pinMode(12,INPUT);
}
void loop()
{
long duration, distance;
digitalWrite(11, LOW);
delayMicroseconds(2);
digitalWrite(11, HIGH);
delayMicroseconds(10);
digitalWrite(11, LOW);
duration = pulseIn(12, HIGH);
distance = (duration/2) / 29.1;
Serial.print(distance);
Serial.println(" cm");
delay(200);
if (distance < 30)
{
servosweep.write(150);
delay(20);
}
if (distance > 30)
{
servosweep.write(0);
delay(20);
}
}