Introduction: Automatic Arduino Water Dispenser

This was a school project which was designed to utilise an Arduino Uno board along with a laser cutting or 3D printed aspect in an invention that helped people. Although automatic taps have already been invented, this project highlights that Arduino can literally be used for making just about anything. There were many bumps along the way during the construction process, but we learned from it so you don't make the same mistakes.

This project is an expansion on the idea originally posted on Circuit Digest on August 14, 2018, by Aswinth Raj. Full credit goes to him for the idea and the code.

Here is the link to the original article:

Step 1: Gather Materials

For this project you're going to need a few different materials which include:

  • 12V Solenoid Valve
  • A length of hose (which should be able to withstand a fair bit of pressure)
  • 2x 3/4" hose clamps
  • Any 15x15x20 laser cut, homemade or cardboard box. The one used in this is attached below.
  • Around 2x 1/2" female to male threaded pipe adapters, depending on whether your solenoid reaches the edge of your box
  • Some kind of drip tray with a grate to catch any liquid that spills
  • An Arduino Uno board
  • 2x wire crimps which fit the solenoid valve you've bought
  • An HC-SR04 ultrasonic sensor
  • A breadboard
  • Some leads
  • Two 20cm long cables
  • 2x bits of heat shrink tubing
  • Soldering equipment
  • A tap spout (or any spout which can connect to your solenoid)
  • An N channel MOSFET
  • A 1K and A 10K resistor
  • A barrel jack (that can connect to your arduino board)
  • Some extra wood for making a small table inside the box
  • Woodworking equipment
  • Spray or a water-based paint
  • Crimping equipment (some pliers and wire cutters)

You should be able to find most of this stuff around your home, at your local hardware store and eBay for pretty cheap.

Step 2: Wiring and Code

Wiring can be completed as shown in the picture and circuit diagram (picture is easier to follow)

Below is the code required for the automatic dispenser (with comments):

#define trigger 9 // all defines assign specific pieces of code to each pin

#define echo 8

#define MOSFET 12

float time=0,distance=0;

void setup()


Serial.begin(9600); // how fast information will be sent to the serial monitor

pinMode(trigger,OUTPUT); // each of the following tell the pins whether they are inputs or //outputs



delay(2000); // wait two seconds


void loop()



if(distance<10); // if the distance measured by the ultrasonic sensor is less than 10cm then //run the code immediately below


digitalWrite(MOSFET,HIGH); //The MOSFET turns on


else { digitalWrite(MOSFET,LOW); // if the the distance measured is more than 10cm then //MOSFET is off


delay(500);// wait half a second


void measure_distance()


digitalWrite(trigger,LOW); //the following code emits a sound at intervals






time=pulseIn(echo,HIGH); //echo receives reflected noise and works out the time since //sound was emitted to received

distance=time*340/20000; // formula for calculating the distance


Step 3: Box Assembly

If you don't have a laser cut box, make two holes down the bottom for putting your Ultrasonic sensor through (make sure you measure up dimensions).

if you have a laser cut box which has laser cut holes which you've already designed, then glue the joins together with either PVA, a glue gun, or some sort of wood glue. Do not glue the lid on!

*If you want a laser cut box, then go to

Step 4: Inside Shelf Assembly

Get 4 pieces of wood and fashion them into legs which can fit into the corners of the box, then glue them in. After that get a flat piece of balsa wood which aligns to the hole for the solenoid to screw into.

You'll need to split your solenoid up by unscrewing parts of it for the next part.

Drill a hole in wood which the small circular part of your solenoid can fit snugly, then drill holes for the screws in the solenoid to fit into (make sure you are extra careful getting the dimensions correct!)

Make sure your solenoid fits when screwed together then move on to the next step. Do not glue the shelf in!

Step 5: Crimp Wires

You're going to want to crimp a couple of leads from the breadboard and chop off the connectors on one side to connect the electronics to the solenoid.

All you have to do is get two wires and strip the ends off them, then you get the two wire crimp parts and set the wire in them. After that you hook the actual wire (metal) through the gaps in the crimp to make a more secure hold (It's useful to use some pretty thin pliers for this because it can get quite fiddly).

After you've done that then all you want to do is get a pair of pliers and squeeze the top of the crimp shut so the wire can't get out.

If you don't have wires that are long enough to reach where your solenoid will be then get a couple of bits of heat shrink tubing and put them over a join you'll have to make by soldering two wires together.

DISCLAIMER: This is an improvised method which we did because of the lack of a crimping tool. If you want a more professional crimp then get a crimping tool.

Step 6: Connect the Solenoid Valve to a Pipe

PREP: Set up a small pot with some boiling water for this

Take one end of the tube that you've got and place it into the boiling water, making sure it doesn't touch the bottom (otherwise you'll squish the end of the tube smaller than its original diameter).

Leave it in the boiling water for about 3-4 mins until its softer and easier to mould then push it over the end of you're solenoid. Add some silicone around the thread of the solenoid for a better fit and to prevent leaking when pushing the pipe on

Put a hose clamp around the joint and tighten it for a better seal.

Step 7: Connect Spout

This one is pretty easy. Just screw the spout (and other joints for length) onto the other end of the solenoid.

Step 8: Putting It All Together

Screw the solenoid firmly onto the top of the inside shelf, then put the electronics carefully into the bottom of your box.

Connect the crimped wires to the solenoid (it doesn't matter which way you put them around).

Screw the spout back on if you took it off to get the solenoid in the box. Connect a 12V power source to your Arduino board (you should've uploaded the code on there already so there is no need for a computer).

Finally, connect the other end of your pipe to a tap or water outlet with significant pressure, whilst also putting the other hose clamp around this or using a garden connector. Turn on the water and test the tap by putting your hand in front of the ultrasonic sensor, but don't put it too close or it won't work. Paint the box if you wish.

Step 9: You're Ready to Start Using It!

Now you can go have fun washing your hands or filling your cup up!

First Time Author

Participated in the
First Time Author