Water Leak Detector
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.
- Water Volume is measured by counting pulses generated by the Hall Effect device.
- Flow Rate is a function of water volume over time.
- The definition of a leak may be argued. Mine may be adopted or freely changed with your own.
- When a leak is detected the flow valve is closed and an SMS message sent to the User.
- The User may send various commands, via SMS, to the device.
- 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
- My code measures the volume of water flowing in blocks of 10 seconds.
- If no water has flowed in this block the Green Led is turned on.
- 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.
- 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.
- When the tap is closed no measurements are taken.
Water Meter Calibration
- In the header file Configuration.h, line TICKS_PER_LITER, must be defined appropriate to the Hall Effect device you buy.
- To calculate this value, load the sketch WaterMeterCalibrate and connect up the hardware as described in the sketch.
- Connect the Water Meter to a water supply and prepare a bucket to collect the water. Turn on the water.
- Press the button. The display changes from Waiting to Collecting.
- When the bucket is full, press the button. The display changed from Collecting to Stopped followed by Ticks and Time.
- Ticks is the number of pulses counted while filling the bucket and Time the elpased time in mill-seconds.
- Calculate TICKS_PER_LITER and place its value in the Configuration.h header file.
- Pressing the button again restarts the cycle.
- Arduino board. I used a Funduino Mega
- Tinysine GSM Shield. Any shield supported by the Arduino GSMshield library will work.
- Nokia 5100. The Adafruit PCD8544 and Adafruit GFX libraries are used for this.
- DS3234 RTC breakout board
- YwRobot 2 channel relay board
- RGB Led
- Hall Effect Water Flow Meter
- Solenoid operated valve
Things To Be Done
- Add more commands to the interface e.g. water used between dates.
- EEPROM should be exploited to save operational data e.g. phone numbers of subscribers, flow meter calibration data, leak detection paramaters
- 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.
- 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.
- The DS3234 needs battery backup to retain date and time. It is only necessary to set up the correct date once.
- 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.
- All hardware pin allocations are defined in Configuration.h You may change freely within limits.
- Device outputs needed to generate interrupts must go to those pins on the Arduino that support interrupts.
- Make sure 3V devices are powered by the 3V source and 5V devices by the 5V source.
- 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.