Arduino Piano Tuner Is Pitch Perfect

[JanHerman] knows that tuning musical instruments is all about precision and that precision is measured in a logarithmic unit called a cent. A cheap tuner unit might be accurate to 1.5 cents which sounds good until you look at one for ten times the price and find it is accurate to 0.1 cents. So you can spend $800 for precision or $60 for something less. [Jan] decided to build something better and cheaper using a 32-bit Arduino and a DDS frequency generator chip on a breakout board.

Oddly enough, the device doesn’t have a display. Instead, it generates a precise frequency and couples it to the piano using a transducer. You tune the string to the corresponding note. The post has a lot of detail about how piano tuning works.

If you know about the chromatic scale, the equal temperament system, and how many cents are in an octave, you might want to skip the first section. We didn’t though. If we learned any of that in childhood piano classes, we’ve forgotten it.

For those whose quest for precision isn’t that critical, note that the difference between two notes can be as little as 0.3316 Hz. It is interesting that the final design isn’t the first one [Jan] attempted and there is an explanation of why the first design wasn’t successful.

The final design calls for a 24-position rotary switch which is tough to find. We might have opted for a rotary encoder and a display or even some LEDs to make a cheap alternative. As it was, the cheap switch used caused problems and required a replacement and very careful soldering.

We’ve seen self-tuning pianos and the use of an oscilloscope for tuning, but those links are long dead. More recently, we’ve seen an old piano hacked for ragtime and if you decide you are giving up on piano lessons, you can always convert your instrument into a workbench.

