Introduction: DIY Hand Sanitizer Dispenser Using Arduino

In this current scenario of global outbreak, it is advised by WHO (world health organization) to maintain Healthy Hand Wash and Sanitation Habits, but the main problem is the way we do it, that is by physical touch to the bottle, which in short doesn’t serve our purpose, so in this tutorial, we will learn How To make a D.I.Y. Arduino Based Soap or Hand Sanitizer Dispenser.



  1. Arduino Nano ( or any Arduino ).
  2. Ultrasonic Sensor ( HC-SR04)
  3. Servo Motor ( metal Geared Preferred ).
  4. Jumper Wires ( female to female ).
  5. misc


  1. Hot Glue Gun.
  2. Computer or Laptop.


  1. Alcohol Based Hand Rub or Sanitizer.( most important)
  2. Self Threading Screw ( 1 pcs).
  3. 0.8 mm copper wire ( 0.5 meter ).
  4. plastic container ( which fits everything inside comfortably)
  5. Stationary ( marker and ruler scale ).

Step 1: Watch the Video

Step 2: Select the Liquid

First and the most important thing we will need for this build is Alcohol Based Hand Rub or Hand Sanitizer or Hand Wash as suggested by W.H.O. ( world health organization ) find more information here .

for this build, it is very important to get right kind of dispenser, since we are just making a dispenser and not printing the entire mechanism, we will need alcohol or hand rub in dispenser or push type bottle.

Step 3: Selection of Components


We will need a Sensor to sense our proximity or presence which will basically act as a trigger or touch less switch for this system. We have two choices here, that is we can use either IR sensor Module, or Ultrasonic sensor Module. We can use IR sensor Module, which is basically a cheap and efficient option, but sometimes inaccurate, or we can use HC-SR04 Ultrasonic sensor, which is quite accurate above 2 cm range, and slightly expensive option, but we will use Ultrasonic Sensor for this Tutorial, for better accuracy.


For motion or to process the Output, we might need either a pump, either motor, or some electronic component that will convert electrical signal to mechanical displacement of alcohol based hand rub or sanitizer through the dispenser, best choice would be to use a Servo motor with metal gears for maximum torque. We will avoid using micro pumps, since they are to be inserted into the container, which again creates vulnerable containment spot. So using an external mechanism with help of servo would be a wise choice.


For this project build, we will need a Microcontroller to control the Input and Output, to Calculate the distance or sense the Trigger from Sensor and Process the Output in form of Servo Sweep in our Example, for which we can use any arduino, which makes it easy to adjust the parameters, fine tune outputs, so you can use any Arduino, we will use Arduino Nano for our work case.

Step 4: Understand the Mechanics

Let's Understand the Mechanical Arrangement before we start making it. We will need a mechanism which will create a force to push the nozzle down and dispense the liquid, since we are using servo motor, that provides circular motion, it alone can’t create a downwards force, we will need some kind of mechanical arrangement to make it happen,we will use pulley mechanism to fix one end and convert the rotational force to push, we can do that using Copper Wire to create a downwards vector force for transmission, what it basically does is, it convert the circular force of Servo to a downwards acting force vector, to simulate push. but this all sounds complicated, so let’s execute this task bit by bit, following the further steps

Step 5: Connections

Connections for this build is very simple !

Sensor to Arduino:

Trigger to D10

Echo to D11

Vcc to Vcc

Gnd to Gnd

Servo to Arduino:

Signal to D9

Vcc to Vin

Gnd to Gnd

(you can refer to this post for basics & working of Ultrasonic. Click here for Components)

Step 6: Attach Servo to Base

First step in mechanical arrangement is to attach Servo motor to one rigid surface inside the box, using hot glue

( be careful while using the hot glue )

Step 7: Pass the Copper Wire Through Servo Arm

Pass the Copper Wirethrough Servo motor using the holes on Attachment Arm, pass at least through 2 holes to ensure proper tension is achieved using circular attachment arm would be better choice, since straight one can get caught inside enclosure.

Step 8: Add Piece of Hot Glue Stick With Hole in Middle

Cut about 2 cm long piece of Hot Glue Stick and make a hole in middle, pass the copper wire through the piece of hot glue stick, which will indeed help to increase the surface area at contact point,

Step 9: End Screw

Attach the second end of wire to another rigid surface (opposite face of servo motor), using a Self Threading Screw or a nail here would be a vise choice since it will allow us to adjust the tension or to remove the bottle for refill.

Step 10: Upload the Code

In theory our idea sounds perfect, let’s code this Arduino and test our idea in real world.

The code is very simple to understand, we used the servo library, and defined basic setups and variables, the main code is such that it calculates the distance in centimeters and if the distance is less than 10 cm the servo motor performs a sweep motion to release the liquid.

you can find the Library for Servo here.

<p>/*==========================================================================  <br>by "Akshay Momaya"
for "Mission Critical" ( youtube )
******subscribe for more ARDUINO projects and tutorials******
==========================================================================*/</p><p>const int servo = 9;     //define Servo Signal Pin
const int trigPin = 10;  //define Trigger Pin
const int echoPin = 11;  //define Echo Pin</p><p>// defines variables</p><p>long duration;
int distance;</p><p>#include <servo.h></servo.h></p><p>Servo myservo;    // create servo object to control a servo</p><p>int pos = 0;    // variable to store the servo position</p><p>void setup() {
  pinMode(trigPin, OUTPUT);    // Sets the trigPin as an Output
  pinMode(echoPin, INPUT);    // Sets the echoPin as an Input
  myservo.attach(servo);     // attaches the servo on pin 9 to the servo object  
  myservo.write(0);         // Sets Servo to initially 0 degrees 
  Serial.begin(9600);      // Starts the serial communication
}</p><p>void loop() {
    digitalWrite(trigPin, LOW);
    // Sets the trigPin on HIGH state for 10 micro seconds
    digitalWrite(trigPin, HIGH);
    digitalWrite(trigPin, LOW);
    // Reads the echoPin, returns the sound wave travel time in microseconds
    duration = pulseIn(echoPin, HIGH);
    // Calculating the distance
    distance= duration*0.034/2;
    // Prints the distance on the Serial Monitor
    Serial.print("Distance: ");
    { //Check distance is less than 10cm 
       myservo.write(45); // Sets Servo in stages from 0 to 180 degrees so soap does not pitch out. 
       myservo.write(120); //Ajust how far you want the servo to go.
       myservo.write(00); // Reset the servo to 0 Degrees
       delay(2500);   //Delay the next time someone can get soap

code is attached in this Step ( some times copying the code from above doesn't work so please download the code from here )

Step 11: Testing

Once our code is uploaded, it would be good practice to Test this project before we complete this enclosure.

in this test we can clearly see when our hand is placed above sensor and distance for ultrasonic drops below 10 cm, servo motor is engaged and alcohol hand rub is dispensed.

once the project is working properly, we can move further to next step!

Step 12: Complete the Enclosure

Once our project seems to be working, it's time to complete the enclosure.

follow the steps to complete it:

  1. measure the Dimensions for Ultrasonic Sensor and holes for Bottle.
  2. make a slot for Copper wire with extra room for Moment.
  3. mark all cutting holes.
  4. use Sharp Blade or Drill to plot the holes.
  5. fix everything with the help of hot glue.

And finally this project comes to life.

Step 13: All Set!

Finally this project is done!

Step 14: Please Donate!

Most of the parts used in this project would be handy with many of guys, so I would request all of you to make this project and donate it to Hospitals or any needy person, I am personally donating this project to an Essential work force. Do share this video with all your Engineer friends and let’s start a moment, make this project, tag us on Instagram using the id @officialmissioncritical its time to contribute to community and show power of our Arduino Community to fight this Global Issue!