Guitar Tuner Using Atmega32

Introduction: Motivation for Design
The Mechanix is a motorized guitar tuner for a standard 6-string electric or acoustic fixed bridge guitar.  Named in honor of Megadeth guitar legend Dave Mustaine, the Mechanix is a unique and innovative product which has numerous patent possibilities.  Traditional handheld guitar tuners are passive; they tell the user whether the guitar string is in tune, sharp, or flat, but the actual adjustment of the tension in the string has to be done by the user. This requires a fair amount of dexterity from the user, particularly when fine tuning is required. Thus, to increase both the convenience and the precision of the tuning process, we designed an active, motorized guitar tuner. The Mechanix responds to the user plucking one of the strings by turning the tuning knob until the string has reached its Standard Tuning note.

Guitar Tuner Using Atmega32

High Level Design
Rationale and sources of project idea
Passive guitar tuners have been commercially available for a long time and have also been implemented as ECE476 projects before, but none have incorporated a machine-controlled tuning process. The Mechanix is aimed at automating the guitar tuning process as much as possible, so as to make the process of tuning more precise and more convenient.

Background math
Standard Tuning, the most popular tuning on a 6-string guitar, is as follows:

String #


Frequency (Hz)

1 (Highest)















6 (Lowest)



Tuning the guitar involves adjusting the tension in each string until it vibrates at its Standard Tuning frequency.
Logical Structure
Our project can be divided into two main stages: signal processing and driving the motor.
Signal Processing
The signal from the plucked string, having a peak-to-peak amplitude on the order of tens of millivolts, first went through a preamplifier that scaled the amplitude up to the order of one volt. It was then put through a bandlimiting filter—a hardware low-pass filter with a cutoff of 400 Hz—before being sampled by the A/D converter on the microcontroller, so that the sampled signal would not be distorted by aliasing. The sampled signal was then filtered in software using Butterworth filters to suppress the higher harmonics of the vibrating string; the aim of this was to yield, as far as possible, a clean sine wave of the fundamental frequency of the plucked string. The frequency of this filtered signal was then calculated by the method of counting zero crossings—noting the time taken for the sine wave to rise through a threshold voltage 20 times, and dividing this time by 20 to get the period of the wave, and taking the reciprocal of the period to get the frequency. An LCD display shows the frequency of the vibrating string.
Driving the motor
To connect the rotating shaft of the motor to a tuning knob of the guitar, we needed a ‘claw’ fixed to the motor that would grasp the tuning knob. We had the claw made in the machine shop of the Department of Mechanical and Aerospace Engineering (special thanks to M&AE ’09 students Patxi Fernandez-Zelaia and Adeboye Ajayi for machining the part). We also estimated the torque required to turn the tuning knobs and, with some assistance and direction from Professor Francis Moon, we obtained a stepper motor from Rick Schmidt of the M&AE department that produced the torque required to turn the tuning knobs and met our design needs.
The motor was driven based on the frequency calculated in the Signal Processing stage. If the frequency calculated was within 1% of the Standard Tuning frequency of the string, the motor was halted. If the frequency calculated exceeded the Standard Tuning frequency by more than 1%, a signal was sent to the motor to rotate the tuning knob in the direction that would loosen the string. If the frequency calculated was below the Standard Tuning by more than 1%, a signal was sent to instruct the motor to rotate in the string-tightening direction. Because we used a stepper motor, we were able to control the turning of the tuning knobs with great precision (to the nearest 1.8o, which was the step size of the motor).
The motor took as inputs PWM signals that would have required a rather complicated implementation if done in software. We avoided this by using instead a motor driver chip, which interfaced between the microcontroller and the motor and which produced the required PWM signals to drive the motor based on simple logical signals (0 or 1) from the microcontroller. This made our motor-driving code clean and simple.
Relationship of our design to available IEEE, ISO, ANSI, DIN, and other standards
We programmed the microcontroller in ANSI C. We used the IEEE 32-bit floating point for the floating point calculations required in calculating frequencies and filter coefficients.
Program/Hardware Design: Signal Processing Implementation
We now aim to provide a cursory overview of the entire process of calculating the frequency of a plucked guitar string, and consequently elaborate each specific piece in copious detail.  The Signal Processing design uses both analog hardware as well as software methods to output a frequency for a plucked guitar string signal.
The line output from the guitar is weak and has a low current.  In order to be able to actually read this signal, we would need to use a BJT amplifier.  To circumvent this cumbersome task, we used an Audio Buddy Preamplifier I already had at home.  This gave this signal a boost and removed some noise as well.
The analog signal output from the preamp is of infinite bandwidth and contains a large amount of second and third harmonic.  It also has a random DC bias.  Before the signal can be send to the microcontroller ADC, it must be band-limited to remove aliasing.  The biasing circuit first uses a 1 uF capacitor to remove any DC bias the signal may have.  We then used a voltage divider to bias the signal at 2.5 V, the middle of the MCU conversion range.  We then passed it through a Salen Key 2nd order low pass Butterworth to band limit the signal to 400 Hz.
The output of Stage 2 is sent to the ADC0 input of the ATMEGA32 and a reference voltage of 5 V is used for sampling and quantization.  The sampling rate is 2 kHz, which satisfies the Nyquist requirements for sampling and recovery.  A constant value of 127 was subtracted from the converted value so that the input to the digital filter would be biased at zero and not at 2.5 V.
We used Bruce Land’s code for a second order filter and modified to accommodate for the added coefficients.  The filter function IIR2() will accommodate for the following transfer function:
Y[n] = b1*X{n] + b2*X[n-1] + b3*X[n-2] – a2*Y[n-1] –a3*Y[n-2]
The converted and zero biased fixed point signal was sent to the filter, which would remove the second harmonic of the guitar signal.  Each string had its own separate filter, which would have the first harmonic in the middle of its band to minimize attenuation.  The filters were able to reject second harmonic at about 8+ dB for the lowest string, with minimum passband attenuation.  Matlab’s fdatool() is used to show the magnitude response for the low E string filter.  For the lower three strings, we actually filter twice to create a fourth order filter.  For the higher strings, we have too much attenuation and simply use the function IIR2() once.  This rejection factor increases for higher strings, as the first and second harmonics are further apart.  Below we detail the fdatool() plot for the filters used for the lowest and highest strings.  The point indicated designates the rejection in dB for the second harmonic.
Guitar Tuner Using Atmega32 Schemetic
A for loop checks for signal zero crossings.  If two samples are below zero and the next two are above zero, a cycle has been detected.  After ten cycles, the time checked is divided by ten and modified to compute the signal frequency.  The value of frequency is somewhat unreliable due to transient behavior, so frequency calculations half a note below or above the desired first harmonic are not fed to the motor.  Even then, small oscillations will occur within range, but will eventually stabilize at the real frequency.  As long as there are more correct readings than incorrect, the guitar string will tune correctly.

Parts List:

Part Part number Quantity used Cost ($)      Source     
STK500 board STK500 1 15 Rented
Atmel mega32 mcu ATmega32 1 8 Rented
White board N/A 2 12 Rented
LCD LCD 1 8 Rented
DIP socket N/A 1 0.50 Rented
1-pin jumper cable N/A 10 5 Rented
Power supply N/A 2 5 Rented
Op-amp LM358 2 0 Rented
M-Audio Preamp Audio Buddy 1 0 Own
Motor LM061-FD02 1 0 Scavenged
Motor driver chip SLA7060M 1 0 Sampled
Claw N/A 1 0 Outsourced
Total Cost: $53.50
Balanced Budget Yes

For more detail: Guitar Tuner Using Atmega32

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

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

Scroll to Top