Drain Clog Detector




Introduction: Drain Clog Detector

Don't let a clogged drain slow you down!
Coming back from our vacation, me and my wife were surprised by the water covering the floor of our apartment, and we found out it's not even clean water, it's drain everywhere. After clearing the drain and cleaning the floor, I had this question: why don't we have an alarm system for potential drain clogs? Clogged drains not only can bring your home to a halt, but will consume additional costs from your pockets, $206 on average is cost of clearing a clogged drain according to HomeAdvisor, in addition to hidden costs of damaged carpets, wooden furniture, ... etc. Our idea is to let home owners as well as enterprises like city/compounds maintenance departments and specialized service providers to have an efficient and intelligent system that alerts whoever in charge as early as possible to take action, which contributes in enriching smart cities with an important feature.

The Idea
Although detection of clogs can be done through a number of techniques, like using gas sensors or internal mechanisms, our team was focused on using sound as our input, as we know that knocking on a tube where it's opened is different sound from that happened when being closed. According to this simple concept, if we can train a model the sound patterns occurring on tube surface during clogs as well as those patterns occurs in opened pipes, we can then apply the model to detect proactively when a clog starts to compose, and we then ring some bills.

Credits for

Project in detail
3 phases are implemented in this project : Gathering data, Learning & prediction.

Before applying this system in real life, we needed to create an
enforced simulation environment, where we have the pipe, flowing water, and somehow to simulate the clog. So, we got a tube, a water hose with a water source doing this in the bath tub, and using the tub surface to close the tube which represents the clog. In this video, we explain how we built the environment and how we collected data for the model training.

And in this next video, showing how we did the testing for the system and the model, in open mode, then in clog mode and back to open mode, however

So, lets explore our implementation step by step:

Step 1: The Experiment

In this scenario we use a small water pipe connected to our hardware and sound sensor. Hardware reads the sensor value and send it back to Cloud. This has been done for 10 min for blocked tube then another 10 min for tube that isn't blocked.

Step 2: Hardware

I- Arduino

To detect the water sound inside the pipe we need a sound sensor. However Raspberry Pi 3 doesn't have Analog GPIO. To handle this issue we use Arduino as Arduino has analog GPIO. So we connect Grove Sound sensor to Grove Arduino shield and connect Shield to Arduino UNO 3. Then we connect Arduino & Raspberry using USB cable. To get more information about Grove Sound sensor, you can check its data sheet. You can find in data sheet a sample code how to read sensor values. Sample Code is almost use will small changes. In below code we connect sensor to A0 in shield. To write on serial, we use Serial.begin() function. To communicate with Raspberry baud rate set to 115200Data will be sent to Raspberry if it is bigger than certain threshold to cut the noise Many trials has been done to choose the desired threshold & delay values. Threshold found to be 400 & Delay value to be 10 millisecond. Threshold has been chosen to filter normal noise & ensure that only meaningful data will be sent to the cloud.Delay has been chosen in away to ensure that sensor has detect any changes in flow sound inside the tube immediately.

II- Raspberry Pi 3
To download android things on Raspberry, you can download the latest version from Android Things Console. In this project we use version : OIR1.170720.017. follow steps in Raspberry site to install operating system on raspberry, for windows you can use these steps After installation you can connect the Raspberry to your computer using USB. Then in your computer console use below command to get Raspberry IP

nmap -sn 192.168.1.*

After getting the IP, connect to your Raspberry using below command

adb connect

To connect your Raspberry to Wifi (add your SSID & password)

adb am startservice \

-n com.google.wifisetup/.WifiSetupService \

-a WifiSetupService.Connect \

-e ssid ***** \

-e passphrase ****

Step 3: Google Cloud - Registeration

Google offer a free tier for all users for one year with ceiling of 300$, Thanks to Google :).
Follow screens to create new project in Google Cloud

Step 4: Google Cloud - Pub/Sub

Google Cloud Pub/Sub is a fully-managed real-time messaging service that allows you to send and receive messages between independent applications.

Step 5: Google Cloud - IOT Core

II- IOT Core
A fully managed service to easily and securely connect, manage, and ingest data from globally dispersed devices. IOT Core still Beta, to have access on it you need to make a request with Justification to Google. We made the request, our justification was this contest. Google approved, Thanks to Google again :). Raspberry will send sensor data to IOT Core which will forward readings to PubSub topic created in previous step

Step 6: Google Cloud - Cloud Functions

Cloud Functions is a serverless environment to build and connect cloud services. Trigger for this function is the PubSup topic that created in step 1. ;; This function will be triggered when new value written in PubSup and write it in Cloud DataStore with Kind "SoundValue"

Step 7: Google Cloud - Cloud DataStore

Google Cloud Datastore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. While the Cloud Datastore interface has many of the same features as traditional databases, as a NoSQL database it differs from them in the way it describes relationships between data objects. No need for any setup as once the Cloud Functions write sensor values to DataStore, data will be added to DataStore

Step 8: Google Cloud - BigQuery

