Software apps and online services
Experts recommend that you wash your hands thoroughly to prevent infection. So I created a timer to measure the time it takes to wash your hands.
Here, the challenge is how to start counting the timer. Push switches are the easiest, but it is preferable not to touch them before hand washing. We could use infrared or ultrasonic sensors, but the need for external components makes it difficult to use them widely.
What makes this project unique is that the sound of running water is detected by a microphone to start a timer. The M5Stick-C used here has a built-in microphone, so you don't need any external components.
Therefore, anyone can realize a simple hand washing timer by simply programming the code into M5Stick-C.
There are many possible ways to detect only water sounds. Using the volume level above a certain value, for example, is an easy way to do this, but it is likely to cause many malfunctions.
Here, I decided to make use of the characteristic of water sounds having a unique frequency spectrum.
An overall block diagram is shown. The audio input from the microphone is converted to the frequency domain by FFT. The SVM (Support Vector Machine) is then used to score how close the input audio is to the sound of water. This score is in sample units for FFT. Next, accumulate this score. This is to detect that this feature has lasted more than a certain amount of time.
I used Jupyter Notebook to learn the SVM. For this purpose, I used the serial log of the Arduino with and without water sound. Detailed things are described later.
Since we are using the FFT library ArduinoFFT, install the library if they are not already installed in Arduino IDE.
Next, compile and program the two source files on github.
How the SVM model was created
Following 3 steps required.
- Record the sample data.
- SVM training by Jupyter Notebook
- Create SVM code according to trained data
First, to record sample data, add the following code to HandwashingTimer.ino.
With this change, the FFT results are logged via arduino serial port. And you can save the data to the file. The data were logged for a few seconds each time the water was running and when it was not. Refer source code in details.
Then, train SVM by Jupyter notebook. I uploaded the training script to the github site, /training/trainingSVM.py
Finally, the training results are stored to finalized_model.csv. I converted the data to WaterSoundDet.ino. Refer LIBSVM document for details due to the SVM function of Jupyter notebook is based on LIBSVM.