Every year, plumbing leaks cause billions of dollars of property damage in the United States alone. According to the Insurance Information Institute, the average water damage insurance claim is a staggering $10,234. Water damage can result from a host of problems, many of which are difficult to predict. A burst hot water tank, pinhole leaks in copper piping, an under-sink faucet leak, or a frozen pipe can all culminate in destroyed insulation, ruined plumbing, and sagging ceilings.
A plumbing leak is more likely to damage your home than fire, lightning, or burglary. Every year, 8.1% of homes will experience a plumbing leak, contributing to over $10 billion dollars in insurance claims every year. In fact, on average, American household wastes 10,000 gallons of water every year due to water leaks. These can come from sources as seemingly innocuous as a stuck toilet flapper or a small under-sink leak in your guest bathroom. However, over time, these small leaks accumulate thousands of gallons of wasted water. Just like it’s essential to install smoke detectors in your home’s bedrooms to protect yourself in the event of a fire, installing a leak detection system can alert you of leaks before they become disastrous.
Water damage is an avoidable calamity. You can get informed about any water leak in your house by installing leak detection system. Leak detection systems meticulously monitor the flow of water as it passes through the pipes, and can reduce the risk by alerting you to problems quickly, so you can act to prevent severe damage. A leak detection system protects your home from one of the most common and costly damages to households. A plumbing leak is more likely to damage your home than fire, lightning, or burglary.How does a traditional leak detection system work?
Traditional leak detection systems work by monitoring water flow through either a mechanical turbine or ultrasonic wavelengths. These leak detection systems observe the pattern of the water flow, either by counting the gallonage passing through the sensor or sonically recording the time delay. Other leak detectors also cut off water by detecting the presence of moisture. If these leak detection systems sense moisture is reaching the floorboards, a mechanical valve is triggered that will block water flow. Moisture-sensing leak detectors are better suited for under-sink of point-of-use applications. Whole-house leak detection systems tend to track water usage to detect potential leaks.
Mechanical leak detection systems, like the FloLogic, use an impeller to count the gallons as they pass through the unit. As water flows through the system, the blades on the impeller fan spin. As the fan spins, the gallonage of water passing through the system is recorded and communicated back to the system. This type of mechanical leak detection system works by physically tracking the water flow. Water demand in a home usually comes in intervals, like when wahing dishes or brushing your teeth. Sustained periods of water flow indicate to the system that a leak is present somewhere in the plumbing or faucet.
Other leak detection systems, like the StreamLabs Control, use ultrasonic waves to detect irregular water patterns within your pipes. The StreamLabs unit transmits ultrasonic waves both upstream and downstream, recording the rate of flow. The flow data is then communicated to your Wi-Fi router and relayed to your smartphone. If your Wi-Fi goes down, the StreamLabs unit pulls historical water usage data and any settings you’ve programmed into it to continue to monitor water flow. Similar to the FloLogic unit, when the StreamLabs senses that water flow has exceeded expected use for an extended period of time, the ball valve inside the unit will close and stop water flow to the entire home. The StreamLabs app will also reflect the water’s temperature, the humidity of the room, and the water pressure.
A reverse osmosis leak detector is an under-sink leak detection device that shuts off water flow when it detects the presence of moisture. Reverse osmosis leak detectors are used to protect your cabinets and floorboards from flooding if your reverse osmosis system begins to leak or your tubing or fittings fail. Water damage beneath a sink can lead to warped cabinetry, mold growth, and ruined hardwood. Just like whole-house leak detection systems monitor water usage to protect your home from damage, these leak detection devices will shut off your reverse osmosis unit at the first detection of moisture.My Solution, detecting Water Leak from Sound
Household water fixtures and appliances produce sound signals when in use. Recording, pre-processing, and analyzing sound signals generated from household water fixtures will help to distinguish between normal operational conditions and abnormal conditions that would indicate a leak. Sound sensors are relatively cheap and easy to install than flow and pressure sensors. Using sound sensors, it is possible to generate time series data which can be used to generate a machine learning model to detect leakage. This requires a mechanism to analyze and recognize audio data collected using sound sensors.
In this project, I will use the SensiML Machine Learning Platform to record the audio and make a machine learning model for household leakage detection from the sound. The approach consists of recording the sound signal that is produced by water fixtures and appliances in the kitchen & toilet and then using machine learning to detect water leaks. This method may not be useful for detecting leakage in the underground water supply line or leakage that is soundless. It can be very effective for detecting a dripping tap, leakage from toilet cisterns, or from an external pipe leak that produces sound. All these leaks are very significant and must not be ignored. A dripping tap can lose between 3-30 liters per day, and leakage from toilet cisterns may reach up to 340 liters per day.What Factors Affect These Sounds?
There are several factors that affect the loudness and the frequency range of the sounds made by water leaks transmitted on the pipes and transmitted to the surface of the ground:
- Water pressure in the pipe
- Pipe material and pipe diameter
- Soil type and soil compaction
- Depth of soil over the pipe
- Surface cover: grass, loose soil, asphalt, concrete slab, etc.
The loudness or intensity of the leak sound is directly proportional to the water pressure inside the pipe. Metal pipes, such as iron mains, copper services, and steel pipes, transmit water leak sounds that are a louder and higher frequency than do PVC pipes or asbestos-cement pipes. The ground cover, whether it is an asphalt street, loose dirt, concrete slab, or grass lawn, also makes an important difference. Hard street surfaces and concrete slabs resonate with the sounds of the water leak, and the leak may be heard for 5 to 10 feet or more on either side of the water pipe. Grass lawns and loose dirt surfaces do not offer such a resonating plate-like surface, and their surface variations make firm contact more difficult.Recording Audio Data and Building Dataset
To build this project, we need to collect audio data that will be used to train the machine learning model. Since the goal is to detect the sound of a water leak, we need to record the sound of different water leaks (e.g. dripping tap at different speeds, toilet cisterns leakage, etc.) from different places (e.g. kitchen, toilet) at different times (e.g. day and night). We also need some examples of normal faucet operation sound and typical background noise that doesn't contain the sound of a faucet, so the model can learn to discriminate between the leakage and normal use.
For a simple audio classification model like our one, we should aim to capture around 15 minutes of data. We have three classes, and it's ideal if our data is balanced equally between each of them. This means we should aim to capture the following data:
- 5 minutes of background noise, with the label "noise"
- 5 minutes of running faucet noise, with the label "operation"
- 5 minutes of leakage noise, with the label "leak"
In the real world, there are usually additional sounds present alongside the sounds we care about. For example, water leakage may accompany by a running exhaust fan sound and normal use of the faucet is often accompanied by the sound of dishes being washed, teeth being brushed, or a conversation in the kitchen. Background noise might also include the sounds of television, kids playing, or cars driving past outside.
It's important that your training data contains these types of real-world sounds. If your model is not exposed to them during training, it will not learn to take them into account, and it will not perform well during real-world usage.
For this tutorial, I will try to capture the following:
- 1 minute of background noise without much additional activity
- 1 minute of background noise with a TV or music playing
- 1 minute of background noise featuring occasional talking or conversation
- 1 minute of background noise with the sounds of housework
- 1 minute of background noise with fans and washing machine
Running faucet sound
- 1 minute of a faucet running in the kitchen
- 1 minute of a different faucet running in the toilet
- 1 minute of a faucet running with a TV or music playing
- 1 minute of a faucet running with occasional talking or conversation
- 1 minute of a faucet running with the sounds of housework
- 1 minute of a dripping tap sound in the kitchen
- 1 minute of a dripping tap sound in the toilet
- 1 minute of a toilet cisterns leakage sound
- 1 minute of a pipe leakage sound
- 1 minute of a leakage sound with some background noise
It is not always possible that we will get all the data we want and it's ok to go without some but we should still obtain 5 minutes of data for each class. However, a model will perform better in the real world if it was trained on a representative dataset.Getting Started
We have collected enough background knowledge. Now, it's time to get the hand dirty. For this project, we are going to use PSoC™ 6 62S2 Wi-Fi BT Pioneer Kit and IoT Sense Expansion Kit for recording the data and running the machine learning model. For developing a tinyML machine learning model for the PSoC 6 microcontroller we will use the SensiML platform here. IoT Sense Expansion Kit has a built-in microphone that will help to record audio data.Setup Development Environment
We are going to use ModusToolbox Software here for developing the firmware for PSoC 6 Kit. ModusToolbox is a software package for the PSoC devices which includes the PSoC SDK, ModusToolbox IDE, and Cypress Programmer. The PSoC 6 SDK includes the standard Cypress tools such as PSoC PDL API (based on PDL 3.1), Middleware Libraries, Command-Line Tools, fw-loader, PSoC 6 MCU Configurators, CapSense, and more.
Go to the link below to download & install ModusToolbox:
After installing the ModusToolbox watch the following introductory training video on ModusToolbox.
Before get starting I also recommend watching the following webinar recording:
If you watch the above videos you will get good knowledge about ModusToolbox. Now, run the ModusToolbox IDE, and from the left Panel click on New Application to create a new application.
Choose your specific board and click Next. CY8CKIT-062S2-43012 in our case.
From the Machine Learning dropdown select SensiML Template Firmware and click on Create. We will use this template firmware to record audio data and transfer the data to SensiML Data Capture Lab using USB.
The template project will be added to your Project Explorer. Now you can modify, build, and upload the firmware to your specific PSoC board.
Connect the PSoC board to the PC using the USB cable provided with the Kit. First, build the firmware and then Program the board choosing KitProg3_MiniProg4.
If you face any issues with uploading the firmware you may need to upgrade the KitProg3 version. Go to the ModusToolbox/tools_2.4/fw-loader and run the fw-loader. Use the following command to upgrade the KitProg3 version.
./fw-loader --update-kp3 all
KitProg3 will be updated to the latest version.
Go to the ModusToolbox again and try to program the board. This time it should be programmed successfully.Sound Recognition Steps
In this step, we are going to build a model to detect water leaks that can run entirely on a microcontroller using the SensiML Analytics Toolkit. In this part, we will build a leakage recognition model step by step. The work involves 4 steps:
- Collect and annotate audio data
- Applying signal preprocessing
- Train a classification algorithm
- Create firmware optimized for the resource budget of an edge device
We will use the SensiML Analytics Toolkit to handle collecting and annotating sensor data, creating a sensor preprocessing pipeline, and generating the firmware. Before starting, we need to sign up for SensiML Community Edition to get access to the SensiML Analytics Toolkit. SensiML toolkit is a collection of several tools. We will use:
- SensiML Data Capture Lab (Windows 10) to record and label the sensor data.
- We will use the SensiML Analytics Studio for offline validation and code generation of the firmware
- (Optional) SensiML Open Gateway or Putty/Tera Term to view model results in real-time
Building real-world Edge AI applications require high-quality annotated data. The process can be expensive, time-consuming, and open-ended (how much data is enough?). Further, applying the correct annotations to time series data is complicated without a clear data collection protocol and tooling.
The SensiML Data Capture Lab makes it easy to collect, annotate and explore their time-series sensor data. We will use the Data Capture Lab to collect and annotate audio data in this project.
Step 1: Download and install the SensiML Data Capture Lab on your PC. Use the link https://sensiml.com/download/ to download DCL.
Step 2: Log in to your account and create a new project
Step 3: Click on Switch Modes and choose Capture mode
Step 4: From the bottom click on Connect
Step 5: Click Next and choose the right Device Plugin
Step 6: Click Next and to confirm click the Next button again
Step 7: Choose the Audio as Capture Source and click on Next
Step 8: Save the sensor configuration with a name
Your configuration is ready for the next stage.
Step 9: Plug the PSoC 6 board to your computer using USB cable and Click on Connect from the bottom.
Step 10: Click on Scan button. Connected COM port will be apear like below
Step 11: Click on done. The device will be successfully connected to your computer.
Step 12: Fill the text fild with an file name and then click on Start Recording. The recording will be started.
Step 13: After complete the recording click on Stop recording. A Save Confirmation window will apear. Click on Save to save the recorded audio.
Step 14: Go to the Project Explorer and open the newly captured file. You can add a Segment by right-clicking and dragging around the area of interest. Then you can apply a label by selecting clicking ctrl+e or clicking on the edit label button under the segment explorer. Once you have labeled the file, click Save.
Step 15: Right click on the opened file and add a session name.
Step 16: From the project properties create the necessary Segment Labels
Step 17: Add the segments in your captured file and Save.
For more instructions on the capabilities, see the Data Capture Lab documentation https://sensiml.com/documentation/data-capture-lab/index.htmlBuilding a Machine Learning Model
Now we are going to build a model to identify water leaks. To build the model we will use the SensiML Analytics Studio. Go to https://app.sensiml.com and sign in. Or directly go from the DCL File menu:
Once the project opens, you will see the overview screen. Here, you can see a high-level view of this project.
You will start building ML model by creating a Query. Due to time limitations, I am not going to show all the steps here. Go to the following link to view step by step process of building and training the model. https://sensiml.com/documentation/application-tutorials/guitar-tuning-notes-audio-recognition.html
My pipeline setting is as follows:
My AutoML model after optimization is as follows:
Confusion matrix of my model
Feature Summary of my Model
Model Validation and Testing
Next, go to the Test Model tab and select the file with metadata Test in Set. This file was excluded from our training data by the Query we created. Then click the Compute Accuracy button to see how the model performs on this capture.
The results of the test will be displayed below. This model performs reasonably well on our test data, and it is worth running it on live data to see how it performs on the device.
Before building the firmware, we can use the Data Capture Lab to see the results in real-time. In the Data Capture Lab, switch back to Capture mode and connect to your board for data streaming again. After that, click on Test Model in the upper right. Watch the video below.Testing Video
For more accuracy, I need to retrain the model. I also want to include the AWS cloud integration. I will build the firmware with the knowledge pack and the AWS cloud functionality but for time limitations I was unable to complete that task and show it here. In the future, I wish to complete that part and update my project.Downloading Model Firmware
For downloading the model for our PSoC 6 board, from the Analytics Studio, go to the Download Model tab and select the target development platform.
Click on Select Platform and finally click on Download.
Extract the downloaded file, and inside you will see a knowlegepack_project and sensiml folders.
We need to copy all of the files in senisml/lib and sensiml/inc over to the source/lib folder in your ModusToolbox template project.
The knowledgepack_project folder will contain the app_config.h for our project. We can copy it to the source folder of our ModusToolbox template project.
Now, we need to open the Eclipse IDE for ModusToolbox and in the terminal, we can run the following command to make and run the firmware:
make program TARGET=CY8CKIT-062S2-43012 TOOLCHAIN=GCC\_ARM
Before making we need to change the application running mode to recognition mode.
#define APPLICATION_RUNNING_MODE RECOGNITION_RUNNING_MODE
Path to Productization
As the testing phase has been completed the next step is to make it a product. As water leakage is a real problem this project has the potential to be a useful product. But for a commercial product several things are important like cost, security, how easy to use, how to power, form factor, outlook, and over the air update.
For reducing the cost I will design a custom PCB removing all the unnecessary components of the dev board. This will also help to reduce the product size. The device may be battery-powered or line power. But before determination of this, I have to explore it more.
I will bring the AWS Cloud connectivity and SNS service to the product. So, that users can get immediate notification on any water leakage. Security and OTA are also a big concern. I think using AWS will help to reduce the concern to a great extent.