top of page

Motion Sensor Controlled Hand Sanitizer/Alcohol Dispenser


In light of the coronavirus pandemic, I decided to create a Motion sensor monitored hand sanitiser/alcohol dispenser. The objective of this project was to create an easier way in which people can wash their hands without having to touch any surface. Push bottles can have many germs on the surface and this device actively combats contracting any bugs from the surface of push bottles by introducing a ultrasonic motion sensor. This motion sensor is connected to a servo motor which allows the sanitizer to be dispensed.

 

#include <Servo.h>


#define trigPin 7

#define echoPin 6












Servo servo;

int sound = 250;


void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

servo.attach(5);

}



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 < 10) {

Serial.println("the distance is less than 5");

servo.write(0);

}

else {

servo.write(30);

}

if (distance > 60 || distance <= 0){

Serial.println("The distance is more than 60");

}

else {

Serial.print(distance);

Serial.println(" cm");

}

delay(500);


}

//Please note that this code is adapted


 





 

https://youtu.be/MC2E6dDfvKE

bottom of page