Measuring audio frequency with an Arduino

When I was working on the Morse Code Decoder project I got unexpected results from the output of of the KY-037 audio module. The output was being monitored by an interrupt in the Arduino Nano. It was triggering far more than I expected. I wondered if it was triggering at the frequency of the audio tone of the Morse code being received.

Rather than research it online I decided to have a go at investigating it myself. I wrote a simple sketch that counts the number of times the interrupt is triggered and at regular intervals does a simple calculation and displays the results as Hz. I’m sure this is all widely known, but it was enjoyable working it out for myself.

It’s a simple setup. Just a Nano on a breakout board and the Audio module

It is triggering once per wave of the tone it hears. While monitoring a steady tone I found it to be reasonable at displaying the frequency. I used this online tone generator for testing. Results were fairly consistent from below 100Hz up to 20kHz. I had to crank the volume up a bit and hold it close to the speaker for 20kHz, I presume because the speakers I have don’t work well at that frequency.

It had to be held close for 20kHz, but not as close for lower audible frequencies.

Here is a closeup of the audio module. It is a cheap one from ebay.

Audio module. The digital output was used.

I’ve uploaded the code for anyone interested to by GitHub repository https://github.com/garrysblog/Audio-Frequency-Measurement-Test

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s