In this article by Pradeeka Seneviratne author of the book, Internet of Things with Arduino Blueprints, explains that for many years and even now, water meter readings have been collected manually. To do this, a person has to visit the location where the water meter is installed. In this article, you will learn how to make a smart water meter with an LCD screen that has the ability to connect to the internet and serve meter readings to the consumer through the Internet.
In this article, you shall do the following:
(For more resources related to this topic, see here.)
The heart of a water flow sensor consists of a Hall effect sensor (https://en.wikipedia.org/wiki/Hall_effect_sensor) that outputs pulses for magnetic field changes. Inside the housing, there is a small pinwheel with a permanent magnet attached to it. When the water flows through the housing, the pinwheel begins to spin, and the magnet attached to it passes very close to the Hall effect sensor in every cycle. The Hall effect sensor is covered with a separate plastic housing to protect it from the water. The result generates an electric pulse that transitions from low voltage to high voltage, or high voltage to low voltage, depending on the attached permanent magnet's polarity. The resulting pulse can be read and counted using the Arduino.
For this project, we will use a Liquid Flow sensor from Futurlec (http://www.futurlec.com/FLOW25L0.shtml). The following image shows the external view of a Liquid Flow Sensor:
Liquid flow sensor – the flow direction is marked with an arrow
The following image shows the inside view of the liquid flow sensor. You can see a pinwheel that is located inside the housing:
Pinwheel attached inside the water flow sensor
The water flow sensor that we are using with this project has three wires, which are the following:
All three wire ends are connected to a JST connector. Always refer to the datasheet of the product for wiring specifications before connecting them with the microcontroller and the power source.
When you use jumper wires with male and female headers, do the following:
Water flow sensor connected with Arduino Ethernet Shield using three wires
You can directly power the water flow sensor using Arduino since most residential type water flow sensors operate under 5V and consume a very low amount of current. Read the product manual for more information about the supply voltage and supply current range to save your Arduino from high current consumption by the water flow sensor. If your water flow sensor requires a supply current of more than 200mA or a supply voltage of more than 5v to function correctly, then use a separate power source with it.
The following image illustrates jumper wires with male and female headers:
Jumper wires with male and female headers
The water flow sensor produces and outputs digital pulses that denote the amount of water flowing through it. These pulses can be detected and counted using the Arduino board.
Let's assume the water flow sensor that we are using for this project will generate approximately 450 pulses per liter (most probably, this value can be found in the product datasheet). So 1 pulse approximately equals to [1000 ml/450 pulses] 2.22 ml. These values can be different depending on the speed of the water flow and the mounting polarity of the water flow sensor.
Arduino can read digital pulses generating by the water flow sensor through the DATA line.
There are two type of pulses, as listed here:.
The rising and falling edges of a pulse are vertical. The transition from LOW state to HIGH state is called rising edge and the transition from HIGH state to LOW state is called falling edge.
Representation of Rising edge and Falling edge in digital signal
You can capture digital pulses using either the rising edge or the falling edge. In this project, we will use the rising edge.
In the previous step, you attached the water flow sensor to Arduino UNO. The generated pulse can be read by Arduino digital pin 2 and the interrupt 0 is attached to it.
The following Arduino sketch will count the number of pulses per second and display it on the Arduino Serial Monitor:
int pin = 2;
int pin = 2; //Water flow sensor attached to digital pin 2
volatile unsigned int pulse;
const int pulses_per_litre = 450;
void setup()
{
Serial.begin(9600);
pinMode(pin, INPUT);
attachInterrupt(0, count_pulse, RISING);
}
void loop()
{
pulse = 0;
interrupts();
delay(1000);
noInterrupts();
Serial.print("Pulses per second: ");
Serial.println(pulse);
}
void count_pulse()
{
pulse++;
}
Pulses per second in each loop
The attachInterrupt() function is responsible for handling the count_pulse() function. When the interrupts() function is called, the count_pulse() function will start to collect the pulses generated by the liquid flow sensor. This will continue for 1000 milliseconds, and then the noInterrupts() function is called to stop the operation of count_pulse() function. Then, the pulse count is assigned to the pulse variable and prints it on the serial monitor. This will repeat again and again inside the loop() function until you press the reset button or disconnect the Arduino from the power.
The water flow rate is the amount of water flowing in at a given point of time and can be expressed in gallons per second or liters per second. The number of pulses generated per liter of water flowing through the sensor can be found in the water flow sensor's specification sheet. Let's say there are m pulses per liter of water.
You can also count the number of pulses generated by the sensor per second: Let's say there are n pulses per second.
The water flow rate R can be expressed as:
In litres per second
Also, you can calculate the water flow rate in liters per minute using the following formula:
For example, if your water flow sensor generates 450 pulses for one liter of water flowing through it, and you get 10 pulses for the first second, then the elapsed water flow rate is:
10/450 = 0.022 liters per second or 0.022 * 1000 = 22 milliliters per second.
The following steps will explain you how to calculate the water flow rate using a simple Arduino sketch:
Serial.print("Water flow rate: ");
Serial.print(pulse * 1000/pulses_per_litre);
Serial.println("milliliters per second");
Pulses per second and water flow rate in each loop
The water flow volume can be calculated by summing up the product of flow rate and the time interval:
Volume = ∑ Flow Rate * Time_Interval
The following Arduino sketch will calculate and output the total water volume since the device startup:
volume = volume + flow_rate * 0.1; //Time Interval is 0.1 second
Serial.print("Volume: ");
Serial.print(volume);
Serial.println(" milliliters");
Pulses per second, water flow rate and in each loop and sum of volume
To accurately measure water flow rate and volume, the water flow sensor needs to be carefully calibrated. The hall effect sensor inside the housing is not a precision sensor, and the pulse rate does vary a bit depending on the flow rate, fluid pressure, and sensor orientation.
You can add an LCD screen to your newly built water meter to display readings, rather than displaying them on the Arduino serial monitor. You can then disconnect your water meter from the computer after uploading the sketch on to your Arduino.
Using a Hitachi HD44780 driver compatible LCD screen and Arduino Liquid Crystal library, you can easily integrate it with your water meter. Typically, this type of LCD screen has 16 interface connectors. The display has two rows and 16 columns, so each row can display up to 16 characters.
The following image represents the top view of a Hitachi HD44760 driver compatible LCD screen. Note that the 16-pin header is soldered to the PCB to easily connect it with a breadboard.
Hitachi HD44780 driver compatible LCD screen (16 x 2)—Top View
The following image represents the bottom view of the LCD screen. Again, you can see the soldered 16-pin header.
Hitachi HD44780 driver compatible LCD screen (16x2)—Bottom View
Wire your LCD screen with Arduino as shown in the next diagram. Use the 10k potentiometer to control the contrast of the LCD screen. Now, perform the following steps to connect your LCD screen with your Arduino:
Fritzing representation of the circuit
Open a new Arduino IDE and copy the sketch named B04844_03_04.ino.
First initialize the Liquid Crystal library using following line:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 7, 6, 5, 4, 3);
lcd.begin(16, 2);
lcd.setCursor(7, 1);
The column and row numbers are 0 index based and the following line will start to print a text in the intersection of the 8th column and 2nd row.
lcd.print(" ml/s");
You can see some information on the LCD screen such as pulses per second, water flow rate, and total water volume from the beginning of the time:
LCD screen output
In the previous steps, you learned how to display your water flow sensor's readings and calculate water flow rate and total volume on the Arduino serial monitor. In this step, you will learn how to integrate a simple web server to your water flow sensor and remotely read your water flow sensor's readings.
You can make an Arduino web server with Arduino WiFi Shield or Arduino Ethernet shield. The following steps will explain how to convert the Arduino water flow meter to a web server with Arduino Wi-Fi shield:
char ssid[] = "MyHomeWiFi";
char pass[] = "secretPassword";
http://192.168.1.177
Typically, the direction of the water flow is indicated by an arrow mark on top of the water flow meter's enclosure. Also, you can mount the water flow meter either horizontally or vertically according to its specifications. Some water flow meters can mount both horizontally and vertically.
You can install your water flow meter to a half-inch pipeline using normal BSP pipe connectors. The outer diameter of the connector is 0.78" and the inner thread size is half-inch.
The water flow meter has threaded ends on both sides. Connect the threaded side of the PVC connectors to both ends of the water flow meter. Use a thread seal tape to seal the connection, and then connect the other ends to an existing half-inch pipeline using PVC pipe glue or solvent cement.
Make sure that you connect the water flow meter with the pipe line in the correct direction. See the arrow mark on top of the water flow meter for flow direction.
BNC pipe line connector made by PVC
Securing the connection between the water flow meter and BNC pipe connector using thread seal
PVC solvent cement.
Image taken from https://www.flickr.com/photos/ttrimm/7355734996/
In this article, you gained hands-on experience and knowledge about water flow sensors and counting pulses while calculating and displaying them. Finally, you made a simple web server to allow users to read the water meter through the Internet. You can apply this to any type of liquid, but make sure to select the correct flow sensor because some liquids react chemically with the material that the sensor is made of. You can Google and find which flow sensors support your preferred liquid type.
Further resources on this subject: