back to top
Friday, January 2, 2026
spot_img

Pipeline Water Detection: ESP32 Smart Water Meter (DIY)

Share this Guide

In ideal fluid dynamics simulations – and perhaps in First world countries – water is a utility that exists at constant pressure, available 24/7. You open a tap, and physics does the rest. But here, in the chaotic reality of Indian (and many central American, Asian countries) metros and developing urban centres, water is a finite event. It arrives like a shy guest, sometimes at 5:00 AM, sometimes at 6:30 AM, often as a trickle, and occasionally not at all.

For decades, the “automation” for this problem was a human being. It was your grandmother waking up before dawn to check the tap. It was the sound of a thousand mosquito pumps whining in unison across the neighbourhood, fighting for the same limited hydraulic resource. This is what I reasoned as “Active Suction” – pulling water from a supply line that is under-pressured or intermittent. It is a necessary survival mechanic, but it comes with a fatal flaw: The Dry Run.

When the municipal line runs dry, your pump continues to spin. Without water to cool the impeller and seals, the friction builds up. The heat rises. Eventually, the mechanical seal fails, or the motor windings burn out. Worse, you waste electricity spinning a fan that moves nothing but air.

We will be building the ESP32 Smart Water Meter with its own Web Server + Home Assistant integration & Automation logic. This is not just a remote switch; it is a watchman for water. It wakes up, tests the line, secures the resource, and shuts down instantly when the supply vanishes. We will use the industrial-grade YF-G1 DN25 flow sensor to give our system “eyes” inside the pipe, an ESP32 for the “brain,” and Home Assistant for the strategic logic.

Core Components Required

ESP-WROOM-32: Robu.in | Cost: 350 INR or $5.
YF-G1 Water Flow Sensor: RoboCraze.com | Cost 900 INR or $9.50.
8 Bit WS2812 RGB LED: QuartzComponents.com | Costs 50 INR or $0.50.
Hi-Link HLK-10M05 PSU: Robu.in | Cost: 230 INR or $3.
DHT-11 Digital Temp Sensor: Robu.in | Cost: 60 INR or $0.60.
Wipro 16A Wi-Fi Smart Plug: Amazon.in | Cost: INR: 1000 or $10.

You will need jumper wires, soldering iron, enclosure box and some resistors + capacitors (described below) from your assorted electronics kit.

The Context: Why This Build is Different

Before we melt solder, we must understand the hydraulic battlefield. Automating a pump in a standard pressurized system (like a pressure booster) is trivial: if pressure drops, turn on the pump.

Our scenario is the opposite. We are dealing with Intermittent Water Supply (IWS).

  1. The Supply is Finite: The water comes for 1-2 hours.
  2. The Pressure is Negative: We are often sucking water faster than Boring/gravity provides it, creating a vacuum.
  3. The Risk is Cavitation: If we pull too hard on an empty pipe, we create air pockets that implode and damage the impeller.

Most “smart plugs” fail here because they rely on timers. A timer is stupid. If the water supply is late by 30 minutes, a timer burns out your pump. If the supply cuts off early, a timer burns out your pump.

We need feedback. We need to know not just if the pump is on, but if water is moving. This requires a dedicated Flow Sensor (The YF-G1 DN25) and specific logic I call the “Priming Window,” which we will code into Home Assistant.


Deep Dive: The Municipal Water Context

To build the perfect automation, one must first respect the complexity of the problem. In many regions, particularly across India, the “Intermittent Water Supply” (IWS) is not merely an inconvenience; it is a complex hydrodynamic phenomenon driven by scarcity, infrastructure management, and rapid urbanization.

Physics of Water Delivery

First World (Continuous Supply)
Q = A ร— v (Constant)
State: Pressurized
Pressure (P): 3.5 Bar
Delay: 0.0s
Developing World (IWS)
Q = 0 (Empty Pipe)
State: Dry / Air Lock
Pressure (P): 0 Bar
โš ๏ธ DRY RUN DETECTED

The Physics of “Suction”

In a standard developed-world plumbing scenario, the municipal main is pressurized (2-4 Bar). Water pushes into your home. In the IWS context, the pressure is often negligible or zero. To get water into an overhead tank (often 3-4 stories up), households install “monoblock” suction pumps directly on the mainline or a shallow sump.

When the municipal valve or Boring mains opens, water trickles into the pipes. But because demand (hundreds of pumps starting simultaneously) exceeds supply, the pressure in the mainline drops below atmospheric pressure. The pipes are no longer conduits of pressurized liquid; they are vacuum chambers. Your pump is actively fighting your neighbor’s pump for every liter.

