Introduction: DIY Easy Non-Contact Automatic Hand Sanitizer Dispenser or Automatic Soap Dispenser With Arduino

About: Just about anything you can do yourself.

There is a version two (v2.0) of this project:

Automatic Soap Dispenser V2.0

Hey everyone, so this was a one day build I did in light of the recent (2020) and I hope you like this build. It was easy and quick and I mainly used what I had lying around. Would love to hear your feedback on improvements.

You can check out my full Video here but I will detail the instructions for each step below.


Arduino Uno:

9G Micro Servo:

Ultrasonic Module HC-SR04 Distance Sensor:

Other Option:

Small piece of Wood

Battery: ~6V battery

String: I using Fishing line

Plastic container: I using a Crayon Box

Flexible Plastic: I am using a not book cover.

Assorted scews: I mainly used gypsum screws. 1/2" and 1"


Solder Iron

Glue Gun

Screw driver

Step 1: Mechanism

So I planned to make this as simple as possible with minimum items, using only a few electronics what I had. So it turned out I had an HC-SR04 ultrasonic distance sensor on hand, a servo and an Arduino UNO. You can use any Arduino here. I should have gone with an Arduino nano or micro to reduce the footprint, but I just rolled with the UNO since it something most of you would also have.

I planned to use the servo to pull a plastic plate anchored on the other end of the dispenser which would have a net downward force on the head of the soap dispenser. You can check the photos to see how I did this. I used a plastic crayon box to contain any spills and also to keep the dispenser in place.

I started off cutting a piece of wood to act as the base. The wood was about 10inchs long and 4inchs wide, but this would change based on your build. I laid out everything and screw the plastic container to the board first as in the picture. Here am using self treading screws. I used these same screws to make some legs for the wood so it would be off the counter away from water by any sink. Keeps the wood from getting soaked.

I used screws to secure the servo and also the Arduino UNO. The placement of the distance sensor was up in the air at this point as it could go anywhere, but I decided to put it to the side. Last I added a fish eye screw to secure the other end of the pull-down mechanism. I cut a piece of plastic from a notebook cover of the top since my previous pieces were causing too much resistance. Now time for the electronics.

I later made the servo stand up to allow the pulling action to take full advantage of the servo rotation. This would give a 180-degree pull over the 90 degrees it if it was lying down.

Step 2: Electronics

So using the circuit diagram above, I connected the servo and HC-SR04 to the Arduino UNO.

I used hot glue to add rubber feet to the bottom legs and also to secure the wires and the HC-SR04 to the wood.

Step 3: Programming

I put the code on my git:

If you do not know anything about Arduino you can watch my two videos:

What is Arduino and microcontroller:

Getting started and Master controlling LEDs with Arduino.

But the general idea is I am using the HC-SR04 to measure how close a hand is to the dispenser. When it gets close, in my code I am using less than 10cm, it would trigger the servo to move from 0 degrees, then to 180 degrees. It would wait for their for a second before returning back to 0 degrees. I added a delay after of 3 seconds to prevent the device from retriggering.

No extra libraries are needed.

Step 4: Testing

When testing, I had to change a couple of things.

The 5v USB power was too little for the servo, so I had to move to external power than feed directly to the servo. See the attached circuit diagram. I also added an "on" and "off" push button.

When it came to the hand sanitizer, the top of the dispenser was smooth, so I added a guide rail and screw as seen in the photo to prevent the mechanism from slipping off. Here I am using a LiPo battery to power the system, so I added a LiPo check to indicate when the battery goes low. It lasts about a week on this battery but I sure I can use a power bank or a 4 AA battery and putt the Arduino in a lower power state. This would make the battery last longer.

Step 5: Splash Proofing

To splash-proof the device, I used some plastic from an old 5 subject notebook I had. I cut pieces such to make a box around the Arduino and ultrasound sensor.

Step 6: Finishing Touches

To finish off, I used some Flat-Matte black spray paint. I made sure to cover all the sensitive stuff with tape beforehand. This includes the servo head, the push button and the HC-SR04 sensors.

There is a version two (v2.0) of this project:
Automatic Soap Dispenser V2.0

Trash to Treasure Contest

Participated in the
Trash to Treasure Contest