This project is about building a prototype of a Smart Water Dispensing Machine which can be placed in places such as convenience stores (e.g. 7-11), malls, concerts, etc. to provide convenient and quick refilling service. The motivation for this project is to solve the waste problem in Hong Kong, particularly to help reduce the burden on the landfills which will be full very soon. It achieves that by reducing the people's dependency on using and buying plastic water bottles as our solution is a quick, convenient and a cheaper alternative as opposed to buying a new plastic water bottle every time. It uses IoT (Internet of Things) to make the processes efficient and realisable. For example, IoT is used for identification and easy payment methods (eg. Credit cards) among many other uses. RFID tag and reader are the components that must be used for identification too. For demonstration purposes, only one bottle will be used with a tag to show how RFID can be used. Also, to accommodate everyone else, an option for Octopus users can be installed as well but for our prototype we won't be installing this for now. With our service, an App will be provided as well so that the users can control how they want to use our service and attain useful information. However, for now, we will only be focusing on making the Water Dispensing Machine, as other future additions to our idea are secondary.


To understand how to make the prototype, we first have to understand the functionality of the components needed. A water storage container will be needed to store clean drinking water and a sensor sensing if the container is empty so that the container can be refilled with water. Another container is needed for water to drain, and it must be cleared regularly whenever a sensor senses it is full. A water pump is used to pump the water out and a water flow sensor is used to measure how much water is being used so that the user can be charged accordingly. The user can be identified by the passive RFID tag on their bottles and thus have the option to be charged through their credit cards. Thus, the machine will need to access the database and perform accordingly so we are using a Wi-Fi module to connect to the Internet, and this is the part which allows IoT. Finally, to put the whole system alive and working, we need a development board from which our software will run.

Thus, for our prototype, we will be focusing on these components in our design for now:

  • Water pump --> Model: 12V DC Peristaltic Pump
  • Water flow sensor --> Model: YF-S201 Hall-Effect Water
  • Wifi Module --> ESP8266 Wi-Fi module
  • Passive RFID tag and reader
  • Development board --> Arduino Leonardo

Step 1: Components, Materials and Tools

Components and materials:

  • Water pump --> Model: 12V DC Peristaltic Pump
  • Water flow sensor --> Model: Uxcell G1/2" Thread Hall Effect Liquid Water Flow Sensor Switch Flowmeter Fluidmeter, 1-30L/minute, 44 mm Long
  • Wifi Module --> ESP8266 Wi-Fi module
  • Passive RFID tag and reader
  • Development board --> Arduino Leonardo
  • Diode --> Model: 1N4001
  • NPN Transistor (BJT) --> Model: PN2222
  • 10mm Pipes
  • Electronic Wires
  • Mechanical parts: Screws, nuts, bolts, etc.
  • Two 800mm x 600mm x 4mm acrylic sheets
  • Acrylic epoxy glue


  • Laser cutting machine
  • Computer with AutoCAD and Solidworks
  • Sandpaper to adjust for laser cutting tolerances
  • Arduino IDE
  • Soldering iron
  • Electrical wire cutter
  • Electrical tape
  • Multimeter


Step 2: Working Principle of the Components

Before making the prototype, it's important to understand the working principle of the components so that you can connect the circuit properly and know how to program later. Also, having a good understanding prior to circuit prototyping will help avoid bugs in the hardware and software, and you are less likely to damage the components.

Water Flow Sensor

This sensor has to be installed in line with the water line and contains a pinwheel with a magnet attached to measure the flow rate of water. There is an integrated magnetic Hall effect sensor that outputs an electrical pulse with every revolution of the pinwheel as the magnet with every revolution, gives a changing magnetic field which the transducer (Hall effect sensor) converts the change in magnetic field into an electric pulse. Since the flow rate of water is proportional to the rotational speed of the pinwheel, we can calculate the flow rate of water passing through using the frequency of pulse we are getting at the output. Thus, we need some calculations and here how it is done:

Frequency of the pulse at the output: F = 10Q , where Q is the flow rate of the in L/min and 10 is the calibration faction which changes depending on the model and type of flow sensor used and sometimes, for the same type and model, the calibration factor has to be further adjusted with personal testing with respect to what's written in the data sheet to acquire a more accurate result. This equation is written in the data sheet and derived with experimental results. Since Q=V*A, where V is the velocity of liquid and A is the cross dimensional area of the passage, and A is constant, thus Q is proportional to V. Thus from experimental result, the calibration factor is found out and it's the same way to do it to further adjust the factor while testing on your own.

Peristaltic pump

The pump is operated by a DC motor to uptake the liquid from one end and drip through the other. Its function is similar to peristalsis that happens in a human body thus having a similar name. As the DC motor rotates, it presses the pipe periodically thus forcing the liquid out. The motor runs at 12V in DC. However, the Arduino only supplies 5 V. Thus an external power source must be supplied to power the pump's 12V DC motor. The Arduino can regulate the speed of the motor. For example, by providing a low input base current to a BJT transistorto control a large collector current from the 12V DC battery which drives the motor. The low input base current is a PWM signal as the Arduino can only produce PWM signals to achieve analog output. By varying the duty cycle of the PWM signal, the speed of the motor can be controlled, thus the rate of water flow can be controlled too.

Step 3: Structural Prototyping

The structure of the water dispensing machine was designed using Solidworks, a popular CAD (Computer Aided Design) software. Since this is a prototype, it is much smaller than the actual product (approximately half the width and half the height). The prototype dimensions L, B & H are 170mm x 170mm x 750mm. The height of the prototype was limited by the range of the laser cutting machine. Slots and joints were made in the structure for easy of assembly, as well as for better stability.