This creates the “Back Siphoning” risk mentioned in hydro-engineering literature. If the pipe has leaks (common in older infrastructure), the vacuum sucks in groundwater or sewage. While our system cannot fix the city’s pipes, understanding this helps us realize why dry run protection is critical. We aren’t just saving the pump; we are stopping the pump from sucking in air (and contaminants) when the clean water column breaks.

Why Timers Are Dangerous

The standard solution sold in electrical shops is the “Automatic Water Level Controller” (AWLC). These devices usually rely on a timer (“Run for 1 hour at 6 AM”) or a simple overhead tank float switch (“Run until full”).

Both fail in the IWS scenario:

  • The Timer Boundation: If the municipal supply is delayed to 7 AM, a 6 AM timer runs the pump dry for an hour. This friction heats the mechanical seal – a ceramic and carbon ring interface relying on water for lubrication. Once the seal cracks, water enters the motor winding, and the pump dies.
  • The Float Switch Failure: If the tank is empty, the float switch demands water. It turns the pump on. But if the municipal line is empty, the pump runs dry indefinitely until someone notices the screaming noise.

The ESP32 Smart Water Meter replaces blind hope with data. It asks a simple question: “I have turned the pump on. Is water actually moving?” If the answer is “No” for more than a set period, it shuts down. It also tracks how much water you have collected in a session and over a time period.


Bill of Materials (BOM): The Hardware Ecosystem

We are building a system that deals with 220V AC mains and water – a combination that demands respect and quality components. Do not scrimp on the sensor or the power supply. We are creating a device that must operate autonomously for years.

image 6

The Brain: ESP32 Development Board

  • Spec: ESP-WROOM-32 or NodeMCU-32S.
  • Why: The ESP32 is a dual-core beast. Unlike the ESP8266, it has more robust GPIOs, better Wi-Fi stability, and hardware pulse counters (PCNT) which are critical for accurate flow sensing without bogging down the CPU. We need that processing power to handle the high-frequency interrupts from the flow sensor while maintaining a stable connection to Home Assistant.
  • Key Feature: The ESP32’s pulse_counter hardware unit can count edges on a signal pin asynchronously. This means even if the Wi-Fi stack is busy negotiating a handshake, the ESP32 won’t miss a single liter of water flowing through the sensor.

The Eye: YF-G1 DN25 Water Flow Sensor

This is the star of the show. Most hobbyist kits come with the tiny white YF-S201 (1/2 inch). Throw that away. For a main municipal line, you need the YF-G1 DN25.

image 5
  • Size: 1 Inch (DN25). This matches the standard inlet pipe diameter of most domestic monoblock pumps (0.5 HP to 1.5 HP), ensuring we do not restrict flow. Reducing the pipe diameter to 1/2 inch for a sensor would choke the pump, reducing efficiency and increasing cavitation risk.
  • Flow Rate: 2 โ€“ 100 Liters/min. A typical 1HP domestic pump moves 30-60 LPM, sitting perfectly in this sensor’s “sweet spot” for linearity.
  • Pressure Rating: โ‰ฅ 1.75 MPa (17.5 Bar). This is overkill for municipal lines (usually <2 Bar), which guarantees safety against water hammer surges.
  • Material: Nylon + Glass Fiber or Industrial Plastic. Robust enough to handle the vibration of the pump line.
  • Precision: ยฑ3% accuracy.
  • Signal: Hall Effect Pulse Output (Yellow Wire). It generates a square wave frequency proportional to flow velocity.
FeatureSpecificationImportance for Water Meter
ModelYF-G1 DN25Fits standard pump plumbing
Flow Range2 – 100 L/minCaptures full pump curve
Working VoltageDC 5V – 18VCompatible with 5V logic supply
Output Pulse$F = 4.8 \times Q$Easy calibration in ESPHome
MaterialReinforced NylonResists vibration fatigue

โš”๏ธ The Sensor Showdown

Not all flow sensors are created equal. Compare the range, material, and best use-cases.

What are you building?

Flow Range Capacity (L/min)

Chart.js

Note: Longer bars handle a wider range of water speeds.

Model Size Material Range
YF-S401 DN6 (1/4″) Plastic 0.3 – 6 L/min
YF-S201 DN15 (1/2″) Plastic 1 – 30 L/min
YF-B5 DN20 (3/4″) Brass 1 – 60 L/min
YF-G1 DN25 (1″) Nylon 2 – 100 L/min
* All models typically operate at 5V DC (compatible with ESP32/Arduino).

