Maker Portal

View Original

Listening to Your Pipes with a MEMS Microphone and Raspberry Pi

See this content in the original post
See this content in the original post

See this content in the original post

The parts needed to follow along with this tutorial are a computer and USB water metering kit. Users can also use their own USB microphone or other audio capture device connected to their computer, however, the USB water metering kit is recommended for replicating the results found in this experiment. The explicit parts are given below:

  • Raspberry Pi 4 Computer - $52.99 (2GB), $61.88 (4GB), $88.50 (8GB) [Amazon], $55.00 [2GB from Our Store]

  • WaWiCo USB Water Metering Kit - $35.00 [Our Store]

See this product in the original post

When using the USB Water Metering Kit, the USB device is plugged into any Mac, Windows, Raspberry Pi, or other Linux-based computer. The flexible band houses the MEMS microphone which is to be connected to a standard 3/4 inch or 1 inch (inner-diameter) PVC or metal pipe along the water flow route. The MEMS microphone will be read by the USB adapter and used to characterize the piping system.

The flexible band should be fitted around the piping to be measured, whether it be near the household water inlet or closer to the water outlet at a sink or tap. For our study, we’ll be looking at the output from a sink (shown in the headline photo). We will also be connecting the USB adapter to a Raspberry Pi 4 computer:

In the next section, we will cover how to download the WaWiCo libraries that use Python as the analysis tool for characterizing the acoustic profile of the water flow and piping system.


See this content in the original post

Depending on the operating system being used, several installations are required before starting the analysis. The series of installs are also outlined in the WaWiCo GitHub repository for USB Water Metering:

The GitHub repository can be installed by cloning into the webpage:

See this content in the original post

The set of Python codes presented in the USB Water Metering repository require 'pyaudio' be installed on the computer being used. The install can be quite an involved process depending on the operating system (Mac, Linux, Windows). To install pyaudio, follow the procedures outlined at the project’s GitHub page relating to your specific OS. For this tutorial, the Raspberry Pi installation procedure is given:

Raspberry Pi OS ‘pyaudio’ Install:

In the terminal, first ensure that the Raspberry Pi has been updated and upgraded:

See this content in the original post

Next, install the pyaudio and portaudio libraries:

See this content in the original post

Finally, install the ‘matplotlib’ graphical toolbox to be used for visualizations:

See this content in the original post

Assuming the installs were successful, the Raspberry Pi should be rebooted. Now your Raspberry Pi (or other computer) should be ready to listen to your pipes!

As a test, the code entitled “realtime_freq.py” should be run in order to test the installations, Python library, and microphone. The test script is given below:

See this content in the original post

The script above will determine if a WaWiCo USB sound card is available and then samples the MEMS microphone at a rate of 44.1kHz in chunks of 4096 samples. Then, the program computes the Fast Fourier Transform (FFT) of the audio signal [learn more at: “The Fast Fourier Transform and Its Applications”]. The sample rate and chunk size outputs a frequency resolution of ≈10.8Hz. The goal of the test script is to determine the approximate range of frequencies outputted by the user’s piping system under various water flows.

Below is an example output of the script for a kitchen sink used in our tests:

In the next section, the actual frequency characterization of the piping will be explored in order to determine when water is flowing and when it is not.


See this content in the original post

The script above is meant to test the WaWiCo USB sound card adapter and the MEMS microphone. The approximate frequency response of the piping system should also be determined by turning the water faucet(s) on and off and investigating the frequency change. The next code entitled “flow_detection.py” takes the frequencies determined as flow frequencies and uses them to characterize flow periods, i.e. periods when water is flowing through the pipe.

The code is given below for reference:

See this content in the original post

The code above creates a local file entitled “WWC_ANA.dat” that cites the frequency amplitudes and time periods for given flow periods. The script is meant to run indefinitely when monitoring flow through the pipes.

The code above outputs the following to the command line or IDE window:

The above frequency bins are calculated using a Goertzel algorithm in place of the Fast Fourier Transform (FFT) [read about the Goertzel algorithm here]. This allow for more rapid quantification of energy in each frequency bin, at the expense of the full frequency spectrum. The Goertzel algorithm should only be used once the frequency bands are identified for the user’s pipe response. This will ensure that the values being logged are appropriately correlated to water flow.

If the frequency distribution of the water flow is still not clear, users can run the real-time spectrogram script (realtime_spectrogram.py) to view the time vs. frequency plot for the water flow periods. Below is an example of the time-based frequency response between no water flow and water flow periods:

Based on the spectrogram response, we could make statements about the frequency response of the water flow periods. It looks like most of our response is in the 3kHz - 7kHz region, as well as the 1.5kHz region, which was discussed above. The actual response may vary based on pipe diameter, pipe material, and water pressure. In the next entry to the water metering analysis, we will cover the significance of the frequency response and how to use the responses to actual determine water flow events.


See this content in the original post

In this tutorial, the WaWiCo USB Water Metering Kit was introduced along with methods for listening to water flow through pipes without the need for invasive plumbing work. A Python GitHub repository was given that contains the signal processing codes used to analyze the incoming acoustic information emitted by the local piping system encompassed in the flexible band containing the MEMS microphone. The experiments given here were meant as an introduction to water metering by first exploring the acoustics of water flow and pipes. By listening to our pipes, we can determine if water is flowing. In the future, more WaWiCo USB water metering codes will be explored which mark specific acoustic events that correlate with water flow periods. Additionally, further tutorials will relate acoustic responses of pipes to mechanical water flow rate sensors, resulting in a more advanced approach to water metering and comparison with accepted methods of determining water flow.

Visit WaWiCo to Learn More About Water Metering: https://wawico.com/

See More from WaWiCo and Raspberry Pi:

See this content in the original post