Toilet Flushing Recognition

Hi, I am trying to build toilet flushing recognition system. I know it sounds stupid b/c I can just add sensor on the toilet to detect the toilet flush, but as it is my senior design, I cannot just use simple sensor to detect toilet flush...T__T (instructor won't let me)

General idea is to add MIC (w/ Band pass filter and amp-circuit: http://www.sparkfun.com/products/9964) and connect to one of the analog input of the Arduino and compare the input sound with stored value. Output(digital) will be connect to ISD1000A or speaker to alarm the user.

I was wondering how to store the reference toilet flushing sound in the Arduino and how to compare (bit by bit) them.

Even if the Arduino had enough memory to store a "reference sound" (which it doesn't), expecting to be able to compare two essentially random noise sounds and be able to pick up that they match is going to be a very difficult, if not impossible (note: depending on your experience in audio processing, artificial intelligence and pattern matching algorithms).

I'm not trying to dissuade you here - I am just hoping you understand how difficult a problem this really could be.

I think the way I would approach it would be to figure out how to do it on a PC first, using sound files - I'm thinking some kind of "eigen-filtering", or perhaps a bayesian approach for the matching algorithm (probably using FFT for spectral analysis of the sounds, and storing the peaks of those as your filter?). Perhaps you could get it simplified down enough so that your filter "reference" values (plus "best fit" window percentages?) could be fit into memory on the Arduino (or perhaps external storage), then the Arduino could (perhaps) do a real-time FFT and compare the values...?

Alright - tons of "ifs" there, but hopefully you see where and how my thoughts went; hopefully this doesn't prejudice you into thinking the above is the only way. That's just how I would start to approach things (and I am probably completely wrong with the above - but then again, I really don't know for sure).

:slight_smile:

There is not enough memory in the arduino to do this. You can only store a fraction of a second of sound.

Even if you could store the audio then a byte by byte comparison will not work. This is because the sampled waveform is never the same twice because you are not synchronising the sampling rate with the waveform. Therefore the waveform gets sampled at a different point every time and so the numbers turn out to be different every time.

You really ought to get an instructor who knows what he is doing. Ask for a different project. (or instructor)

T__T
How long that Arduino can capture the sound signal??
not even a second?

Thanks guys.

A typical sampling rate is 40 KHz or so. That is, 40000 samples per second, where a sample is typically at least 8 bits. So you would need 40K of RAM to hold one second. This is on a processor that has around 2K of RAM. So you are going to get around 1/20 of a second. That's for the recorded sample. And to hold a "comparison" sample would double your memory requirements. Which means you could only sample 1/40 of a second.

In any case, since they are both "noise" rather than a tune the whole thing is hopeless.

However what might work is a simpler approach of a Mic, suitable low-pass filtering tweaked to let through the "rumble" of the flush but exclude things like doors opening (or the seat being lifted). Then you simply need to do an analog read to see if the sound level exceeds a certain threshold.

So you might have one adjustment pot (the sound threshold) and another (the frequency) and with a bit of experimenting get a fairly good result, with a minimum of parts, and a simple program.

I cannot just use simple sensor to detect toilet flush

Is the simplest solution not allways the best?

OK, some ideas to make it really complex:

  • use a flow meter to count the liters/gallons - how much water is used - sustainability ==> extra points
  • add a temp sensor e.g. DS18B20 is a favorite here
  • add a gas sensor e.g. - Error, Electronic & Electronics Components Depot United States
  • add an alarm
  • add a weight sensor
  • add a RTC to time "the call of nature"
  • add an ethernetshield to twitter the status
  • add an LDR to check the light
  • add a relay to shut the light off
  • add a fan
  • add a out-of-paper detection (printers used to have a separate line for that :slight_smile:
  • ....

I think cr0sh has the right idea here. A Fast Fourier transform should work pretty accurately, and give you good marks as well. :wink:

I think I would do this:

  • Wait for a certain sound level to occur
  • Then pause about 1/2 to 1 second, to eliminate things like banging doors, coughs, hand-claps
  • If the sound persists, capture as much as you can (eg. 1000 samples)
  • Run a FFT analysis on the capture buffer, checking if various "signature" frequencies are there
  • Check that the sound stops after approximately the correct time (eg. toilet flush ... 5 seconds?)

If it passes those tests then you have it!

... or speaker to alarm the user. ...

Don't worry, they'll be alarmed alright.

robtillaart:
OK, some ideas to make it really complex:

...

And a public-address announcement:

Warning! Toilet has been flushed! Structural integrity failure in 10 seconds .. 9 .. 8 ..

Simple, I would mount/attach a simple float switch inside the water tank. Trying to use sound recongnition using a arduino is a brain dead idea and a waste of time IMHO. In the real world one searches for simple, elegent, cost effective solutions. I guess in your instructors course, not so?

Lefty

retrolefty:
Simple, I would mount/attach a simple float switch inside the water tank. Trying to use sound recongnition using a arduino is a brain dead idea and a waste of time IMHO. In the real world one searches for simple, elegent, cost effective solutions. I guess in your instructors course, not so?

Lefty

He's already stated that a simple sensor doesn't fill his instructor's requirements. I'm sure if the goal was only to detect when a toilet was flushed, a sensor on the tank or valve would be the appropriate method. I don't think that is necessarily the case.

Maybe the goal is to get the OP to think outside the box? Perhaps the goal is "can you think of a non-standard way to detect the presence of an event without using normal means"?

Which is where I was going in my solution; ie, could you get a small, low-speed, low-memory microcontroller to recognize a given sound?

Although not related - what about if you were trying to detect a gun shot? Or a bomb blast? Or a particular image piped in from a camera (maybe an extremely low-resolution camera - perhaps 32x32 pixels)?

Thinking outside the box might yield solutions to potentially hairy problems that need lower-power processors, where you can't (or don't want to) dedicate the equivalent of an entire PC (or cluster) to the problem. Perhaps that is what the goal of the project ultimately is - not necessarily limited to the domain of toilet flushing...?

:slight_smile:

A Fast Fourier transform should work pretty accurately,

Nick have you actually used a FFT and looked at the results, it is not as clean as the text books would have you believe. Then when you have got a spectrum extracting meaningful data out of it is anything but simple.

Glad you asked me that Mike, because I am attempting to do that right now. I'll let you know later on whether theory and practice can be made to merge at all practically. :slight_smile:

Thank you guys for all the help.

I was also thinking about the sound pitch detection. eg. setting the threshold and alarm the user.
However, I was concerning with all those noise inside the bathroom.
Is there any known frequency range for the noise? (such as door knocking, water, cough, voice, etc)
My MIC already has band pass filter (pass band 100Hz 10KHz)

Again, Thank you so much guys

So you might have one adjustment pot (the sound threshold) and another (the frequency) and with a bit of experimenting get a fairly good result, with a minimum of parts, and a simple program.

Hey Nick, thanks for the idea.
I know how to set up the sound threshold but how can I set up the frequency?

This may be interesting to all: Reconocimiento de voz con ATmega128 - Pruebas 02 - YouTube

Voice recognition on a wiring board.

There are links in the video info.

A microphone can work, I wouldn't drop that idea. The noise is strong it depends where you put the mic. Even a piezo should work as the flush should generate considerable vibrations. Flushing is also a time factos. So a simple cough should not trigger that (a long vomit :grin: might). You don't need an FFT in that case, simple filters could do the trick if needed.

Another option is a pressure sensor, flushing will surely change pressure in many points...

daguri87:
My MIC already has band pass filter (pass band 100Hz 10KHz)

as in the last post I already mentioned, length of a flush is long. You could use 3 band pass filters on various frequencies so you distinct between various noises (to me a flush sounds pretty much white noise, so you should have signals on all of them, other rumors might/should be pretty short and have distinct frequencies, ok, add a sign that says: don't sing). Use a moving average filter on a subsampled part of the output as they are very efficient (byte as resolution for the array should be more than enough). I also don't think you need a fast sampling rate, 1-2Khz could do the trick, maybe even lower.

I have a filter design suite on my website (choose 1st order filters, long calculations not float): http://www.schwietering.com/jayduino/filtuino/

I sort of started looking at this but then when on to something else

I did attach a piezo for a bit to my main line - and felt that I could get an indication when different water sources were on - I also got noise from walking across the wood floors but the profiles were different.

the following might also give you some ideas

http://www.google.com/search?q=Detecting+Human+Movement+by+Differential+AirPressure+Sensing+in+HVAC+System+Ductwork%3A+AnExploration+in+Infrastructure+Mediated+Sensing&rls=com.microsoft:en-us&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1

There are some really good electronics tutorials here:

Passive RC high pass filters

Passive RC high low filters

He explains, he demonstrates, he shows the theory and the calculations, and he has a cat!