The Muscle: 5V Relay Module (High/Low Level Trigger) | Tuya Smart switch

  • Spec: 1-Channel or 2-Channel 5V Relay Module with Optocoupler Isolation.
  • Rating: 10A @ 250VAC.
    • Critical Note: For pumps larger than 0.5HP, the starting current (inrush) can be 3-5 times the running current. This can weld the contacts of a standard blue Songle relay.
    • Recommendation: Use the relay module to trigger a Contactor or a specialized Solid State Relay (SSR) for the pump itself. However, for pumps <0.5HP, a high-quality relay module is acceptable if protected by a snubber.
  • Isolation: Look for the “JD-VCC” jumper on the board. This allows us to power the relay coil from a separate 5V source, keeping the noisy 5V back-EMF away from our sensitive ESP32.

Completely replaceable via a Tuya smart switch. Using a smart switch means controlling the On/Off via Home assistant and not via ESP32.

The Safety: RC Snubber & Power Supply

  • RC Snubber: A 100ฮฉ Resistor + 0.1ยตF (100nF) Capacitor in series, placed across the pump terminals (or relay contacts).
    • Physics: When an inductive load (motor) turns off, the magnetic field collapses, generating a high-voltage spike (Back EMF) that can reach hundreds of volts. This spike can arc across relay contacts (welding them) or travel back through the power lines to crash the ESP32. The capacitor absorbs the high-frequency spike, and the resistor dissipates the energy.
    • Component: You can buy pre-made “RC Snubber Modules” or solder a 100nF 400V capacitor and a 100ฮฉ 1W resistor in series.
  • Power Supply: A quality Hi-Link HLK-10M05 module or a branded 5V 2A USB adapter.
    • Warning: Do not use cheap, unbranded phone chargers. They often output “noisy” DC power. The Hall effect sensor in the YF-G1 is sensitive to voltage fluctuations and may report “ghost flow” (pulses) even when water is still if the power rail is noisy.

Display & User Feedback:

We have used an WS2812b LED Ring and programmed it so that users can check the level of water coming in without access to mobile or PC.

image 1

Miscellaneous

  • Jumper Wires: Female-to-Female.
  • Enclosure: IP65 Waterproof junction box (150mm x 100mm x 70mm).
  • Plumbing Fittings:
    • 2x 1-inch Union couplings (critical for removing the sensor for cleaning).
    • Thread seal tape (Teflon).
  • Cable Glands: To seal wire entries against moisture.

ESP32 YFG1 Water Meter

Hardware Setup: The Physics of Placement

This is where 90% of builders fail. You cannot just screw the sensor anywhere. The placement determines whether you measure water or air bubbles.

The Great Debate: Suction vs. Discharge Side

In industrial pumping, you almost never place a restriction or a flow meter on the suction side. This is counter-intuitive to the “Water Hunter” logic (we want to know if water is coming in), but physics dictates otherwise.

Why NOT the Suction Side (Inlet)?

  1. Restriction & NPSH: The suction side relies on atmospheric pressure (or gravity) to push water into the pump. Any device (like a turbine sensor) adds resistance (Head Loss). If the pressure drop across the sensor is too high, the “Net Positive Suction Head Available” (NPSHa) drops below the “Net Positive Suction Head Required” (NPSHr) by the pump.
  2. Cavitation: When NPSHa < NPSHr, the water pressure falls below its vapor pressure. The water literally boils at room temperature, forming vapor bubbles. These bubbles collapse (implode) when they hit the high-pressure impeller vanes, causing pitting, noise (“pumping gravel”), and destruction.
  3. Turbulence: The suction line often contains a mixture of air and water during the priming phase. A Hall effect turbine sensor spinning in an air-water mix produces erratic, useless data.

The Solution: The Discharge Side (Outlet)

Install the YF-G1 DN25 on the Discharge (Output) Side of the pump, after the non-return valve (NRV).

  • The Logic:
    • If the pump is running and the Suction line is full -> Water is compressed and pushed out -> Sensor Registers Flow.
    • If the pump is running and the Suction line is empty -> No water is pushed out -> Sensor Registers 0 Flow.
  • The Benefit: The water on the discharge side is under positive pressure. This compresses any micro-bubbles, ensuring a solid liquid stream that spins the turbine smoothly. The reading is stable, accurate, and cavitation-free.

Plumbing Best Practices: The 10D/5D Rule

To ensure the “laminar flow” required for the Hall effect sensor to be accurate (ยฑ3%), you must follow the 10D/5D Rule utilized in industrial flow metering.

The 10D/5D Plumbing Rule

To achieve ยฑ3% accuracy with Hall Effect sensors, laminar flow is non-negotiable. Turbulence caused by elbows creates “swirl,” falsifying data.

๐Ÿ“ Calculator: Required Pipe Lengths

Enter your pipe diameter to see required straight run lengths.

mm
Before Sensor (10D) 250 mm
After Sensor (5D) 125 mm

๐ŸŒŠ Flow Dynamics Simulation

Visualizing the effect of elbows on rotor stability.

Status: High Turbulence

The 90ยฐ elbow immediately before the sensor creates a vortex. Water strikes the rotor blades at irregular angles. Result: Sensor over-counts or under-counts. Calibration is impossible.

  1. Straight Pipe Before Sensor: You need a straight run of pipe equal to 10 times the pipe diameter before the sensor inlet.
    • For a 1-inch (DN25) sensor: 10 \times 1 inch = 10 inches of straight pipe.
    • Why: Elbows, valves, and the pump outlet itself create “swirl” and turbulence. If water enters the sensor while swirling, it will spin the rotor faster or slower than the actual flow rate, ruining calibration.
  2. Straight Pipe After Sensor: 5 times the pipe diameter (5 inches / 12.5 cm) after the sensor.
    • Why: This prevents back-pressure turbulence from affecting the rotor.
  3. Orientation:
    • Horizontal: Best. Ensure the sensor axis is horizontal (wires up or sideways, not down).
    • Vertical: Acceptable, but only if flow is UPWARDS. Never install with flow downwards, as air pockets can get trapped in the rotor chamber, causing the sensor to read zero even when water flows.
  4. Direction: Look for the Arrow on the YF-G1 body. It must point in the direction of water flow.

Electrical Wiring & Voltage Shifting

image 3

The YF-G1 operates best at 5V-18V. We will power it with 5V from our PSU. The ESP32 GPIOs are 3.3V tolerant. Sending a 5V pulse directly to an ESP32 GPIO is risky for long-term reliability. A voltage divider circuit is recommended.


BabaBuilds Engineering Toolkit

Math & Physics Calculators for the Perfect Smart Water Setup

๐Ÿงช Pulse Calibration Lab

Don’t guess. Perform a “Bucket Test” and enter the data below to generate your exact ESPHome YAML factors.

Results

Pulses per Liter: 48.0
Liters per Pulse (Factor): 0.02083
# Copy this into your ESPHome YAML
lambda: |-
  const float L_PER_PULSE = 1.0f / 48.0f; 
  return id(pulse_counter).state * L_PER_PULSE;

Comparing your real-world measurements against the factory standard (approx 60 pulses/L).
Gap indicates calibration drift due to plumbing.

Total Capacity 1000 L
Est. Fill Time 33 min

๐Ÿ“ Tank Physics Engine

Calculate the exact volume of your overhead tank and estimate fill times based on your flow sensor’s reading.

From Sensor

Leave a review

Reviews (0)

N๏ฟฝj๏ฟฝbrW๏ฟฝ๏ฟฝ๏ฟฝ'๏ฟฝ๏ฟฝy๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝ{ 2z
Pilฤni
clear sky
13.2 ° C
13.2 °
13.2 °
46 %
3.3kmh
0 %
Thu
13 °
Fri
21 °
Sat
21 °
Sun
23 °
Mon
23 °

Related Posts

How to Get the Best FPS in CS2 on Any PC (Ultimate Settings Guide)

This comprehensive guide covers all CS2 video settings that impact performance and quality to Get the Best FPS in CS2 on Any PC

Helldivers 2 Weapons Tier List | All Guns Ranked & Best Uses

This updated Helldivers 2 Weapons Tier List August 2025 ranks every primary and secondary weapon, including Warbond weapons โ€“ from S-tier to D-tier. Discover each gunโ€™s stats, strengths, and best scenarios (which factions or missions they excel in) so you can optimize your Helldivers 2 loadout and bring Democracy to the enemies of Super Earth with the right firepower!

Comprehensive Guide to Bambu Lab 3D Printers Lineup (2025)

Bambu Lab has rapidly become a leading name in...

Bambu Lab Calibration Guide (P1, X1, A1 Mini & H2D)

Bambu Labโ€™s 3D printers are renowned for their automated...

Using Seeed Studio mmWave Module with ESPHome

In the ever-expanding universe of smart technology, the fusion...

Raspberry Pi Automatic Fans Using L298n PWM

Welcome, We all know Raspberry Pi SBC Likes to...
- Advertisement -spot_img