Pitch Detection on Arduino using Autocorrelation

This is the third part of the article about the Arduino Pitch Detector. It describes the IDE and tool chain used to compile the software.\(\)


The code has been compiled using the GNU C++ compiler in the Arduino AVR 1.6.11 tool chain. This tool chain comes included with the Arduino IDE 1.6.12.

I personally use the Visual Studio IDE together with the Arduino for Visual Studio plugin. Another option is the derived Atmel Studio that supports an In Circuit Emulator (ICE). However, the choice of IDE is irrelevant to the compilation. Some notes on the tool chain:

  • I strongly suggest to turning on all the compiler warnings (Arduino > File > Preferences > Compiler Warnings = all).
  • Older tool chains may not have C++11 support enabled giving rise to errors such as “'State' is not a class or namespace"). To fix, edit the file hardware/arduino/avr/platform.txt file and extend the variable compiler.cpp.flags to include -std=c+11 or -std=gnu+11.
  • Install the libraries Adafruit SD and Adafruit ST7735, by downloading and place them in the libraries folder to your Arduino tool chain, or in the libraries folder in your sketchbook path.
  • Reload the tool chain (Visual Studio (Tools > Visual Micro > Reload tool chains)
  • Select the correct board type
  • Clear the build, and rebuild
  • Upload to Arduino
  • If you’re curious and want to see mixed assembly and source code:
    • enable verbose messages when compiling (shows the location of the .elf file)
      compile with -g (hardware/arduino/avr/platform.txt)
    • avr-objdump -Shlw fname.elf >fname.S.cpp


With the tool chain in place, you can move ahead and download the sources through GitHub.

The next page explains the first step in the signal path: digitizing the analog signal from the microphone.

Student at MVHS
I see education as the foundation upon which entrepreneurs are able to build innovative organizations and execute their vision for the future.

4 Replies to “Pitch Detection on Arduino using Autocorrelation”

  1. Hello,

    I want to know the frequency of the power grid, but harmonic frequencies in the power grid are a huge problem.
    Can you send me a code for ‘filtering’ fundamental? (0-150Hz max)

  2. Hello,

    First of all, this a great work ! Not only just a sample stuff but very documented, you shoudl be proud !

    I’d like to use it for a guitare. Do you think it will work ? Did you test it ?

    Finally, did you make a video of it to see how good it works ? :)

    Thanks for the sharing and keep having fun making all these things :)

  3. Hello. Bravo for this work …
    I am a retired electronic engineer, and I designed a tuner working with FFT on a PC with a professional tool : Labview from National Instrument, which offers huge signal processing libraries. I wanted a very precise instrument to tune the reeds of a vintage italian accordion (Paolo Soprani, 1915). I am also playing bassoon, and then concerned with bass notes. I encountered many difficulties with low frequency cut off of the microphones, giving signals with harmonics far higher than fundamental (up to 20 dB). The lowest note of my accordion is a Bb at 58.27 Hz, on the left hand chords. This is also the lowest note of the basson. Precise measurement need very long sampling of several seconds !
    Well, now, I want to buid a little funny gadget which will animate a “snake” poping out of a basket in relation with the recognised notes … I am very interested by your work, but I think i will use a more powerfull processor than the Arduino uno, and then higher sampling frequency and 500 or 1000 samples.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.