Household water manifold - A flow meter on each output. Advice appreciated.

Thread Starter

Clayton Allen

Joined Feb 15, 2016
17
Greeting folks,

I recently had a huge water bill ($300+) and for the life of me couldn't locate the cause right away. So I went down to the basement and did some poking around. As it turned out, I have a backup sump pump that is powered by water that was stuck in the on position. I couldn't spot it right away because not only is it super quite next to my central air unit, the drain out in the backyard was clogged with tree roots and frozen (so no soggy ground either).

This ultimately gave me the idea to make a super nerdy, over engineered way to monitor my household water usage. In my basement, I have this PEX manifold in which the main service line splits to all areas of the home needing water. This is nice because it makes it super easy to isolate each output. So the idea would be to simply tie a water flow meter to each output of the manifold and use a microcontroller such as Arduino or Particle Photon (preferred) to monitor/log/get alerts as required.

Sample water meter:


As I understand it, these use a hall effect to measure the flow of water. Now if I were to simply use one on the main, I could simply program an interrupt and start pulse counting. That's fine and dandy but I have several outputs on the manifold to monitor. In fact, I have 24 outputs (hot and cold water) to hook into. Did I already mention "Super nerdy and over engineered" yet?

So I did about 7 hours of research yesterday, and found that my initial impression of using an IO expander like the MCP23017 wouldn't cut it because they simply allow an on or off state. They would count pulses and increment accordingly. Well this is the point where I'm drawing a blank. In theory, I would need a method that if 1 or more lines are in use that I could get this data and send it over the webs for tracking and say for example a line runs for X amount of time I could receive an alert letting me know of a potential leak in X location. I could even add extra protect by using solenoid valves to cut it off from my phone (as I develop this project past step 1 of course).

Can hear from you all about your ideas to count pulses (possibly concurrently)?
 

GopherT

Joined Nov 23, 2012
8,009
Option 1

Get two arduino's and treat each set of 12 valves as separate projects.

I would scan through all 12 meter outputs and record a tick each time an output changes (I assume the frequency is less than a few hundred hertz). You should be able to scan all 12 about 10,000 to 50,000 times per second so you don't miss a tick. You can add a divide by 16 counter to each line if they are ticking off volume increments faster than 10k Hz.

If you want to do it with a single arduino, a similar method would be used. I would add a multiplexer with less frequent sampling. How about sharing some detail on your meter? Also, that meter does not look too robust. Make sure it has proper testing authority stamps - your insurance company may not pay for water damage caused by unlisted eBay/Chinese novelty prototyping parts.
 

mcgyvr

Joined Oct 15, 2009
5,394
Arduino mega has enough digital IO

Is that flow meter really rated for the expected flow rates/pressure,etc..? Looks awful small
 

Thread Starter

Clayton Allen

Joined Feb 15, 2016
17
How about sharing some detail on your meter? Also, that meter does not look too robust. Make sure it has proper testing authority stamps - your insurance company may not pay for water damage caused by unlisted eBay/Chinese novelty prototyping parts.
I found this one on Adafruit:



The insurance aspect is one not yet considered. Given that my PSI couldn't be higher than what this is rated for, I would hope this could handle the potential flow during line use. I don't however see that it has any sort of official blessings stamped on it. I've also added the datasheet as an attachment.

I would scan through all 12 meter outputs and record a tick each time an output changes (I assume the frequency is less than a few hundred hertz). You should be able to scan all 12 about 10,000 to 50,000 times per second so you don't miss a tick. You can add a divide by 16 counter to each line if they are ticking off volume increments faster than 10k Hz.
So this in translation would to store a variable for each channel then during each loop to increment the value if a flow is happening?

Here is also some data from the Particle Photon pinouts:




I sort of wanted to try this over the Arduino due to the ease of internet capability. However the Mega, is indeed well equipt with GPIO...
 

Attachments

Sensacell

Joined Jun 19, 2012
3,449
It all depends on the maximum signal output frequency of the sensor.

