IoT Water Flow Meter using ESP8266 & Water Flow Sensor
IoT Based Water Flow Meter using ESP8266. Interface YFS201 Hall Effect Water Flow Sensor with NodeMCU Code & send flow rate/Volume data to Thingspeak Server
- Suitable forB.Tech/Diploma ESP8266/IoT students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
Overview: IoT Water Flow Meter using ESP8266 & Water Flow Sensor
In this project we will learn how to make
IoT Based Water Flow Meter using ESP8266
&
Water Flow Sensor
. We will
interface YFS201 Hall Effect Water Flow Sensor with NodeMCU
ESP8266 Board. We will display the
water flow rate
& Total
Volume
in 0.96″
OLED Display
. We will then integrate the hardware with
IoT Server
. For IoT Server, we will use
Thingspeak
App. The water flow rate & volume data can be uploaded to
Thingspeak Server
& can be viewed/monitored from any part of the world.
Water Management System
is an important part of City Management. Water management involves supplying water according to the real requirement & without wasting Water. Therefore it is very important to measure water flow rate and volume. Without measuring these parameters, Water Management is almost impossible. Also monitoring the
Water Volume, Flow Rate & Water Quality
remotely using
Internet Connectivity
has become very essential. Therefore there is a need for
Monitoring Water Management System
Online.
There are so many
Water Flow Sensors
available in the market but are too expensive to use and afford. As a result, a
low-cost
water flow meter is required. So we will use
YFS201 Hall Effect Water Flow Sensor
with ESP8266 & design simple IoT Based Water Flow Meter.
Bill of Materials
Following are the
components
required for making this project. All the components can be easily purchased from
Amazon
. The component purchase link is given below.
S.N.
Components Name
Quantity
Purchase Links
NodeMCU ESP8266
Amazon
AliExpress
YF-S201 Hall-Effect Water Flow Sensor
Amazon
AliExpress
0.96" I2C OLED Display
Amazon
AliExpress
Connecting Jumper Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
YF-S201 Hall-Effect Water Flow Sensor
This is an image of the
YF-S201 Hall-Effect Water Flow Sensor
. This sensor can be connected to the waterline as it has both inlet and outlet. Inside the sensor, there is a pinwheel that measures how much liquid has moved through it. There’s an integrated
magnetic hall effect sensor
that outputs an
electrical pulse
with every revolution.
The sensor comes with three wires:
1. Red
(5-24VDC power)
2. Black
(ground)
3. Yellow
(Hall effect pulse output)
The water flow rate can be calculated by counting the pulses from the output of the sensor. Each pulse is approximately
2.25 milliliters
. This Sensor is cheaper and best but not the accurate one as flow rate/volume varies a bit depending on the flow rate, fluid pressure, and sensor orientation. To get better precision of more than
10%
, a lot of
calibration
is required. You can make a basic IoT Based Water Flow Meter using this Sensor.
The pulse signal is a simple
square wave
so its quite easy to log and convert into liters per minute using the following formula.
C++
Pulse
frequency
(
Hz
)
/
7.5
=
flow
rate
in
L
/
min
To learn more about this sensor, you can follow our previous guide here:
Arduino & Water Flow Sensor Complete Hookup Guide
IoT Water Flow Meter using ESP8266 & Water Flow Sensor
Now let us
interface YF-S201 Hall-Effect Water Flow Sensor with Nodemcu ESP8266 & OLED Display
. The OLED Display will show
Water Flow Rate
&
Total Volume
of Water passed through the pipe. The same Flow Rate & Volume data can be sent to
Thingspeak Server
after an interval of 15 seconds regularly. You can switch to
Blynk Application
if you want immediate data. Similarly using
MQTT Protocol
better wireless communication can be achieved.
But now let us see the IoT Water Flow Meter Circuit Diagram & Connection.
Water Flow Sensor is a
digital Sensor
, so we can connect its output pin to any of the digital pins of ESP8266. In my case, I connected to
GPIO2
, i.e
D4
. The sensor works at
5V
& can be connected to
Vin
of ESP8266. Similarly, I2C OLED Display
SDA & SCL
pins are connected to
D2 & D1
of ESP8266 respectively. The OLED Display works at
3.3V
so it can be connected to 3.3V pin of Nodemcu.
I have assembled the circuit on Breadboard. You can use the
custom-designed PCB
for making the small Water Flow Meter board.
PCB Designing & Ordering Online
The
PCB for this project
has been designed in EasyEDA online PCB making tool. Below is the front view and Back View of the PCB.
The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from
ALLPCB
at
1$
only.
Download Gerber File: IoT Water Flow Meter
You can use this Gerber file to order high quality PCB for this project. To do that visit the
ALLPCB
official website by clicking here:
https://www.allpcb.com/
You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.
After filling all details, select your country and shipping method. Finally you can place the order.
Mathematical Calculation to Measure Flow Rate & Volume
We have determined flow rate by a change in velocity of the water. The water velocity depends on the pressure that forces the through pipelines. The cross-sectional area of the pipe is known and remains constant, thus we calculate the average velocity that indicates the flow rate.
Let us consider Q is the flow rate/total flow of water through the pipe, V is the average velocity & A is the cross-sectional area of the pipe. In such a case the basis relationship for determining the liquid’s flow rate in such cases is
Q=VxA
Sensor Frequency (Hz)
= 7.5 * Q (Liters/min)
Litres
= Q * time elapsed (seconds) / 60 (seconds/minute)
Litres
= (Frequency (Pulses/second) / 7.5) * time elapsed (seconds) / 60
Litres
= Pulses / (7.5 * 60)
Setting up Thingspeak
Now we need to
setup the Thingspeak Account
. To set up Thingspeak follow the following Steps:
Step 1
: Visit
https://thingspeak.com/
and create your account by filling up the details.
Step 2
: Create a New Channel by Clicking on “Channel” & fill up the following details as shown in the image below.
Step 3
: Click on API Key, you will see the “
Write API Key
“. Copy the API Key. This is very important, it will be required in Code Part.
Step 4
: You can click on the “
Private View
” & customize the display window as you want.
So, that’s all from the Thingspeak Setup Part. Now let us move to the programming Part.
Source Code/Program
Now Let us see
ESP8266 Water Flow Sensor Code
using Arduino IDE. The code can be directly uploaded to the NodeMCU Board. But before that we need few
Libraries
for OLED Display. So download the Library first and add it to the Arduino IDE.
Download SSD1306 Library
Download Adafruit GFX Library
String
apiKey
=
"KBD1JSZTUKCXJ15V"
;
const
char
*
ssid
=
"Alexahome"
;
const
char
*
pass
=
"loranthus"
;
Change the Thingspeak API Key, Wifi SSID & Password from the line above.
The complete source code is given below.
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306
display
(
SCREEN_WIDTH
SCREEN_HEIGHT
&
Wire
OLED_RESET
)
;
String
apiKey
=
"KBD1JSZTUKCXJ15V"
;
// Enter your Write API key from ThingSpeak
const
char
*
ssid
=
"Alexahome"
;
// replace with your wifi ssid and wpa2 key
const
char
*
In this project we will learn how to make
IoT Based Water Flow Meter using ESP8266
&
Water Flow Sensor
. We will
interface YFS201 Hall Effect Water Flow Sensor with NodeMCU
ESP8266 Board. We will display the
water flow rate
& Total
Volume
in 0.96″
OLED Display
. We will then integrate the hardware with
IoT Server
. For IoT Server, we will use
Thingspeak
App. The water flow rate & volume data can be uploaded to
Thingspeak Server
& can be viewed/monitored from any part of the world.
Water Management System
is an important part of City Management. Water management involves supplying water according to the real requirement & without wasting Water. Therefore it is very important to measure water flow rate and volume. Without measuring these parameters, Water Management is almost impossible. Also monitoring the
Water Volume, Flow Rate & Water Quality
remotely using
Internet Connectivity
has become very essential. Therefore there is a need for
Monitoring Water Management System
Online.
There are so many
Water Flow Sensors
available in the market but are too expensive to use and afford. As a result, a
low-cost
water flow meter is required. So we will use
YFS201 Hall Effect Water Flow Sensor
with ESP8266 & design simple IoT Based Water Flow Meter.
Bill of Materials
Following are the
components
required for making this project. All the components can be easily purchased from
Amazon
. The component purchase link is given below.
S.N.
Components Name
Quantity
Purchase Links
NodeMCU ESP8266
Amazon
AliExpress
YF-S201 Hall-Effect Water Flow Sensor
Amazon
AliExpress
0.96" I2C OLED Display
Amazon
AliExpress
Connecting Jumper Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
YF-S201 Hall-Effect Water Flow Sensor
This is an image of the
YF-S201 Hall-Effect Water Flow Sensor
. This sensor can be connected to the waterline as it has both inlet and outlet. Inside the sensor, there is a pinwheel that measures how much liquid has moved through it. There’s an integrated
magnetic hall effect sensor
that outputs an
electrical pulse
with every revolution.
The sensor comes with three wires:
1. Red
(5-24VDC power)
2. Black
(ground)
3. Yellow
(Hall effect pulse output)
The water flow rate can be calculated by counting the pulses from the output of the sensor. Each pulse is approximately
2.25 milliliters
. This Sensor is cheaper and best but not the accurate one as flow rate/volume varies a bit depending on the flow rate, fluid pressure, and sensor orientation. To get better precision of more than
10%
, a lot of
calibration
is required. You can make a basic IoT Based Water Flow Meter using this Sensor.
The pulse signal is a simple
square wave
so its quite easy to log and convert into liters per minute using the following formula.
C++
Pulse
frequency
(
Hz
)
/
7.5
=
flow
rate
in
L
/
min
To learn more about this sensor, you can follow our previous guide here:
Arduino & Water Flow Sensor Complete Hookup Guide
IoT Water Flow Meter using ESP8266 & Water Flow Sensor
Now let us
interface YF-S201 Hall-Effect Water Flow Sensor with Nodemcu ESP8266 & OLED Display
. The OLED Display will show
Water Flow Rate
&
Total Volume
of Water passed through the pipe. The same Flow Rate & Volume data can be sent to
Thingspeak Server
after an interval of 15 seconds regularly. You can switch to
Blynk Application
if you want immediate data. Similarly using
MQTT Protocol
better wireless communication can be achieved.
But now let us see the IoT Water Flow Meter Circuit Diagram & Connection.
Water Flow Sensor is a
digital Sensor
, so we can connect its output pin to any of the digital pins of ESP8266. In my case, I connected to
GPIO2
, i.e
D4
. The sensor works at
5V
& can be connected to
Vin
of ESP8266. Similarly, I2C OLED Display
SDA & SCL
pins are connected to
D2 & D1
of ESP8266 respectively. The OLED Display works at
3.3V
so it can be connected to 3.3V pin of Nodemcu.
I have assembled the circuit on Breadboard. You can use the
custom-designed PCB
for making the small Water Flow Meter board.
PCB Designing & Ordering Online
The
PCB for this project
has been designed in EasyEDA online PCB making tool. Below is the front view and Back View of the PCB.
The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from
ALLPCB
at
1$
only.
Download Gerber File: IoT Water Flow Meter
You can use this Gerber file to order high quality PCB for this project. To do that visit the
ALLPCB
official website by clicking here:
https://www.allpcb.com/
You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.
After filling all details, select your country and shipping method. Finally you can place the order.
Mathematical Calculation to Measure Flow Rate & Volume
We have determined flow rate by a change in velocity of the water. The water velocity depends on the pressure that forces the through pipelines. The cross-sectional area of the pipe is known and remains constant, thus we calculate the average velocity that indicates the flow rate.
Let us consider Q is the flow rate/total flow of water through the pipe, V is the average velocity & A is the cross-sectional area of the pipe. In such a case the basis relationship for determining the liquid’s flow rate in such cases is
Q=VxA
Sensor Frequency (Hz)
= 7.5 * Q (Liters/min)
Litres
= Q * time elapsed (seconds) / 60 (seconds/minute)
Litres
= (Frequency (Pulses/second) / 7.5) * time elapsed (seconds) / 60
Litres
= Pulses / (7.5 * 60)
Setting up Thingspeak
Now we need to
setup the Thingspeak Account
. To set up Thingspeak follow the following Steps:
Step 1
: Visit
https://thingspeak.com/
and create your account by filling up the details.
Step 2
: Create a New Channel by Clicking on “Channel” & fill up the following details as shown in the image below.
Step 3
: Click on API Key, you will see the “
Write API Key
“. Copy the API Key. This is very important, it will be required in Code Part.
Step 4
: You can click on the “
Private View
” & customize the display window as you want.
So, that’s all from the Thingspeak Setup Part. Now let us move to the programming Part.
Source Code/Program
Now Let us see
ESP8266 Water Flow Sensor Code
using Arduino IDE. The code can be directly uploaded to the NodeMCU Board. But before that we need few
Libraries
for OLED Display. So download the Library first and add it to the Arduino IDE.
Download SSD1306 Library
Download Adafruit GFX Library
String
apiKey
=
"KBD1JSZTUKCXJ15V"
;
const
char
*
ssid
=
"Alexahome"
;
const
char
*
pass
=
"loranthus"
;
Change the Thingspeak API Key, Wifi SSID & Password from the line above.
The complete source code is given below.
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306
display
(
SCREEN_WIDTH
SCREEN_HEIGHT
&
Wire
OLED_RESET
)
;
String
apiKey
=
"KBD1JSZTUKCXJ15V"
;
// Enter your Write API key from ThingSpeak
const
char
*
ssid
=
"Alexahome"
;
// replace with your wifi ssid and wpa2 key
const
char
*
Technologies used
Hardware components
- ESP8266
- Arduino
- SSD1306
- OLED
Software & tools
- Arduino IDE
- Blynk
- ThingSpeak
- MQTT
- EasyEDA
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.