Each part was converted to an engineering drawing within Solidworks and then saved as a .dwg file so that it can be accessed via AutoCAD, another popular CAD software. All the parts were arranged in two 800 x 600 sheets on AutoCAD (see images) to prepare them for laser cutting. The line colour (layer) was changed to red (RGB 255,0,0) so that the laser cutting software understands that these lines are meant to be cut. The file had to be saved again as a .dxf file because our laser cutting machine couldn't read .dwg files.

Two 800mm x 600mm x 4mm acrylic sheets were used to make the parts. The parts were removed from the sheet. Joints that were too big to fit into slots were reduced using sandpaper. They were fixed using acrylic glue (epoxy), as shown in the image. All the parts were not stuck. Parts like doors were kept lose so that we could open and shut them easily. It is important to let the glue dry for at least 24 hours before putting any weight on it, or else it may break.

We had to repeat the laser cutting and assembling process because we made a mistake while sticking the parts and couldn't make any change since the glue had dried up. So one must be careful while sticking the parts. Also, wear gloves so that the glue does not get on your hands.

Once the structure was dry and ready, other parts like the water container, the pump, the pipes and all the electronic components were added.

Step 4: Designing the Circuit Schematic (For References/PCB Fabrication/etc.)

This circuit diagram is illustrating the circuit connection for the Arduino development board, the peristaltic pump and the water flow sensor.

The Arduino board will be powered up by a 9V Battery connecting at the DC power jack of the board. Since the board can't provide enough current to drive the DC motor of the peristaltic pump properly, we use another 12V Battery as the power source of the pump.

The pump is connected in parallel with a flyback diode which is used to eliminate the flyback, which is the sudden voltage spike seen across the motor which is an inductive load. A bypass ceramic capacitor is also in parallel to reduce the noise. A polarised capacitor is placed along the batter to protect the battery. The capacitors are basically used to enhance the performance and to protect other components in the circuit. Lastly, a transistor is used to control the large current through the pump. The resistor at the base of the transistor is used to adjust a proper base current so as to control the collector current which is the current through the motor. The board uses PWM to send the base signals and thus we use it to control the force at which the pump is pumping.

The water flow sensor is not a power-hungry device to we can easily connect it to the 5V of the board and we use one wire to read the digital input signal from the sensor.

Finally, it its important to remember that all the connections should have a common ground.

Step 5: Circuit Prototyping

For making a prototype, it's good to use a breadboard for placing and wiring the components on it. Use a multimeter to test the components and part of the circuit diagram to see if it works they way you expect to. For example, test the current and voltage levels to make sure if it's connected to the rest of the circuit it won't damage other components to fry up the Arduino board.

It is best to have a master switch which can turn on and off the complete circuit immediately. For our prototype, it's the button which is used to press for refilling the water however it won't include the Wi-Fi module and the RFID but still, it is safe enough. It is because, only when the button is pressed, the peristaltic pump and the water flow sensor will be in need of use. Thus only then we are required to power them up.

The water flow sensor has 3 wires, red, black and yellow. The red wired is wired to the 5V of the Arduino board. The black wire is wired to the ground. The yellow wire is the signal output of the sensor which is the digital input of the Arduino.

Once again, it is important to remember that all of the components have a common ground otherwise there can be a short-circuit which will damage the Arduino board and other components. The circuit prototyping is an important procedure because we are able to do debugging of the circuit and make sure the circuit is correct. After this procedure, PCB fabrication can be done to make the circuit neat and tidy. However we won't be doing it for now.

Step 6: Programming (Software)

To understand the software, we can individually understand how to program for one component at a time.

For the water flow sensor, all we have to do is count the number of pulses in 1 second given by the sensor using a pulse counting function, for example, "pulseCounter()". This function can be used with interrupts such that whenever there's a pulse, it adds one to a pulse counting variable. There will one if-else function which will run every 1 second. We can use the function, "mills()", to time the cycles. And this if-else function will keep adding the rate to the total amount of liquid dispensed because at each second, the rate is recorded, thus for the time elapsed, the amount of the water dispensed in that 1 second will be equal to the rate since rate is also just the amount of water dispensed in 1 second. The equation used to calculate the flow rate is as follows:

Let C be the calibration factor, oldTime be the time of the last time the if-else function was successfully run, pulseCount be the variable counting the no. of pulse in the 1 second time elapsed:



Since, F=pulses/seconds --> F = pulseCount/(millis() - oldTime). Since the time elapsed is not exactly 1 second, we can use :(millis() - oldTime)" to. get a more accurate time elapsed in milliseconds. So we need to further convert it to seconds. Therefore, F = pulseCount/((millis() - oldTime)/1000) --> F=pulseCount*(1000/(millis() - oldTime)). Finally, we get, Q= (pulseCount * (1000/(millis() - oldTime)))/C.

Since Q is in L/min. Therefore, Q1=L*1000/(min * 60) --> flow rate in mililitres in one second. Therefore, we can conclude that, the amount dispensed in the 1 second elapsed = (Q/60)*1000 which can be added to the total for every passing second to get the total amount of water dispensed.

For the peristaltic pump, we use PWM to chose the duty cycle by using the value ranging from 0-225 in the function analogWrite(). Thus we have a large range of values to control the motor speed and thus we can get an analog output.

<p>That's a good idea, it could reduce a lot of plastic waste :)</p>

About This Instructable




More by hyder007:Water Dispensing Machine 
Add instructable to: