Introduction: Water Meter + Arduino = Aquameterduino !

Picture of Water Meter + Arduino = Aquameterduino !

After a bad water damage (our cellar basically filled up whilst we were away for several days), I decided to monitor our water usage for anomalies. Enters Arduino...

The idea of this project is to use an arduino to count every drop of water that goes through the water company meter. Said arduino needs to be connected to my LAN so that I can query it on a regular basis, it also needs to be aware of (real) time so it can timestamp the water consumption.

For this project you will need:
- an arduino
- an ethernet shield + sd card (based on the W5100 chip)
- a proto shield
- a realtime clock (http://www.ebay.com/sch/i.html?_nkw=DS1307+Based+Real+Time+Clock)
- a shmitt trigger (e.g. 74C14N)
- a capacity (1 microF)
- some resitors (20kohm and about 100Kohm)
- a reed switch
- a reed switch-enabled water meter (Gioanola, about 75 euros http://www.gioanola.it/download/downen/08_eloutput_EN_HI.pdf)

Optional:
- a set of passive POE cables (http://www.ebay.com/sch/i.html?_nkw=Passive+Power+over+Ethernet)

references:
http://www.ganssle.com/debouncing-pt2.htm
http://www.ladyada.net/learn/arduino/ethfiles.html
http://www.cosm.com/
http://www.gioanola.it/download/downen/08_eloutput_EN_HI.pdf


I asked a professional to mount a basic water meter right behind the Water Company one (which by law, I cannot touch). Said basic meter has a little magnet on one of its internal wheels and is shipped with a reed switch. So, in practice, everytime a liter goes through it, the switch is closed momentarily. Of course this switch needs to be de-bounced. This could be done by sotfware but we'll come back to that...

The arduino will serve basic http requests so that it can be queried over the LAN and will also log its activity onto a SD card. So this arduino will be a very busy one... at times. Hence the necessity for the reed switch signals to be conveyed through interrupts so that we never miss a signal. This basically rules out debouncing the switch through software as interrupts and timer do not cohabitate nicely.

Hardware debouncer it is, then !

Step 1: RC Debouncer

Picture of RC Debouncer

So, the reed switch bounces... We are going to transform the spikes produced by said switch into a nice square wave.

Extensive documentation can be found on the net on this topic (and I found this one particularly useful: http://www.ganssle.com/debouncing-pt2.htm).

In a nutshell, R x C = the time during which you want to smooth out your signal. In my case, I chose 20ms which translates into 1 microF for the capacity and 20kohm for the R2 (well all I had available was 2x 10k), R1 needs to be 'bigger' than R2, 100k is good (33k+68k in my case).

A Schmitt trigger later and I have a clean square signal ready to trigger an arduino interrupt.

I tested the setup on a bread board (as you should !) before commiting it to a proper shield.

Step 2: Ethernet and SD Card

Picture of Ethernet and SD Card

The ethernet connection is used to answer a handful of basic http requests. A log of all water meter activity is saved on the SD card.

Using an SD card and an ethernet connection together has proven challenging (both use an SPI connection) until I used the W5100 chip based ethernet shield with an integrated SD card.

Great tutorial there: http://www.ladyada.net/learn/arduino/ethfiles.html

So that's out of the way.

Step 3: Real Time Clock, Interrupts.

Picture of Real Time Clock, Interrupts.

RTC

My real time clocks is based on the DS1307 chip, extremely common. Add a coin cell and a (magic frequency) quartz. I liked the form factor of this RTC as it can be plugged directly onto the arduino pins, like a shield.


Interrupts

And interrupts just, well.., interrupt your program so that you can do something based on that event. Try to be quick (like increment a counter and return) so that if another interrupt shows up, you don't miss it.

Associate a callback method and a pin in your code. Every time a (raising) signals shows up on said pin, you get a callback...

Step 4: Putting It All Together

Picture of Putting It All Together

A little lego for grown ups... I stacked up my arduino, the ethernet shield, my custom shield and the realtime clock.

I added a couple of LEDs to my project and a (nice?) box. Given the location of my water meter, POE cables proved handy.

Step 5: Scripting / Code

Picture of Scripting / Code

Arduino code:

I started from the ladyada code (ethernet+sd card), added an interrupt. The ip address of the shield is the only thing to be configured and you can do it via a config file on the SD card. So this script can be installed as-is, no line needs modification.

RTC setup : I set the time of my RTC using the d1307_setTime script. Good enough for my purpose. Do it once and for all, that's the whole point of the RTC module and its coin battery.

Ip address: if config.txt exists on the SD card, its content will override the ip address.


Linux script:

I wrote a script which runs on a linux box and which crontab fires a few times a day. Pretty brute force as it downloads the whole content of the SD card and then 'explores' it. It sends me an email with a reassuring 'everything is OK' or an alarming 'too much water consumed today' !

IP="192.168.999.999"
EMAIL="me@email.com"

> crontab -l
00 8,16,23 * * * /bin/bash $HOME/bin/watermeter.sh > $HOME/watermeter.log 2>&1

Step 6: Internet of Things

Picture of Internet of Things

I though I would experiment the Internet of Things trend and upload my data to a server. I did so (to Pachube / Cosm) but did not find it added much to this project. I left the functionality in the script as it doesn't hurt and might come in handy someday...

In theory you can connect your arduino directly to it, simplifying the project somewhat and you can install triggers/alerts.

In practice the service is in its beta version and needs to become a lot more friendly. At this point it should be viewed as a repository only, which is only a good thing if the service is reliable over time... we'll see. For now, I decided to keep control over my data logging + processing and my alerts on this side of the cloud...

APIKEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
FEED="99999"
DATASTREAM="xxxxxxxxxx"

https://cosm.com



Voila !

Comments

3rdiii (author)2016-11-27

How muc was the install?

skmbi (author)2015-08-28

Hi! Try site narodmon.ru to send info and get graph and alarm settings.

Im use it.

Look for example here http://narodmon.ru/8779

and radiation monitor http://narodmon.ru/1547

warlock40 (author)2015-02-01

Would it be difficult to add a notification feature to either email or audible alarm. I had a leaking toilet dump hundreds of $$ of water into the drain and didn't notice the usage until the bill. I'd like to add some analytics to the resulting data to tell without looking daily when something goes wrong

nicoo (author)warlock402015-02-01

Hi warlock40, this is the point of watermeter.sh. This script retrieves the Aquameter log file and performs a bunch of actions based on the water consumption.
It does send an alarm email (which caught a couple of toilet leaks for me !).
Take care,
N.

lvan der walt (author)2012-12-26

Very nice project. Im am thinking of doing the exact same thing, in order to curb the ever rising cost of water, and possibly be able to detect water leaks. I have put together the following Fritzing sketch as I am not a electronics bofin at all. Would you be so kind as to check and let me know if this is correct.

Sorry the image

Mchlpl (author)2012-11-13

What you need now is an electrovalve, so that you can remotely cut off water in case of suspicious readouts :)

hankenstien (author)2012-07-23

Another thing that this project made me think of, is if you have a pool that you put up the water company charges you water usage and sewage usage, they assume that the water is being processed in there sewer system, and in some states this can be more expensive then the water usage an the return delivery fee, setting one of these up, could save you alot, especially if you happen to have a pump with a reed switch. I really like your idea, even the case is nice good job all around my friend! Its just one of those that make you think.
HANKENSTIEN

nicoo (author)hankenstien2012-07-26

Thank you for your comment. This meter has proven handy to monitor my sprinkler system too... only to realize that most of our water usage goes into watering the lawn ! This will probably convince me to recycle rain water somehow.

Let me know what you end up building yourself.

Take care,
N.

hankenstien (author)2012-07-20

MAN, that looks like a disastrous, hope you didnt lose too much in the flooding, good invention though.
Good day

About This Instructable

97,405views

226favorites

License:

More by nicoo:Hacked roomba + arduino snowballs into a Eurobot 2013 entry...Flashing bootloader into Arduino UNO R3Arduino Sprinkler System + Web control
Add instructable to: