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);



void loop() {

long duration, distance;

digitalWrite(trigPin, LOW);


digitalWrite(trigPin, HIGH);


digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

if (distance < 10) {

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



else {



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

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


else {


Serial.println(" cm");




//Please note that this code is adapted

bottom of page