If it's relatively low (a few 10s of pulses per second) you could get away with polling it through an I/0 expander / shift register scheme.
Every time an input changes you would capture the value of a free-running timer, then compare this to the previous capture to measure the frequency (period) of the signal. Easy to to totallize the values too, just count all the pulses, then you could see a nice ratio of where the water went.
 

Picbuster

Joined Dec 2, 2013
1,047
Attention is required when more then 1 flow meter is installed. creating a multi drop two wire rs485 line is the most simple way to get the data to the main processor. The main processor polls when no answer it produce alarm.
The main processor needs
a: tcp/ip interface allowing to internet
b: internal clock
c: backup battery
d: internal counters each flow meter one.
e:sd or other medium to save counters when emergencies occur.
f: simple program to handle the lot.
@ flowmeter simple pic handling the rs485.(address/data handling)

main processor pic/atm/msp/ beck< read info or complete hardware like arduino or microchip demo board.
 

dannyf

Joined Sep 13, 2015
2,197
using an IO expander like the MCP23017 wouldn't cut it because they simply allow an on or off state.
those chips allow interrupts so yes, they can be made to work.

Typical AVRs can be made to work here as well - ATmega2560 for example supports multiple pin change interrupts, in addition to external interrupts. Not to mention that timer interrupts can be made to work here as well.

Lots of choices.
 

Thread Starter

Clayton Allen

Joined Feb 15, 2016
17
Let's see if I understand this correctly...

Let's say I wire up a Arduino Mega, as mentioned above they support multiple pin change interrupts. I was under the impression that an interrupt will stop all other functions so that a count for example, may be taken of the ticks in the Water flow sensor. So if let's say the upstairs bathroom and the downstair bathroom showers are running (2 hot water lines & 2 cold water lines). Technically, I would only capture one line?

Your guy's inputs are very interesting and useful. Thanks!
 

GopherT

Joined Nov 23, 2012
8,009
Let's see if I understand this correctly...

Let's say I wire up a Arduino Mega, as mentioned above they support multiple pin change interrupts. I was under the impression that an interrupt will stop all other functions so that a count for example, may be taken of the ticks in the Water flow sensor. So if let's say the upstairs bathroom and the downstair bathroom showers are running (2 hot water lines & 2 cold water lines). Technically, I would only capture one line?

Your guy's inputs are very interesting and useful. Thanks!
Not exactly.

Lets say some of Your meters are ticking away (low to high, high to low) and some are not ticking at all. The arduino quickly scans the current state of all the current state (high or low) of all the meters and comparing them against the previous time the states were checked. Doing this much faster than any meter can go from low to high and back to low again. The arduino records each time a meter makes a transistion to a variable value dedicated to that meter to monitor total flow. If you want, you can also record the time when the tick occurred to calculate the flow rate of each meter (must have the time for the previous time the meter changed states as well).

All this has to be accessible to you to be valuable (serial interface to your laptop, a wifi or bluetooth connection or even a small serial display on the arduino are possible).

Cheers.
 

dannyf

Joined Sep 13, 2015
2,197
It takes very little time to process an interrupt: 20 ticks for the overhead, and maybe 50 ticks forbthebisr itself. Let's say 100 ticks per interrupt.

Let's say that your sensor generates 1 interrupt per revolution. X 24 sensors and you have 24 interrupts per revolution, or 2400 ticks per revolution.

An avr is good for 16 million ticks per second, easily. That means your sensors can revolve at 16milkion / 2400 or 8k per second before you exceed the avrs processing capability.

Not a fat chance.
 

GopherT

Joined Nov 23, 2012
8,009
So the attachment I uploaded is a listing of pins that interrupts can be attached to per Arduino.cc. Am I looking the wrong listing? this shows fewer than 24 pins.
You don't have to use interrupts. You just scan, note the change, update the display if needed, and scan again.

The most important thing we need to advise you is information on how fast the meters tick the output pin on/off - that way we can assure you that the arduino can handle 24 of these meters without issue.
 

Thread Starter

Clayton Allen

Joined Feb 15, 2016
17
Well I most certainly thank you for your help...

So I would simply need to declare the sensors and their pins i.e. s1 = D3 , s2 = D4 , and so on... Then program a for loop to go through each one and read that status and update variable that treat ticks as x amount of liters have passed through x sensor. Using the idea of data persistence mentioned above I would take the new number of ticks and add that to the prior number of ticks counted. In turn allowing me to calculate how much water usage has occurred through each line.

Did I get that right?
 

Thread Starter

Clayton Allen

Joined Feb 15, 2016
17
So it occurred to me that I may be able to simulate this idea using a Particle Photon. I was reading the documentation on PWM. It states the PWM takes three params: Pin, Value, and Frequency. Couldn't I use this to simulate a water flow on the Arduino?

analogWrite() (PWM)
Writes an analog value to a pin as a digital PWM (pulse-width modulated) signal. The default frequency of the PWM signal is 500 Hz.

Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite() (or a call todigitalRead() or digitalWrite() on the same pin).

// SYNTAX
analogWrite(pin, value);
analogWrite(pin, value, frequency);
analogWrite() takes two or three arguments:

  • pin: the number of the pin whose value you wish to set
  • value: the duty cycle: between 0 (always off) and 255 (always on).
  • frequency: the PWM frequency: between 1 Hz and 65535 Hz (default 500 Hz).
NOTE: pinMode(pin, OUTPUT); is required before calling analogWrite(pin, value); or else the pin will not be initialized as a PWM output and set to the desired duty cycle.
Maybe set a pin to a 25% duty cycle at a certain frequency that could sim that of the sensor at full flow, perhaps?

I could simply just sort hotplug the jumper from the Photon into the pin waiting for a reading...
 

Thread Starter

Clayton Allen

Joined Feb 15, 2016
17


Arduino Code:

int sensorPin = 7;
int sensorCount = 0;


void setup() {
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}

void loop() {
int sensorRead = digitalRead(sensorPin);
if( sensorRead == HIGH){
sensorCount++;
}
Serial.print("Sensor read: ");
Serial.print(sensorCount);
Serial.println(" ticks");
}


Particle Photon Code--Generates a 25% duty cycle @ 1Hz

int ledPin = D3;

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop() {
analogWrite(ledPin, 63.75, 1);
}
 

GopherT

Joined Nov 23, 2012
8,009
So it occurred to me that I may be able to simulate this idea using a Particle Photon. I was reading the documentation on PWM. It states the PWM takes three params: Pin, Value, and Frequency. Couldn't I use this to simulate a water flow on the Arduino?



Maybe set a pin to a 25% duty cycle at a certain frequency that could sim that of the sensor at full flow, perhaps?

I could simply just sort hotplug the jumper from the Photon into the pin waiting for a reading...

Your meters generate a square wave (50% duty cycle) at 0 Hz (no flow) to 222 Hz (30 liters per minute). 2.25 mL between rising edges of the meter output.
 
Last edited:

Thread Starter

Clayton Allen

Joined Feb 15, 2016
17
So I changed my code to 50% duty cycle and 222Hz. I get a nice and steady "flow" of 1s and 0s (111111000000111111). However, when I reduce the frequency to much lower values (the faucet not all the way on) I get very erratic readings (10001110010111010110101). Any ideas on what could cause that?

I would almost expect that if the frequency of change between high and low was further apart so would the 1s and 0s.
 
hello,
i'm using the same model... i found the way to.. it works great
VARIABLES :
int pressure;
volatile int flow_frequency; // Measures flow meter pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowmeter = 3; // Flow Meter Pin number
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
flow_frequency++;
}

SETUP :
{
pinMode(flowmeter, INPUT);
Bridge.begin();
attachInterrupt(digitalPinToInterrupt(3), flow, RISING); // Setup Interrupt
// see http://arduino.cc/en/Reference/attachInterrupt
sei(); // Enable interrupts
currentTime = millis();
cloopTime = currentTime;
}
//you may change bridge.begin by serial.begin(rate) ( i 'm using with yun)

LOOP

l_hour = (flow_frequency * 60/7.5); // (Pulse frequency x 60 min) / 7.5Q = flow rate in L/hour
flow_frequency = 0;
pressure=l_hour;

Console.println (pressure);
and you get liter/h.. you may change in gallon
Have fun
Fred
 
Top