We gather a sample 10 min from normal pipe & 10 min from blocked pipe with difference exactly 1 hour between the 2 iterations. After downloading data DataStore and make some manipulation to add classification for each row. Now we have 2 csv files one for each category. As best practice upload data CSV files first to Cloud Storage. In below screen we create a new bucket & upload the 2 CSVs files As this bucket will be used for analysis only, no need to choose Multi-regional bucket Then create new Dataset & new table in BigQuery and upload the 2 CSVs file from bucket to the new table

Step 9: Google Cloud - Data Studio

Then we use Data Studio to draw some insights. Data Studio will read data from BigQuery table. From graphs we can see the difference between 2 categories in number of telemetries and sum of values per minute. Based on these insights we can design a simple model, pipe is considered blocked if in 3 successive minutes, count of telemetries values that are higher than noise threshold (400) is more than 350 telemetries. and in 3 successive minutes, count of telemetries value that is higher than spark threshold (720) is more than 10 telemetries.

Step 10: Prediction Phase

We refer to a reading, when it exceeds a certain value (THRESHOLD_VALUE) which was set to 350 that filters noise and lower water flow rates in the tube, from being considered as a reading

Data analysis shown that in open mode the number of readings is less
than 100, but in clog mode, values are far higher (reached 900 per minute), but in rare cases were also less than 100. However, these cases are not repeated consequently, and for three consequent minutes, total number of readings always exceeded 350. Having open mode in same three minutes will sum up less than a 300, we could confidently put this rule: Rule # 1 --> For three minutes in a raw, if total readings > 350 , then a clog is detected. We found maximum value reached in open mode doesn't exceed a certain value (SPARK_VALUE ) which is found to be 770, so we added this rule: Rule # 2 --> If reading value > 350 , then a clog is mostly detected.

Combining both rules, gave us an easy way to implement the detection
logic, as shown. Notice that below code was deployed on Arduino which then evaluates the received telemetries based on our model and send to raspberry if pipe is clogged or open.

Step 11: Code

All Code for Arduino, Raspberry & Cloud Function can be found on Github.

For more information you can check this link

Arduino Contest 2017

Participated in the
Arduino Contest 2017

Raspberry Pi Contest 2017

Participated in the
Raspberry Pi Contest 2017

Be the First to Share


    • Microcontroller Contest

      Microcontroller Contest
    • Automation Contest

      Automation Contest
    • Make it Glow Contest

      Make it Glow Contest



    Question 1 year ago

    Great project! Is sound frequency or sound loudness being used by the sensors here?


    Question 2 years ago on Step 11

    How can garbage in pipes going into rivers or canals be checked and gaibage prevented before going into rivers using IOT ?It would require alarming mechanism from the building from where pipes are coming out.What if there is an automated collection on the open sude of pipe?


    2 years ago

    Can you please help us, what sensor can we use to put outside the pipe so that it wont be damage, that can detect if there is a clog on that passageway, our focus on drainage system in city area. Thank you


    3 years ago

    Actually this is similar to my proposed thesis which is Water drainage clog detection with IOT, can you please help us, our professor suggested we use a hall effect sensor? to detect if there is no water flowing or there is water and a clog is detected and then the data is send to the cloud and location, very similar to yours hope you can help us, thank so much


    Reply 2 years ago

    I share with you my experience however I’m sure you and your team will make something awosm.
    Let’s imagine you have a building consists of 4 floors and each floor hasn’t one flat and only one connection from the main tube is exist
    Between every 2 flats you will need to put a sensor on the main tube, of sensor detect blocakage then the above flat will have a problem soon. So this will answer how many sensors you need

    Then where to add your sensor between the 2 flats, in the middle? What happen if the blockage happen above this sensor ? What if blockage under the sensor? As you know water Ian not move inside the tube continuesly. So you have many cases needed to be handle. For example if sensor detect no water is this mean no one use the water in floors above the sensor? Or it means there’s is a blockage above the sensor and unseen the above flat? Or there is a blockage above the sensor and above the nearest flat?
    Here I suggest to have synchronization/communication between all sensors in the building so if the above sensor detect water flow and lower sensor didn’t detect it then there’s an issue. Also I recommend to have something in top of building that flow water every 2 min for example and see all sensors in building can detect this water.

    Also based on where you will place sensor you need to calculate your alarm time. I meant if sensor is very near to the above flat. And it detect a blockage, maybe you have no time to give the alarm.

    Another question, where the sensor can be ? Can you put it inside the tube. I found this difficult. But if you can, it will be better. Imagine a robe that is pass inside the tube NDA sensors aren’t attached to this robe :)

    About the kind of sensor, I don’t need know what is the best but I used a voice sensor and I to gives us good results


    Reply 2 years ago

    I hope this will help:) and tell me what you did when you done :)


    3 years ago

    That would be really useful for the kitchen sink! :)


    Reply 3 years ago

    Ya. In fact the idea was for my wife as we returned home from a vacation to find kitchen full of water :(. So she told me I’ve to invent something :D