Using UNO's built-in Analog Comparator for a real-time audio frequency meter (up to 20kHz)

Dear community,

I would like to showcase a neat use of Arduino UNO's built-in Analog Comparator (pin 6/7) to create a high-speed audio frequency meter.

Normally, an issue with UNO's built-in Analog Comparator is that it doesn't have threshold hysteresis (making it very sensitive to noise). However, I found a simple way to add feedback/hysteresis by connecting one of the digital outputs with a resistor to the comparator reference, to create the feedback/hysteresis "programmatically". Maybe this approach can be useful in other projects as well. I've not found this approach (using an UNO) mentioned anywhere before (I do know that some other boards have threshold hysteresis built-in).

Here is a schematic of how to hook things up:

The input audio signal should be centered on 2.5 V (for example using a decoupling circuit). Here is an example what the inputs to pin 6 (AIN0, Comparator +, yellow) and pin 7 (AIN1, Comparator -, pink) look like, showing a sound wave of 247Hz and detection threshold hysteresis:

Some neat examples of frequency signals obtained with the setup:

Playing open strings of my guitar:

Cheap dog whistle (still audible). Gentle blowing (~3200 Hz) versus firm blowing (creating a high-frequency overtone):

< see github for screenshot, I was allowed only 3 embedded media >

A fast tjirp sound (5ms per tjirp) created with a "sonar" app (headphone output directly connected to circuit):

< see github for screenshot, I was allowed only 3 embedded media >

Signal from a "tone generator" app (connected via headphone jack) showing the highest frequency of ~24 kHz that can be detected:

< see github for screenshot, I was allowed only 3 embedded media >

More information/examples and code can be found on my github page:

Hope this is useful for anyone, curious about your reaction!

2 Likes

Thanks for sharing!

Looks Great. Maybe I can see if I can tune stuff with it.

Nice :slight_smile: I must build something like that too :slight_smile:

My guitar tuner is not accurate and not convenient, maybe I can get better results this way :slight_smile: