Water Meter Pulse Sensor

created by hek , updated

In some cases, newer water meters are equipped with a pulse output. However if you have an older power meter without a pulse output, then you might be able to use one of the options below to sense your water consumption.

Use the TCRT5000 IR Barrier Line Track sensor. It emits an infrared light and detects the reflection. If you aim it at the fastest turning hand on your meter, you can detect pulses or a rate.

Some water meters emit a fluctuating magnetic field that can be detected by using a Hall effect sensor. Instructions are available here.

The sensor example sketch counts the pulses from your attached sensor and converts it into liters or gallons per minute and the cummulative water volume.

There are a few parameters that need to be tuned to your water meter. Set the PULSE_FACTOR to the number of revolutions per cubic-meters (or gallons) of water.

You can also set the frequency that the sensor will report the water consumption by updating the SEND_FREQUENCY. The default frequency 3 times per minute (every 20 seconds).

The sensor has two modes of operation:


Use this mode if you power the sensor with a battery. In this mode the sensor will sleep most of the time and only report the cumulative water volume. Unfortunately the sensor cannot report the current water flow rate because the sensor can not track time while sleeping; the elapsed time between two blinks is required to calculate the current flow rate.

SLEEP_MODE = false

In this mode the sensor will not sleep and will report the current water flow rate and the cumulative water consumption to the gateway. This mode requires constant power so you will need to connect the sensor to an electrical outlet.

Wiring Things Up

Start by connecting the radio module.

Sensor Arduino Comment
VCC VCC (3.3 - 5V) Red
DO (digital out) Digital pin 3 (D3) Green


Last updated by web-flow, 7 Dec 2016, "Repo restyled using astyle (#683)"

 * The MySensors Arduino library handles the wireless radio link and protocol
 * between your home built sensors/actuators and HA controller of choice.
 * The sensors forms a self healing radio network with optional repeaters. Each
 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
 * network topology allowing messages to be routed to nodes.
 * Created by Henrik Ekblad <[email protected]>
 * Copyright (C) 2013-2015 Sensnology AB
 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
 * Documentation: http://www.mysensors.org
 * Support Forum: http://forum.mysensors.org
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 * Version 1.0 - Henrik Ekblad
 * Version 1.1 - GizMoCuz
 * Use this sensor to measure volume and flow of your house watermeter.
 * You need to set the correct pulsefactor of your meter (pulses per m3).
 * The sensor starts by fetching current volume reading from gateway (VAR 1).
 * Reports both volume and flow back to gateway.
 * Unfortunately millis() won't increment when the Arduino is in
 * sleepmode. So we cannot make this sensor sleep if we also want
 * to calculate/report flow.
 * http://www.mysensors.org/build/pulse_water

// Enable debug prints to serial monitor
#define MY_DEBUG

// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_NRF5_ESB
//#define MY_RADIO_RFM69
//#define MY_RADIO_RFM95

#include <MySensors.h>

#define DIGITAL_INPUT_SENSOR 3                  // The digital input you attached your sensor.  (Only 2 and 3 generates interrupt!)

#define PULSE_FACTOR 1000                       // Nummber of blinks per m3 of your meter (One rotation/liter)

#define SLEEP_MODE false                        // flowvalue can only be reported when sleep mode is false.

#define MAX_FLOW 40                             // Max flow (l/min) value to report. This filters outliers.

#define CHILD_ID 1                              // Id of the sensor child

unsigned long SEND_FREQUENCY =
    30000;           // Minimum time between send (in milliseconds). We don't want to spam the gateway.

MyMessage flowMsg(CHILD_ID,V_FLOW);
MyMessage volumeMsg(CHILD_ID,V_VOLUME);
MyMessage lastCounterMsg(CHILD_ID,V_VAR1);

double ppl = ((double)PULSE_FACTOR)/1000;        // Pulses per liter

volatile unsigned long pulseCount = 0;
volatile unsigned long lastBlink = 0;
volatile double flow = 0;
bool pcReceived = false;
unsigned long oldPulseCount = 0;
unsigned long newBlink = 0;
double oldflow = 0;
double volume =0;
double oldvolume =0;
unsigned long lastSend =0;
unsigned long lastPulse =0;

void setup()
    // initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion)

    pulseCount = oldPulseCount = 0;

    // Fetch last known pulse count value from gw
    request(CHILD_ID, V_VAR1);

    lastSend = lastPulse = millis();

    attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, FALLING);

void presentation()
    // Send the sketch version information to the gateway and Controller
    sendSketchInfo("Water Meter", "1.1");

    // Register this device as Waterflow sensor
    present(CHILD_ID, S_WATER);

void loop()
    unsigned long currentTime = millis();

    // Only send values at a maximum frequency or woken up from sleep
    if (SLEEP_MODE || (currentTime - lastSend > SEND_FREQUENCY)) {

        if (!pcReceived) {
            //Last Pulsecount not yet received from controller, request it again
            request(CHILD_ID, V_VAR1);

        if (!SLEEP_MODE && flow != oldflow) {
            oldflow = flow;


            // Check that we dont get unresonable large flow value.
            // could hapen when long wraps or false interrupt triggered
            if (flow<((unsigned long)MAX_FLOW)) {
                send(flowMsg.set(flow, 2));                   // Send flow value to gw

        // No Pulse count received in 2min
        if(currentTime - lastPulse > 120000) {
            flow = 0;

        // Pulse count has changed
        if ((pulseCount != oldPulseCount)||(!SLEEP_MODE)) {
            oldPulseCount = pulseCount;


            send(lastCounterMsg.set(pulseCount));                  // Send  pulsecount value to gw in VAR1

            double volume = ((double)pulseCount/((double)PULSE_FACTOR));
            if ((volume != oldvolume)||(!SLEEP_MODE)) {
                oldvolume = volume;

                Serial.println(volume, 3);

                send(volumeMsg.set(volume, 3));               // Send volume value to gw
    if (SLEEP_MODE) {

void receive(const MyMessage &message)
    if (message.type==V_VAR1) {
        unsigned long gwPulseCount=message.getULong();
        pulseCount += gwPulseCount;
        Serial.print("Received last pulse count from gw:");
        pcReceived = true;

void onPulse()
    if (!SLEEP_MODE) {
        unsigned long newBlink = micros();
        unsigned long interval = newBlink-lastBlink;

        if (interval!=0) {
            lastPulse = millis();
            if (interval<500000L) {
                // Sometimes we get interrupt on RISING,  500000 = 0.5sek debounce ( max 120 l/min)
            flow = (60000000.0 /interval) / ppl;
        lastBlink = newBlink;


NameSize# Downloads
tcrt5000.pdf309.61 kB1443

Shopping Guide

Hall Effect Sensor Module
Some water meters generate magnetic field pulses that can be measured by a hall sensor.
156 available - $3.50   Buy
In stock - $1.56   Buy
TCRT5000 IR Barrier Line Track Sensor
This line track sensor might be able to measure the turning wheel rate through the water meter glass.
906 available - $0.99   Buy
In stock - $5.54   Buy


Sensors & Actuators

Related Content