Frequency detection using Trinket M0 and Adafruit 12S MEMS microphone

I want to use an Adafruit Trinket M0 and an Adafruit 12S MEMS microphone to detect a specific frequency range and output a signal to the gate of a power transistor to open when the frequency is detected.

Trinket Pinout:


My biggest issue is the coding. I understand I need some sort of Band Pass Filter but I am at a loss as far as how to even begin the code. Any help or guidance would be much appreciated.

Of it would be easier to use an analog microphone and a separate physical BPF, what hardware would you recommend?

You could build a bandpass filter using opamp(s) or a filter chip or a PLL discriminator and connect the output to an Arduino. Require external hardware.

Or use a FFT program to sense a specific frequency.

What frequency? Will you be able to achieve a proper sample rate?

I want to use an Adafruit Trinket M0 and an Adafruit 12S MEMS microphone

May I suggest that you change your Title to reflect the content of your project. For example "Frequency detection using Trinket M0 and Adafruit 12S MEMS microphone"

If you edit your Original Post you can change the Title.


...I've never used that particular hardware.

An external (analog) band pass filter won't work with the digital microphone so that will have to be done in software.

You'll need an I2S library and an FFT (or FHT or filter library). I don't know if there's an i2S library specifically for the microphone. If there is not a microphone/audio library it will be up to you to read at the "correct" sample rate and to make sure the data is read/structured as audio samples.

to detect a specific frequency range

That can be tricky (depending on the nature of the sound) because real world sounds contain multiple-simultaneous frequencies and amplitude variations and another dimension of complexity.

Just for "educational purposes" [u]Audacity[/u] will allow you to record sounds with your computer and then display the spectrum or spectrogram. If you can see what you're looking for on the spectrum there is a better chance if finding it with software.

If you are not familiar with how digital audio and sampllng works, the Audacity website has a little [u]digital audio tutorial[/u].

FFT & filtering are "advanced programming" topics but there are libraries so you don't have to write the "hard part" code yourself, but you do have to understand what they are doing.