Introduction: Automatic Hand Sanitizer Dispenser

About: My name is Nikolas and I am studying Mechanical Engineering and Aeronautics! I love making things with electronics and 3D printing in order to solve problems, to improve our lives but also to satisfy my imagin…

Hi friends, in this Instructables I will show you how to make an accessory that can be attached to most hand sanitizer/soap dispensers and make them CompletelyAutomatic and Hands-Free! Firstly though check out the video above to see the device in action and understand how it functions!

My name is Nikolas, I am from Greece and I will go into the 10th Grade this month!


Over the last months the COVID-19 pandemic has been spreading chaos all around the world. There have been countless infections and unfortunately many casualties. One of the most important measures suggested by the World Health Organization is frequent hand washing with either soap or hand sanitizers. But one of the most significant problems is the way we do it and that is by physically touching the dispenser which eliminates the whole purpose of the action and even creates a great risk of infection. So I decided to create something using an Arduino Nano board that could combat this problem, but I also wanted it to be cheap and to be able to be attached to many different dispensers easily, quickly and effectively! And this is exactly what I made, an accessory that can be attached to most hand sanitizer/soap dispensers and turn them Completely Hands-Free and Automatic!


Here is the list of things you will need

  • 1 x Arduino Nano
  • 1 x DRV8825 Bipolar Stepper Motor Driver
  • 1 or more x Generic breadboards (I used 2 mini breadboards as they seem to fit the enclosure more easily)
  • Many Jumper Wires
  • 1 x 28BYJ-48 4 Phase Stepper Motor DC 5V For Arduino (OEM)
  • 1 x Infrared Obstacle Avoidance Sensor Module
  • 1 x Limit Switch KW12-3 - Micro Roller Lever Arm Normally Open/Close

  • 1 x Aluminium Rigid Coupling 5mm to 8mm

  • 1 x Trapezoidal Lead Screw T8-300mm with Brass Nut, Pitch 2mm (you will need about 80mm of the screw)

  • 1 x On-Off switch (generic)

  • A Hand Sanitizer Dispenser

  • 1 x 688zz Ball Bearing 8x16x5mm

  • 1 x LM8UU 8x15x24mm Solid Polymer Linear Bearing

  • 2 x Velcro ties

  • 1 x 9V battery (generic)

  • 1 x 9V Battery Clip

  • 1 x Resistor 1kΩ

  • 1 x Electrolytic Capacitor 100μF

  • 19 x M3 Screw any length from 8mm to 20mm

  • A 3D printer (If you don't have access to one you could try using wood or cardboard instead)

  • A stapler
  • A Soldering Iron (generic)

  • Software

  • Arduino IDE

  • 3D Slicer ( I would suggest Cura)

Step 1: Understand the Mechanism

So basically a stepper motor is connected with a coupler to a screw. The 3D printed Presser is connected on one side with the screw using a nut and on the other side it is supported by a 3D printed rod. The rod does not allow the screw's rotational force to rotate the presser and instead the presser moves linearly. This way we can command the stepper to move in any direction (back and forth), at any speed and for as many steps as we like.

Step 2: Understand How the Device Works

The concept is that when the IR Obstacle Sensor, which is attached to the 3D printed IR Holder, gets activated, by simply putting your hand a few centimetres (inches) below it, the presser goes down a set distance, (pressing the dispenser) waits for 2 seconds and then returns to the initial position by simply going up until the end-stop switch gets activated. Similarly when the device first gets powered on, the presser will go up until the switch gets activated and then it stops there, as a kind of self-calibration so that the presser is ready for use. Then using the Velcros you wrap the Hand-Sanitizer of your choice and tighten it as much as possible.

Now the Automatic Hand Sanitizer Dispenser is completely functional!

Step 3: Design Custom Parts

All the 3D printed parts were designed by me on Onshape but you don't need to worry about 3D designing because I have provided all the necessary .stl files!

Step 4: 3D Printing Custom Plastic Parts

I 3D printed the parts on my Creality3D Ender 3 V2 Printer in Grey and White PLA at 0.2mm layer height and at 20% infill. If you don't have access to a 3D printer don't worry you could always try using cardboard or wood.

Step 5: Modding the Stepper

The 28BYJ-48 stepper motor is a small and really cheap unipolar stepper motor and has a torque of about 300 g/cm which works with our project but I wanted it to be stronger for better results. We can increase the torque to 800+ g/cm by converting it to a bipolar motor with a simple and easy mod! This is because bipolar steppers have bigger coils and as a result a lot more torque.

  1. Firstly you want to remove the blue cover with a screwdriver.
  2. Once removed you want to fully cut off the middle copper trace that goes up to the red wire using a knife. You want to make sure that it does not connect at all anymore.
  3. Now you can cut off and remove the red wire from both sides.
  4. You can reattach the blue cover now, if you want. I needed to cut off 2 of its supports to be able to put it back.

Now you have your own bipolar 28BYJ-48 stepper. It has approximately 2.5 times the initial torque. However now you will need to get a bipolar stepper driver such as the DRV8825 which I am using. The minimum voltage supply for the driver is rated at 8.4V and our motor is rated at only 5V. But don't worry the bipolar version of the motor can easily handle that voltage!

Step 6: DIY Velcro Ties

It's time to make the Velcro ties that will attach the accessory to the dispenser! If you already have some Velcro cable ties feel free to use them. Otherwise cut one part at 30cm - 40cm and the other at 4cm - 7cm, you can make them as short or as long as you like. Now you want to staple the two parts together. Make sure that the sides that will be stapled together are either both rough or both soft. Now your Velcro tie is ready to use! You will need two of these.

Step 7: Circuit

It's time to create the electronics circuit!

  1. For starters connect the 9V battery's Ground to Arduino Ground with a 100μF electrolytic capacitor in between (Remember the side of the capacitor with the white line is the ground/cathode). Connect the 9V positive end to a generic On-Off switch and then to Vin on the anode of the capacitor. I am using two mini breadboards because they fit well inside the case, use any breadboard you like but please take into consideration the limited space.
  2. Connect the IR Obstacle Sensor VCCto5V, Ground to Ground and finally OUT to Digital pin 9.
  3. Now we are going to connect the end-stop switch. Connect the common leg to 5V and the normally open to Digital pin 8 and to Ground through a 1kΩ resistor.
  4. Add the DRV8825 bipolar motor driver to the breadboard. Connect the Vmot to the Vin of the Arduino. Connect the two Grounds to Ground. Connect the Dir pin to Digital pin 2, the Step pin to Digital pin 3, the Enable pin to Digital pin 4. Connect the Reset and Sleep pin to each other.
  5. Lastly connect the 28BYJ-48's blue cable to A2, the yellow cable to A1, the orange cable to B1 and the pink cable to B2.

The electronics are finally connected!

Step 8: Programming

const int dirPin = 2;

We define the Dir pin of the driver as the Digital pin 2.

const int stepPin = 3;

We define the Step pin of the driver as the Digital pin 3.

const int enablePin = 4;

We define the Enable pin of the driver as the Digital pin 4.

const int stepsPerRevolution = 6000;

We define the number of steps per revolution as 6000, one 360 degree rotation is 2048 steps.

int endStop = 8;

We define the input pin of the endStop switch as the Digital pin 8.

int irSensor = 9;

We define the input pin of the IR obstacle sensor as the Digital pin 9.

void setup(){
pinMode(endStop, INPUT);

In setup we declare the endStop and irSensor pins as Inputs.

pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enablePin, OUTPUT);

We declare the stepPin, dirPin and enablePin as Outputs.

digitalWrite(enablePin, LOW);

We set the enablePin LOW to enable the DRV8825 driver

while(digitalRead(endStop) == LOW){

As long as the digital value of the endStop switch is LOW (The switch is not being pressed.)

digitalWrite(dirPin, HIGH);

the direction of the motor's rotation is set as anti-clockwise

for(int x = 0; x < 1; x++){
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);

and the stepper will rotate anti-clockwise one step at a time until the While statement's condition is false.

digitalWrite(enablePin, HIGH);}

This disables our driver so that when not in use the driver does not consume much current.

void loop(){
if(digitalRead(irSensor)== 0)     {<br>

In the loop if the digital value of the irSensor is 0 (there is an obstacle (hand) in front of the IR Obstacle sensor)

digitalWrite(enablePin, LOW);

The driver gets enabled.

digitalWrite(dirPin, LOW);

The direction of the motor's rotation is set as clockwise.

for(int x = 0; x < stepsPerRevolution; x++)
{digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);

The stepper will rotate clockwise for 6000 steps.


It will wait for 2 seconds.

while(digitalRead(endStop) == LOW) 

As long as the digital value of the endStop switch is LOW (The switch is not being pressed)

digitalWrite(dirPin, HIGH);

the direction of the motor's rotation is set as anti-clockwise

for(int x = 0; x < 1; x++){
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);

and the stepper will rotate anti-clockwise one step at a time until the While statement's condition is false.

digitalWrite(enablePin, HIGH);}

Then the driver will get disabled until the If statement's condition is true and the code plays again.

Step 9: Cover Assembly

  1. Just place the Velcro tie in the gap,
  2. Add on top of it the holder and
  3. Screw them together.
  4. Screw the Velcro grip to the cover.

You will need to do this twice for both Velcros. The cover assembly is now complete!

Step 10: Presser Assembly

Push the linear bearing in the right hole until it is stuck in the middle. Then screw the T8 nut to the left hole of the presser with 4 screws.

Step 11: Electronics Case Assembly

Put your circuit in the electronics case. Run the cables of the stepper, the End-Stop switch and the IR Obstacle Sensor through the hole.

Step 12: IR Obstacle Sensor Holder Assembly

Screw the IR Obstacle Sensor to the hole and use a nut to tighten it.

Step 13: Final Assembly Part 1

  1. Insert the bearing.
  2. Add the T8 screw through the bearing and through the Presser's T8 nut. (The T8 screw needs to be 70mm to 82mm long. If you have a longer screw you should cut it to the wanted size using a tool like a hacksaw. Otherwise you can try 3D printing one.)
  3. Then add the 3D printed rod.

Step 14: Final Assembly Part 2

  1. Tighten the coupler to the motor's shaft.
  2. Then tighten it to the T8 screw.
  3. Lastly screw the motor to the base with two screws.

Step 15: Final Assembly Part 3

Add the end-stop switch as shown in the picture and screw the Cover to the Base with 5 screws.

Step 16: Final Assembly Part 4

Screw the IR Obstacle Sensor Holder to the front of the base with 2 screws. Finally, screw the Electronics Case to the Cover with 3 screws!

Step 17: Enjoy Your Creation!

Well done! This project is now completed! Now tie it to a Hand Sanitizer/Soap Dispenser turn on the switch and you now have your ownsafe way of Automatic Hand Sanitation during these difficult times!

Thanks for reading! If you enjoyed make sure to check out my YouTube channel for upcoming projects!

"Can't Touch This" Family Contest

Runner Up in the
"Can't Touch This" Family Contest