I’m trying to build a custom baby monitor for my wife who is deaf. It needs to detect loud noises and listen for a specific series of tones from a feeding pump our daughter uses. It will then send a radio signal to the other room to trigger a bed shaker.
I do have a loop which samples the MAX4466 microphone and uses a “peakToPeak” calculation to determine volume, which I can use to trigger for loud noises (pasted below). However, I cannot figure out how to determine the frequency of a noise sample. I’ve tried searching for other sketches and tutorials that would work, but haven’t found anything. The feeding pump, when it has an error puts out a series of tones which alternates between 4.1 kHz and 2.1 kHz. What I wanted to do is see if the first tone is sounding, and then if the second tone shows up within a couple seconds afterwards, then it would trigger sending the signal to the other device.
I’ve tried for two days now to find a way to determine the frequency, but haven’t figured it out. Any help would be greatly appreciated. The closest I was able to get was this: Instructables - Arduino Frequency Detection, but when I use this script, the Arduino can no longer do analogRead()
to get the status of various setting knobs and such I have on the device.
The script I use to get the sound level / loudness is:
#define micPin 0 // Microphone
const int sampleWindow = 96; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
while (millis() - startMillis < sampleWindow) {
sample = analogRead(micPin);
// Check peakToPeak mins and maxs
if (sample < 1024) {
// toss out spurious readings
if (sample > signalMax) { signalMax = sample; } // save just the max levels
else if (sample < signalMin) { signalMin = sample; } // save just the min levels
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude