Creative Commons License

arduino hand sanitizer .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.

Supplies for arduino 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 for making arduino hand sanitizer

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. And 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.

arduino hand sanitizer

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 for arduino hand sanitizer

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 arduino hand sanitizer

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.

arduino hand sanitizer

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.

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

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 arduino hand sanitizer:
  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!

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!


  1. Michel Ange Ivain TAKODJOU NGUEMTO Reply

    Good projects. I want to know how I can do to improve the system in the code
    -if a hand is there for a long time how to avoid repeating the process
    – if the hand is there for a brief time how to stop the process.

    • Akshay Momaya Reply

      you can use Counter or may be add Delay, generally Delay of 3 seconds might be enough.

  2. Vidyalakshmi Prabhu Reply

    what to change in the code if we are using arduino uno?

    • Akshay Momaya Reply

      Nothing needs to be changed in code while using Arduino UNO instead of nano.

  3. Arnav goel Reply

    Hi.. I have downloaded the code in Arduino software but not able to upload it on the arduino nano. Please help

  4. Hi sir, i cannot donwload the coding for this project..How can i get this coding please.Thanks

  5. Hello! you have a cool project, i stumbled upon yours and started making it, but the problem was for some reason the servo won’t reverse? did i do something wrong in the code or do i specifically need a servo motor you used? thanks in advance

Write A Comment


A Market Place for your Innovations