IoT Based Water Flow Meter using ESP8266 & PCB Designing

As you all know that the water level is decreasing day by day. So we need a water management system. Water Management System is an important part of Smart City Management. Water management involves supplying water according to the real requirement & without wasting Water. There are many ways to measure water flow these days. as well as various types of water flow meters used to measure the amount of water flow in pipelines, but they are all too expensive. Instead of these expensive water flow meters, we can use readily-available and low-cost YFS201 Water Flow Sensor. This sensor can be used in Soft Drinks Industries and Chemical industries to continually measure and quantify the liquids that they are handling during this automation process.

In this tutorial we will learn how to make IoT Based Water Flow Meter using NodeMCU ESP8266 & YFS201 Water Flow Sensor. We will interface YFS201 Hall Effect Water Flow Sensor with NodeMCU ESP8266 Board and 0.96″ OLED Display. We will use an IoT Cloud platform. For IoT Cloud platform, we will use Thingspeak. The water flow rate & volume data can be uploaded to Thingspeak Server & can be viewed/monitored from anywhere using any internet connected device.

Components Required

  • Required components are as follows:
  • NodeMCU – ESP8266-12E Board
  • Water Flow Sensor – YF-S201 Hall-Effect Water Flow Sensor
  • OLED Display – 0.96″ I2C OLED Display
  • Connecting Jumper Wires (10)
  • Breadboard

YF-S201 Hall-Effect Water Flow Sensor

water_flow_sensor

waterfs

In the above image you can see the sensor. This sensor sits in line with your water line and contains a pinwheel sensor to measure how much liquid has moved through it. There’s an integrated magnetic hall effect sensor that outputs an electrical pulse with every revolution. The hall effect sensor is sealed from the water pipe and allows the sensor to stay safe and dry.

The sensor comes with three wires: red (5-24VDC power), black (ground) and yellow (Hall effect pulse output). By counting the pulses from the output of the sensor, you can easily calculate water flow. Each pulse is approximately 2.25 milliliters. Note this isn’t a precision sensor, and the pulse rate does vary a bit depending on the flow rate, fluid pressure and sensor orientation. It will need careful calibration if better than 10% precision is required. However, its great for basic measurement tasks!

The pulse signal is a simple square wave so its quite easy to log and convert into liters per minute using the following formula.

Pulse frequency (Hz) / 7.5 = flow rate in L/min.

Features:

  • Model: YF-S201
  • Sensor Type: Hall effect
  • Working Voltage: 5 to 18V DC (min tested working voltage 4.5V)
  • Max current draw: 15mA @ 5V
  • Output Type: 5V TTL
  • Working Flow Rate: 1 to 30 Liters/Minute
  • Working Temperature range: -25 to +80℃
  • Working Humidity Range: 35%-80% RH
  • Accuracy: ±10%
  • Maximum water pressure: 2.0 MPa
  • Output duty cycle: 50% +-10%
  • Output rise time: 0.04us
  • Output fall time: 0.18us
  • Flow rate pulse characteristics: Frequency (Hz) = 7.5 * Flow rate (L/min)
  • Pulses per Liter: 450
  • Durability: minimum 300,000 cycles
  • Cable length: 15cm
  • 1/2″ nominal pipe connections, 0.78″ outer diameter, 1/2″ of thread
  • Size: 2.5″ x 1.4″ x 1.4″

Check the YF-S201 Hall Effect Water Flow Meter / Sensor Datasheet

IoT Water Flow Meter using NodeMCU ESP8266

Now We will interface YF-S201 Hall-Effect Water Flow Sensor with Nodemcu ESP8266 & OLED Display. In OLED display we can see Water Flow Rate & Total Volume of Water passed through the pipe. Measured data can be sent to Thingspeak Server after an interval of 15 seconds regularly. You can switch to Blynk App if you want immediate data or MQTT Protocol.

Follow circuit connections are as follows:

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 download the gerber file and order the PCB online from PCBWay.

Download Gerber File: IoT Water Flow Meter

How to get PCB? Don’t worry. Simply Visit PCBWay.com and upload gerber file and order the PCB. PCBWay is one of the most experienced PCB manufacturers in world. They offer very good quality PCB at reasonable price.

Why Buy Printed Circuit Board From PCBWay?

  • 24 hours production lead-time*
  • Team supported with over 90 professionals & technical
  • 99% on-Time Shipping with great support from DHL
  • Great quality approved by customers all over the world
  • Trusted Experience
  • A 24/7 non-stop production and assistance service
  • Low Minimums
  • Factory PCBs with most competitive advantages
  • A Chinese expert in Electronic Manufacturing Service (EMS)

pcbway

Setting up Thingspeak IoT Cloud Platform

ThingSpeak is an open-source software written in Ruby which allows users to communicate with internet enabled devices. It facilitates data access, retrieval and logging of data by providing an API to both the devices and social network websites.

Now we will setup the Thingspeak Account for this project. It is very simple. Please follow given below steps.

1: Visit https://thingspeak.com/ and sign up with your details.

2: Create a New Channel by Clicking on “Channel” & fill up the following details as shown in the image below.

3: Click on API Key, you will see the “Write API Key“. Copy the API Key. It will be required in Code Part.

4: You can click on the “Private View” & customize the display window as you want.

Source Code/Program for NodeMCU

Upload given below code to the NodeMCU. But before that we need few Libraries for OLED Display. So download the Library first and add it to the Arduino IDE.

  1. Download SSD1306 Library
  2. Download Adafruit GFX Library

Change the Thingspeak API Key, Wifi SSID & Password from the line above.

The complete source code is given below.

Monitoring Water Flow Rate & Volume

After uploading the code the OLED Display will strat working and will show the flow rate and volume. Initially the flow rate will be 0 liter/minute(L/M). Also Total Volume shown will be 0 Liter(L). Once the motor is turned ON & Water Starts flowing, you can see the OLED Display displaying the Flow Rate (F) & Volume(V).

Now you can monitor the Water Flow Rate & Volume Data on Thingspeak Server as well. You just need to visit the Private View of Thingspeak Dashboard.

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. I am a tech blogger and an IoT Enthusiast. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning!

Leave a Reply