This project is inserted into the domestic water feedpipe and measures flow, controls an on/off valve and communicates via SMS. Leak detection strategy is a matter of choice and my algorithm may be easily replaced by your own.

This is a work in progress. More coming


Principle of Operation.

  1. Water Volume is measured by counting pulses generated by the Hall Effect device.
  2. Flow Rate is a function of water volume over time.
  3. The definition of a leak may be argued. Mine may be adopted or freely changed with your own.
  4. When a leak is detected the flow valve is closed and an SMS message sent to the User.
  5. The User may send various commands, via SMS, to the device.
  6. The current repetoire of commands is
  • Tap On
  • Tap Off
  • Ping (reports current state of tap)
  • Reset (turns the tap on and resets all counters)

Leak Detect Strategy

  1. My code measures the volume of water flowing in blocks of 10 seconds.
  2. If no water has flowed in this block the Green Led is turned on.
  3. If water flowed in this block and the previous block had no flow then water has started flowing. The time is noted and the Blue Led turned on.
  4. If water flowed in this block and also the previous block, compare the current time to the time when water started flowing. If the difference is greater than a pre-defined limit a Leak has been encountered. The tap is closed, the Red Led turned on and an SMS alert sent to the User.
  5. When the tap is closed no measurements are taken.

Water Meter Calibration

  1. In the header file Configuration.h, line TICKS_PER_LITER, must be defined appropriate to the Hall Effect device you buy.
  2. To calculate this value, load the sketch WaterMeterCalibrate and connect up the hardware as described in the sketch.
  3. Connect the Water Meter to a water supply and prepare a bucket to collect the water. Turn on the water.
  4. Press the button. The display changes from Waiting to Collecting.
  5. When the bucket is full, press the button. The display changed from Collecting to Stopped followed by Ticks and Time.
  6. Ticks is the number of pulses counted while filling the bucket and Time the elpased time in mill-seconds.
  7. Calculate TICKS_PER_LITER and place its value in the Configuration.h header file.
  8. Pressing the button again restarts the cycle.

Parts List

  1. Arduino board. I used a Funduino Mega
  2. Tinysine GSM Shield. Any shield supported by the Arduino GSMshield library will work.
  3. Nokia 5100. The Adafruit PCD8544 and Adafruit GFX libraries are used for this.
  4. DS3234 RTC breakout board
  5. YwRobot 2 channel relay board
  6. RGB Led
  7. Hall Effect Water Flow Meter
  8. Solenoid operated valve

Things To Be Done

  1. Add more commands to the interface e.g. water used between dates.
  2. EEPROM should be exploited to save operational data e.g. phone numbers of subscribers, flow meter calibration data, leak detection paramaters

Design Choices

  1. Arduino or Raspberry Pi? Because Arduino is a 5V device and the GSM shield and Relay Shield are 5V it made sense to go Arduino to avoid using voltage level shifters.
  2. Communication. SMS or Internet? My original version used the messaging app Telegram. However that needs an internet connection. I didn't want to rely on home WiFi and a 3G GSM shield that supports SSL is much more expensive than a 2G GSM shield. So I went for SMS.

DS3234 Setup

  1. The DS3234 needs battery backup to retain date and time. It is only necessary to set up the correct date once.
  2. In WaterControl.ino, function setup(), line SetTimeDate(...) set the current date and time, upload the program to Arduino and run it. The DS3234 is now setup and does not need to be reset as long as the battery backup is present. Now comment out the SetTimeDate(...) line.

Software Design

  1. All hardware pin allocations are defined in Configuration.h You may change freely within limits.
  2. Device outputs needed to generate interrupts must go to those pins on the Arduino that support interrupts.
  3. Make sure 3V devices are powered by the 3V source and 5V devices by the 5V source.
  4. Rather than cram too much code in the .ino file I separated discrete funtions into paired *.h and *.cpp files. THis is good practice and should be adopted in all Arduino projects.