For this report, we were asked to designed an Automatic hand-sanitizer dispenser. The materials used for this lab are Arduino microcontroller, ultrasonic sensor and a rectangular base that is able to hold hand-sanitizer product
We research some drawings online and came up with a conclusion and sketch it first. The goal was to build an effective hand sanitizer dispenser . The ultrasonic sensor should detect the hand and release a specific amount of hand sanitizer by using the code in Arduino.
The code for our Arduino project is the following:
#include<Servo.h>
int trig=8;
int echo=9;
int dt=10;
Servo servo;
//int distance,duration;
void setup() {
// put your setup code here, to run once:
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
Serial.begin(9600);
servo.attach(3);
}
void loop() {
// put your main code here, to run repeatedly:
if (calc_dis()<10)
{
for (int i=0;i<=180;i++)
{
servo.write(i);
delay(1);
}
delay(100);
for (int i=180;i>=0;i--)
{
servo.write(i);
delay(1);
}
delay(100);
}
}
//This code is written to calculate the DISTANCE using ULTRASONIC SENSOR
int calc_dis()
{
int duration,distance;
digitalWrite(trig,HIGH);
delay(dt);
digitalWrite(trig,LOW);
duration=pulseIn(echo,HIGH);
distance = (duration/2) / 29.1;
Serial.println((String) "Duration" +"Duration" + "Duration" + distance);
return distance;
}