16 thoughts on “Arduino Piano Tuner Is Pitch Perfect

  1. Nice hardware and software work.
    I’m quite a novice but I’ve tuned few pianos with a smartphone app and they seem to do fine for the mid-range scale, then you move up and down by ear only with the beat, as said high and low frequency must be avoided with such tools.

    Is there anything wrong with the smartphone FFT accuracy to need dedicated hardware?

    1. If the frequencies are right, no problem at all. No idea about the wave form coming your phone. From the helper device, Sine, Triangle and Square are coming out. My favorite was Sine. I wonder if the phone’s loudness is sufficient for grands…

  2. This would be fine if pianos were tuned to absolute pitch but this leads to a very sterile tone and a piano that seems out of tune. This is why human tuners adjust the pitch of notes by a few cents progessively depending on which ocatve they are tuning, not to mention having the skill to revoice to cope with felt compression on the hammers.

    1. Absolutely.
      Had a fascinating afternoon a month ago when my piano tuner explained – and demonstrated – how the inharmonicities of the piano (unique to each piano) affect how you have to tune it, and what happens if you ignore this and just tune it chromatically – each note sounds perfect, but chords are nasty.

      1. Should add – it’s not just the root pitch of the string, but also the harmonics which affect how you tune it. Tuning the root pitch correct laces the harmonics out, and so you have to adjust all the strings to compensate for this.

        All because I cheaped out and didn’t buy weightless zero-thickness strings in a vacuum.

          1. No, temperament has to do with the spacing of the notes within an octave, not with compensating for inharmonicity. Equal temperament makes all similar intervals sound, well, similar, which allows playing in any key without discordant harmony. Other temperaments make certain key signatures have some perfect intervals, at the cost of making others unlistenable.

      2. Jahn its tuner device has a feature, called Pianyzer, that can record and suggest a particular streching scheme. Of course, this is targeted at professionals, tuning many pianos. Page 18 of the manual ( shows a streching diagram, which might be illiustrative.
        Entropy ( is a software piano tuner, also capable of calculating the amount of strech for a piano. I’ve no experience with it, because up to present, I trusted my ears.. The main problem, when tuning once or twice a year, lies in finding the right temperament for al fifths in the middle region.

    2. Striking a string on a piano produces a tone consisting of several harmonics which are not in tune with their fundamentals. For example, the tone produced by a piano string for tone A4 can consist of a 440 Hz fundamental, with a second harmonic at 881 Hz and a fourth harmonic at 1768 Hz. If the partials had a harmonic proportion of frequencies to each other, the second harmonic would have a value of 880 Hertz and the fourth harmonic 1760 Hertz.
      This is known as the “Inharmonicity” of a piano string. It is caused by the stiffness of the string and can be different from instrument to instrument. This inharmonicity explains why, on a piano, the bass has to be tuned lower than the theoretical frequency and the descant higher. But how much depends in the instrument and personal preferences.
      That’s why my (1) my device is a ‘Helper’ and (2) why the advice is to follow the traditional tuning scheme, and play the control chords. The device helps in finding the right temperament, which is hard enough to master. Plus that the amount of strech is minimal in the region C4-C5.
      But of course, professional tuners will defend their profession. In reality, they all differ in how a piano is tuned. This is not a case of good/bad, but of taste. Ten years ago, I moved to a different city and hired another tuner. The first time, I didn’t like his tuning at all, it felt like a different instrument. But very soon the feeling was gone, I got used to it. So, tuning isn’t rocket science, start with the correct frequencies coming fom the helper, next follow your own prferences.

  3. Honestly, I was lost with respect to the tuning theory. What are intervals, semi-tones?

    For example, notes are equal intervals; intervals on what? Frequencies in engineering are frequently expressed on a log scale. Are the intervals equal frequency (always increasing by 5.4Hz, linear), or are they 1.033% greater than the next lower frequency (logarithmic), or something else? (These numbers were chosen at random. Consider the concept, not the numbers.)

    That said, the tuner itself is very simple. The AD9833 is a DDS sine wave generator that is programmed over SPI, and should be clocked by it’s own crystal for frequency stability. The output is amplified and applied to both a speaker and a transducer. Downstream of the AD9833 is pure analog. Simple!

    The Arduino used was likely considerable overkill, as was the 24-position switch. Replace the switch with an encoder (2 inputs to the Arduino). Note selection is controlled by the encoder, and indicated by lighting 1 of 24 LEDs, driven as a Charlieplexed array (6 output pins – see Wikipedia). Once a note is selected, use a look-up table to obtain the constants needed to set the AD9833 output frequency. That eliminates ALL the realtime math. The constants are communicated the the AD9833 using SPI. Done!

    P.S. Even 8-bit controllers can do double precision float math. It just takes a little time.

    1. @Brett, I’m not a music theory expert, but you’ve not yet had a reply, so here’s my attempt:

      Pick a note, say A4 (the A above middle C, called C4). In Western music, the convention is that A4 is 440Hz (concert pitch). Octaves since Greek times are double ratio, so A5=880Hz, A3=220Hz. Octaves define your interval. By convention in Western music, there are 12 semitones in an octave: A, A#, B, C, C#, D, D#, E, F, F#, G, G#. It doesn’t have to be that way, and in various other music cultures there are 17 tones in an octave, or 24 (called quartertones). Because octaves are defined by doubling, the natural way to define 12 equally spaced intervals (notes) is logarithmically. Hence you get as the multiplier 1.0595 (to four places) = 2^(1/12), or the 12th root of the double ratio. Let’s check: A4 is 440Hz, and if you multiply repeatedly by 1.0595, you get the frequency for the other 12 notes in the fourth octave. On your 13th step you get to A5=880Hz, the octave higher (try it, you should get 880.36792, because we’ve round up the multiplier in the fourth decimal). There’s probably a lot more to it than this, but in a paragraph, that would be my summary.

      For a historical look at tunings, and an explanation of why modern “equal temperament” tuning was not what Bach historically used for his famous “Well Tempered Clavier” piece, plus the intricacies of what makes music sound good, see this well-written online article, An Introduction to Historical Tunings, (1997) by Kyle Gann, music professor at Bard, Bucknell, and Columbia ( )

      1. Elaborating on “It doesn’t have to be that way…” In various other music cultures there are 17 tones in an octave (Persian/Arabic music), 5 tones (Indonesian), 24 tones (appropriately called quartertones), or even 53 tones (Turkish).

    2. One of the lessons learned is that a 12-position switch is possible too, with a few more octave tunings to do. What you write about LEDs etc, is correct, but personally I don’t like LEDs to look at, I experience them as optical point loads. The realtime math isn’t really a problem, software wise it’s very simple and enables also other A4 settings.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

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