Go Down

Topic: Water leak detection (Read 2489 times) previous topic - next topic

Jason-K

Hi everyone.
First of all, I should mention that I'm a newbie to the world of arduino's/programming in general, but have an electronics background.
I have been given the task of developing a tool to detect excessive water usage (in the form of water leaks) and provide early notification should such be detected.

The property is a holiday resort(family owned) with over 200 sites, that has had issues with extremely large water bills in the past (in the order of $40,000, well over 4 times the usual water consumption).

My idea is to utilise a water flow sensor (most probably hall effect type) in the main water supply pipe, count the cycles and average it over the last 24 hours. If the average is excessively high, an email alert will be sent to the manager to investigate.

The hardware I will be using is the Freetronics EtherTen (embedded ethernet and SD).

Now I believe I have all the info I need to get the arduino to send the email, including ethernet library etc...but I have hit a brick wall in the actual pulse counting and average calculation. I have seen some examples that just count the pulses and print to serial port, but I can't really get any further than that.

Any help regarding direction, or any other ways to achieve the outcome would be very much appreciated.

Jason

lemming

#1
Apr 09, 2012, 10:00 am Last Edit: Apr 09, 2012, 10:03 am by lemming Reason: 1
I assume that you are using commercial water flow meters. If this is the case they state in their data sheets how many litres pass through the meter per tick (or pulse). You could thus report the actual volume used per hour using millis().

You would need to connect the output of the water meter to one of the hardware interrupt pins of the Arduino (and use attachInterrupt()) so as not to miss any pulses.

Once you have detected excess usage will the manager go around 200 sites checking for wastage?
Our local water authority is tackling the same problem (determining whether leaks or wastage) by comparing the usage reported by a meter on the mains against the aggregate readings on individual meters downstream. Any discrepancy between the two readings indicates a leak. Otherwise the excess usage (i.e. waste by guests) is indicated by the individual meters.

200 meters are too many to put in, but a meter on the main and a few more on various branches would narrow the problem down to a segment of the resort.

Jason-K

Thanks for the reply.

Yes, they will be commercial water flow meters. At this stage, I was only going to utilise the one sensor/arduino to detect current water flow/24 hour average...given that we know a rough average water usage over 24 hours which is fairly constant, if I could detect anything exceeding this amount(with some overhead) over that period, there must be something wrong.

At the moment, (after receiving said large water bill) they are manually watching the mains meter tick over while they turn off different branches of piping to figure out which branch has the problem. Your suggestion however with having multiple meters on different branches would certainly make their job a lot easier!

I will get stuck into some code and report back.

Cheers,
Jason

robtillaart


For the average you might use - http://arduino.cc/playground/Main/Statistics -

However looking at the problem you not only want to detect an higher average daily use, but also a sustained flow of longer than lets say an hour should cause a "code orange" alert, you don't want a leak to flow for several hours ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Jason-K



For the average you might use - http://arduino.cc/playground/Main/Statistics -

However looking at the problem you not only want to detect an higher average daily use, but also a sustained flow of longer than lets say an hour should cause a "code orange" alert, you don't want a leak to flow for several hours ...


Ah yes, that's what I'm looking for, thanks!

Regards to the high sustained flow...I don't think it will be overly effective, as in peak times(morning and evenings - showers for over 1000 guests), the peak flow would be considerably high, making any water leak a small percentage, and triggering false alarms. However, I will keep it in mind. It might even be worthwhile doing some logging to find total peak flows at certain times of the day...maybe when I have a bit more experience!

Cheers,
Jason

wildbill

Since you have SD capability, once you have the basic version up and running, consider logging the data. You can do some analysis in other tools (Excel?) and keep a record of what normal usage is hour by hour. Then the device can use that as a more accurate (probably) means of detecting a problem.

Jason-K

Thanks wildbill, that is certainly on the cards (excuse the pun) for the future, once I get the basic program working.

Should I be debouncing the hall sensor at all? If so, software of hardware debounce?(Schmitt trigger)

It's coming along nicely, surprisingly!

PeterH

If you're leaking for leaks, presumably the way to detect that is that the flow rate never quite drops to zero. So, rather than looking for a sustained high flow, you would need to look for a sustained period with a constant, low but non-zero flow. With that many outlets, there may only be a few times of the day when you can confidently predict that the flow should really be zero.
I only provide help via the forum - please do not contact me for private consultancy.

Jason-K


If you're leaking for leaks, presumably the way to detect that is that the flow rate never quite drops to zero. So, rather than looking for a sustained high flow, you would need to look for a sustained period with a constant, low but non-zero flow. With that many outlets, there may only be a few times of the day when you can confidently predict that the flow should really be zero.


Very interesting idea, certainly one that had not ever crossed my mind!
I'm thinking it should be easy to do this, using an if statement to check if current flow is lower than the "previouslow" variable and write the new low to that variable. Eventually it should settle to a constant minimum value, and we would know roughly the size of the water leak. Brilliant!

I think I can confidently say that between about 12am-5am, flow should be minimal, except the few services running sporadically like pool refilling and effluent systems...

I have since found out that there are 2 main water feeds in a loop arrangement, so I need a sensor in each main pipe and aggregate the two together.
Now it makes it tricky...what sort of issues would arise attempting to use two interrupts concurrently with essentially the same program associated with it on a single Arduino? I'm guessing possibly a few lost pulses if the second interrupt occurs while the first is still processing?


Thank you for your excellent suggestion!

Cheers,
Jason

wildbill

Quote
I think I can confidently say that between about 12am-5am, flow should be minimal, except the few services running sporadically like pool refilling and effluent systems...

Depends on your clientele - in some cases, at 12am, the party's just getting really started  ;)

Quote
Now it makes it tricky...what sort of issues would arise attempting to use two interrupts concurrently with essentially the same program associated with it on a single Arduino? I'm guessing possibly a few lost pulses if the second interrupt occurs while the first is still processing?

This is why your interrupt routines should do as little as possible - in this case just increment a count. What frequency are the pulses from the water meter?

Jason-K

Hehe, well certainly for some, 12am is when the show gets on the road!

It should be very low frequency, but have not selected the sensors yet...checking the data sheets for a few I have found, somewhere in the order of 300Hz for absolute peak flow, but very likely to be much lower than that. I assume the 16MHz clock rate of the Arduino should handle that with ease, even with a large program running (without delays)?

Constantin

DLJ has some nice water meters at watermeters.com that feature a tick for every gallon that passes through them. I have used them before, great performance and good cost.

I second only using the ISR to increment the flow count and then going back to the main loop. Periodically, read and clear the accumulated flow ticks. In the past, I would have even steered you in the direction of the Dallas/Maxim line of 1-wire accumulators (great chips!) in order to monitor multiple water meters but alas Dallas/Maxim decided to discontinue them and not offer a replacement. So make do with the two hardware interrupt pins you have or use the PinChangeInt function to add more interrupts.

You should also consider using an RTC if you want to log the time accurately... I have had great luck with the DS3231 series. The Chronodot is available in a breadboard version, works great. Simply program the thing to output a square wave at 1Hz and you have a great timing system.

Jason-K

So this is what I have come up with so far. I am, however struggling to come up with any ideas on how to record the usage over the last 24 hours. I could copy the same as "currentLPMin" code with a different timer, however I wouldn't be able to display a running total until the timer reaches 24 hours before it would update.

Any suggestions would be appreciated.

Code: [Select]
int ledPin = 13;
volatile int sensorState = LOW;
volatile unsigned long flowCount = 0; //total number of pulses from water meter since start
const float litresPerPulse = 4.75; //Flow sensor correction value, how many litres per sensor pulse
float litresUsedTot = 0.0; //Total litres used since program started
float avgLPMin = 0.0; //Average Litres Per Minute since program started
float currentLPMin = 0.0; //Current flow rate in Litres Per minute
float lastLP24Hr = 0.0; //Litres used in last 24 hours
float minFlowRate = 0.0; //The minimum flow rate measured
int sampleTime = 2500; //sample time for checking current flow rate - in milliseconds
unsigned int timerCount = 0; //Counter for pulses to determine frequency
unsigned int currentLPMinTimer = 0; //timer for current litres per minute calculation
unsigned int last24HrTimer = 0; //timer for litres used in the last 24 hours


void setup()
{
  currentLPMinTimer = millis(); //get current clock time for current Litre per minute calculation
  last24HrTimer = millis(); //get current clock time for last 24Hr usage calculation
  pinMode(ledPin, OUTPUT); //Initialize the LED pin as an output
  attachInterrupt(0, incrementFlowCount, RISING); //listen for hall sensor pulse, and increment flow count.
  Serial.begin(9600); //Start serial port
}

void loop()
{
  litresUsedTot = litresPerPulse * flowCount; //Calculate total litres used since program start
  avgLPMin = litresUsedTot / millis() * 60000 ; //Calculate avg flow in mins since program start
  if ((millis() - m1Timer) >= sampleTime) { //check if it has reached sample time
    currentLPMin = timerCount / m1Timer * 60000; //calculate current flow in LPM
    currentLPMinTimer = millis(); //reset timer after calculation
    timerCount = 0; //reset count to 0 for next sample
  }
  last24HrUsage =

}

//************Increment the flow counter***********
void incrementFlowCount(){
  flowCount++;
  timerCount++;
}

Several things...

  If you want to monitor more than one meter/device, consider using a multiplexer and polling.  A multiplexer is a circuit that switches between inputs or outputs based on the status of an address or 'SELECT" pin.  Here's a link to a very simple one:

http://www.toshiba.com/taec/components2/Datasheet_Sync//168/7380.pdf

They come in lots of flavors.  You could then use your Arduino to select which meter you want to listen to.  One way to do this would be to sample the rate (switching to a new meter and counting ticks for a period of time to measure flow rate, then switching to next meter).  You'd lose absolute volume information between samples, but you could estimate it from the sample info.  Alternatively, you could load hardware between the Arduino and your meters so that the meter ticks acted as clocks on accumulators (counters), which the polling software then reads & clears/resets.

Regarding detecting problems...

  It seems you want to detect changes over time as well as absolute values over time.  For changes, capturing differences is what you want.  So if today's value is 1000 gallons but yesterday was 400 gallons, that's a change of 600 gallons.  If you measure your daily fluctuations for a bit and find that the average fluctuation (standard deviation) is, say, 200 gallons; then a change of 600 gallons is very unusual (probably happening less than 2% of the time).  One the other hand, if you accumulate values (adding yesterday to todays for a period of, say, 7 days), then you can compare to your expected totals over that time and again decide whether to sound an alarm.

Locating problems...

  If you have 200 places where you might have problems, and you want to speed up locating the problem, you can decide how many places are a reasonable number ro check manually as compared to the cost of having the meters.  So, for example, if it's expected that it will take 15 minutes per spot to check, and your person checking is paid $10/hr, that's $2.50/spot.  If you estimate that leak problems will happen 6 times / year, then it's $15 per spot per year.  If you estimate that your meters will last 5 years, then it's $75 per spot / 5 years to check manually as compared to the meter cost.  If the meters cost less than that, you'd be justified in having a meter per spot; if not then divide into the meter cost to determine how many to use. 
  That said, you only need 2 meters to split the area in half, 4 to split it into quarters, etc.  Using a binary search, you can sample branches of branches to locate which area has the problem.

  Okay, so that's a lot and maybe not all that clear, but I hope it helps.  Please feel free to ask clarifying questions.

Go Up