chapter 1 · the process was carried out in five steps. the very first step involved acquisition of...
TRANSCRIPT
CHAPTER 1
INTRODUCTION
Guitar is one of the most popular stringed instruments in the music industry
today. It consists of six strings, each tuned to a particular musical note. Musical notes
are basically sound waves of a certain frequency which are attained in guitar by
vibrations of these six strings and they differ with the tension in these strings. Hence
tuning the guitar strings to the preset values becomes a very important task for a
guitarist.
Tuning is generally done with the use of guitar tuners which display the
current note being played. A guitarist observes the tuner and changes the tension in
the strings with the help of a tuning key until the correct note is attained.
Figure 1.1: A typical guitar tuner and tuning key
The objective of the project is to make the instrument self-tuning, meaning
that the frequency of vibration of the string must be picked up by a guitar pickup to be
transformed from a signal to a mechanism for tensioning which will provide
tightening and loosening of the string to generate a different pitch.
To accomplish this task a simple feedback loop is required where the
tensioning mechanism is the actuator (servo motor), the sound produced by the
1
vibration of the string is the measured output and the user selected note to be played is
the set-point.
The self-tuning guitar will be extremely useful for the musician who wants to
effortlessly tune their guitar. All of the processing is done on the guitar, so there is no
external device that needs to be connected and attached to the guitar. The fiddling
with the tension in the strings is left to the guitar and more specifically the motors on
the guitar. People who regularly play guitar or who are just starting out will find this
system very beneficial to use just before playing.
2
CHAPTER 2
LITERATURE SURVEY
1. Thomas Johnsen et al (2008) proposed the design of a self-tuning guitar which
had the ability to detect the frequency at which an individual string was vibrating and
then adjusting the tension on the string until it vibrated at a predetermined desired
frequency. The string frequency was captured using the guitar’s standard output jack,
and then a microcontroller was attached to the back of the guitar which interpreted the
frequency and sent commands to a collection of stepper motors on the head in order to
adjust the string that is being played. The unit’s controls consisted of a six-position
switch which was used to select the string and a set of the LEDs that indicated the
tuning status.
The process was carried out in five steps. The very first step involved
acquisition of the sound signal from guitar pickups through the output jack on the
guitar. Next, the signal from the guitar was amplified with a DC bias of 2.5 V. After
amplification, the overtones were removed using a low pass filter in the third step and
the signal is then sent to the microprocessor in the fourth step.
Now, the output of the LPF was an analog signal. In order to do calculations
within the microprocessors the analog values needed to be converted to digital values.
In order to do this, the A/D Converter sampled the incoming data and recorded the
values in the A/D registers. A “zero” value of 2.5V was used in calculations so
attenuation in the signal could be ignored. In order to calculate the frequency, the time
elapsed in between the “zero” value points in the waveform were measured with the
uP timer.
The last step involved changing the tension in the string using stepper motors.
Reasons for the selection of stepper motors instead of servo was also explained as it
had the capability of being precisely controlled and they allowed more than one full
revolution in both forward and reverse directions.
2. The project 1 of SENG 466 (2013) consisting of Michael Sykes, Bruno Sampaio,
Radost Rychterawas was to design a self-tuning monochord guitar which detected a
3
few notes around middle C and tuned the string. The instrument was be self-tuning
such that the frequency of vibration of the string must be picked up by a sensor to
transform from a signal into a mechanism for tensioning which will provide
tightening and loosening of the string to generate a different pitch. To accomplish the
model, the mechanical design first had to be mounted, tensioned and then picked so as
to ensure proper coupling of the electrical system.
The electrical system design’s objective was to tune the guitar string to a set
note by filtering the fundamental frequency and adjusting the system accordingly.
This is achieved by implementing a feedback design to read the current frequency and
compensate for error. A motor, controlled by the microcontroller, adjusts the tension
to match the new set note. Replacement of the microphone was also explained as it
produced unexpected noise and therefore a magnetic coil was selected as a
replacement. The stepper motor was used to adjust the tension of the string to increase
or decrease the frequency of vibrations, and thus the fundamental note output. Some
of the special considerations like noise and interference, fine adjustments of the
system were explained
The frequency acquisition and its corresponding calculations were also
explained on the stepper motor to be used and it was displayed on the LCD screen.
The system also was built with a “user interface” which connects the user to the
instrument through and LCD screen and switches buttons to select note.
Recommendations regarding accuracy of mechanical parts, adding a high Q
band pass filter, using a multi turn potentiometer were also suggested.
3. Samir Rawani et al (2002) made a model of a self-tuning guitar. It was operated
by a computer chip, which read the frequency of a plucked string and sent the signal
of the desired frequency to six stepper motors, one on each string. Each motor was
fastened to a worm gear and as the motor spun, the nut slid up and down the worm
gear and tightening and loosening of the string took place.
The computer chip used was a Motorola MC68HC11 which read the
frequency output from the guitar’s pick-up, and in turn sent the information to the
4
motors, and kept reading at set intervals of time and relaying information to the
motors until the string has reached the desired tuning.
To power the device they used a rechargeable battery, similar to those used in
computer laptops, they claimed that it needed to be recharged every 15-20 tunings.
The feature which made their design special, and ultimately marketable, was
the ability to calibrate the guitar to alternate tunings, which are a must for any
experimental guitarist. The potential market of the model was also explained in detail.
4. The Automatic Guitar tuner project by an anonymous user on PBworks.com used
three prototypes based on which the actual model was made. First the frequency of
the signal was obtained through a series of filters. After its failure, Fast Fourier
Transforms were used to determine the frequency of the signal. After that failed, an
Auto Power Spectrum Analysis was done and a servo motor was added which proved
to be a success and it improved the accuracy of frequency calibration.
All the problems in the three stages were rectified and the final model was
designed upon. The frequency calculation was very accurate and reliable. When used
alone (without the servo) the frequency was obtained with each strum varying
somewhere between hundredths of a percent to at most half of a percent. There was
more feedback into the system with the presence of the servo and the sequence
structure which decreased the reliability of the frequency calculation, however the
system would self-correct itself since the vast majority of frequency calculations were
correct. Also to increase the speed of the system the number of samples was reduced
to 1/4 of the sampling rate. This decreased the precision of the frequency calculation,
since the values obtained now had to be multiplied by a factor of 4 and any slight
variations or errors also multiply by 4. Still in the end the device was able to work for
any string. There is a drop down menu for the string and the tuning and then upon the
user hitting go and plucking the motor will turn the peg until the guitar is "in tune".
5
CHAPTER 3
SYSTEM DESIGN
The design of the guitar is centered on the use of the Arduino Mega
microcontroller to handle the sensor and motors for tensioning application. The
following sections outline the mechanical and electrical designs for the project.
3.1 Mechanical Design
The mechanical design approach taken to develop the robotic instrument was
centered on ensuring coupling of the electrical systems. The guitar string required a
way to be mounted, tensioned and picked.
3.1.1 String Mounting
The single-string unit needed support and tension which was similar to a
traditional guitar for repeatability of the sound and feel of the string. Like most
components of this project, the string mounts went through numerous design
iterations until the design was perfected.
The initial design involved a plywood piece with wood pieces mounted
perpendicular to the surface. The wood pieces were installed with grooves at the top
to support the string and restrict motion side to side as the string was plucked. This
design was initially chosen as it was simple and quick to construct for testing. It was
soon found that the string made a very noisy signal when played with the wood
pieces. The sound had a notable “twang” and was difficult for the sensor to process as
there was a significant amount of noise. The observation was made that the string was
not sitting in the grooves exactly and was as a result vibrating between the wooden
walls increasing the noise in the signal and giving a poor guitar sound.
At this point, it was observed that the string mounts and guitar bridge were
found to support the string at a single point rather than other a certain length axially as
the previous design had. The new design consists of two nuts (placed near the
headstock on guitar) mounted on the wooden pieces and can be seen in Figure 3.1
6
below. The new design was found to give a much better sound than the original
design as well as a cleaner signal which was taken in by the sensor.
Figure 3.1: String Mounting
3.1.2 Tensioning System
An important criterion of the project was to have the system be self-tuning,
meaning that a mechanism was required to accept a value from the microcontroller
indicating which direction the tension is to be changed in. This was accomplished by
using a tuning peg directly from the guitar which takes a rotational input and
translates it to linear motion of the string as it wraps around the peg. The user tab of
the tuning peg was attached to the servo motor using a customized coupling as seen in
Figure 3.2. The coupling, which had to be customized, needed a strong but light
material. Hence, for this purpose polypropylene or PP was used.
7
Figure 3.2: Tensioning System
3.1.3 Servo Motor
A servomotor is a rotary actuator that allows for precise control of angular
position, velocity and acceleration. It consists of a suitable motor coupled to a sensor
for position feedback. It also requires a relatively sophisticated controller, often a
dedicated module designed specifically for use with servomotors.
Servomotors are not a different class of motor, on the basis of fundamental
operating principle, but use servomechanism to achieve closed loop control with a
generic open loop motor. In other words, a servomotor is just a regular motor with a
sensor installed, typically to measure angular position during operation. Hence, given
the precision that it offers, a servo motor becomes an obvious choice for our
application.
Servos are controlled by sending an electrical pulse of variable width, or pulse
width modulation (PWM), through the control wire. There is a minimum pulse, a
maximum pulse, and a repetition rate. Servomotors can usually only turn 90 degrees
in either direction for a total of 180 degree movement. The motor's neutral position is
defined as the position where the servo has the same amount of potential rotation in
the both the clockwise or counter-clockwise direction. The PWM sent to the motor
determines position of the shaft, and based on the duration of the pulse sent via the
control wire; the rotor will turn to the desired position.
8
Figure 3.3 on the next page shows the basic block diagram of a servo motor.
Figure 3.3: Servo Motor Block Diagram
One main disadvantage of a servo motor is that it does not offer continuous
rotation. In fact most of the servo motors available in the market restrict their
movement up to half rotation or 180 degrees. That is a major drawback for us,
although since the output of the servo motor is highly accurate it is given preference.
Hence, we use servo motor in our project to achieve fine tuning and it can be easily
used to account for detuning which occur due to changes in temperature, humidity and
the mere act of playing the guitar which drives it out of tune.
The servo motor we use is V0150 by Vega Robotics which offers a torque of 15
kg/cm at 4.8 to 6 V.
9
Figure 3.4: V0150 Servo Motor
3.2 Electrical Design
A guitar string is basic in construction but inherently complex in dynamics. Its
vibration produces frequencies that cover the entire spectrum and include a
fundamental plus all harmonics (overtones). The system design objective is to tune
the guitar string to a set note by filtering out the higher frequencies or overtones and
adjusting the system accordingly. This is achieved by implementing a third order low
pass Butterworth filter, which filters out the overtones, controlled by the
microcontroller, adjusts the tension to match the new set note and a user interface
creates a modular and portable system.
Figure 3.5 shows the frequency spectrum of the note E2, the note at which the sixth
string of the guitar is set. It can be clearly observed that the signal contains higher
frequency elements other than the standard known frequency which is 82.41 Hz.
10
Figure 3.5: Frequency Spectrum of guitar string tuned to E2 (82.41 Hz)
3.2.1 Sound Sensor
The sensor board initially contained an electret microphone; however, on
testing the microphone picked up an unexpected noise which produced a dirty signal
from the sensor module. The intrinsic property of the electret microphone is that it
picks up noise other than the vibrational string sounds. The noise factor limited the
usability of the microphone due to the complex software required to filter the signal
and therefore a magnetic coil was selected as a robust replacement.
Figure 3.6 displays a noisy waveform at the 329.63 Hz input frequency. The
noise was consistent for every new signal and persisted almost throughout the entire
waveform. However, replacing the microphone with the guitar pickup coil produced a
very clean square wave signal at the fundamental frequency expected. Hence, a guitar
pickup seemed like a perfect replacement for the system.
11
Figure 3.6: Noisy output from microphone
3.2.1.1 Guitar Pickup
A guitar pickup basically consists of a magnet with a wire wrapped around it,
a coil. When a piece of metal, such as the guitar string right above it, moves, it
changes the magnetic flux of the magnet, and this induces a voltage in the coiled wire
around the magnet. The induced voltage will oscillate exactly in the same way as the
string above it oscillates mechanically - for this reason the pickup translates the
mechanical oscillation, the sound, into a voltage oscillation - which is easier to
transmit through wires.
Figure 3.7: Guitar pickups
The sensitivity of a pickup is mainly described by the number of coil windings
around the magnet, the strength of the magnet and the distance to the guitar string.
Usually a compromise between these parameters must be found. High magnetic fields
caused by more powerful magnets, or by placing the magnet closer to the guitar
12
string, dampen the guitar string's oscillation - the pickup starts acting as an
electromagnetic brake. A high number of coil windings will make the pickup too
sensitive, so that any other disturbing fields get captured by the pickup, also, the
increased voltage could lead to a distorted sound.
Figure 3.8: Working of a guitar pickup
The entire guitar pickup, that visible thing under the guitar strings, is actually
a casing containing an array of magnetic poles - usually one per string - which are
connected to a master magnet that has the coil wrapped around it. Sometimes the
individual poles are visible as little circular bumps under each guitar string.
3.2.1.2 The Pickup As Circuit
From an electrical standpoint, a magnetic guitar pickup is equivalent to the
circuit in Fig. 3.9.
A real coil can be described electrically as an ideal inductance L in series with an
ohmic resistance R, and parallel to both a winding capacitance C. It is a bit simplified
compared to the reality but it gives a basic idea to start with. For a humbucker, two of
these circuits have to be connected in series. Since both coils (with precise
manufacturing) have practically identical properties, you may use the same simple
replacement circuit for the electrical examination. You then have to use twice the
values for the inductance and the resistance and half of the value for the capacitance
as compared to one coil.
13
Figure 3.9: Electrical Scheme of a Guitar Pickup
Many people measure only the resistance and think they know something about a
pickup. But this is a fundamental error. By far the most important quantity is the
inductance, measured in Henries. It depends on the number of turns, the magnetic
material in the coil, the winding density and the overall geometry of the coil. The
resistance and the capacitance don’t have much influence and can be neglected in a
first approximation. When the strings are moving, an AC voltage is induced in the
coil. So the pickup acts like an AC source with some attached electric components.
The output from a pickup is much cleaner than what we obtained when using a
microphone. Figure 3.10 shows the signal obtained from a pickup.
14
Figure 3.10: Clean output obtained from pickup
3.2.2 Low Pass Filter
As stated earlier, the vibration of a guitar string produces frequencies that
cover the entire spectrum and include a fundamental plus all harmonics (overtones).
Thus for computation of the fundamental frequency, all the upper harmonics are to be
eliminated. This is easily done with the help of a low pass filter.
A simple passive RC Low Pass Filter, or LPF, can be easily made by
connecting together in series a single resistor with a single capacitor as shown below.
In this type of filter arrangement the input signal is applied to the series combination
(both the Resistor and Capacitor together) but the output signal is taken across the
capacitor only. This type of filter is known generally as a “first-order filter” or
“one-pole filter”, because it has only “one” reactive component, the capacitor, in the
circuit.
But the main disadvantage of Passive Filters is that the amplitude of the output
signal is less than that of the input signal, ie, the gain is never greater than unity and
that the load impedance affects the filters characteristics. With passive filter circuits
containing multiple stages, this loss in signal amplitude called “Attenuation” can
become quiet severe.
Figure 3.11: First Order RC Low Pass Filter
One way of restoring or controlling this loss of signal is by using amplification
through the use of Active Filters. As their name implies, Active Filters contain active
components such as operational amplifiers, transistors or FET’s within their circuit
15
design. They draw their power from an external power source and use it to boost or
amplify the output signal.
Figure 3.12: Low Pass Active Filter with Amplification
The frequency response of the circuit will be the same as that for the passive
RC filter, except that the amplitude of the output is increased by the pass band gain,
AF of the amplifier. For a non-inverting amplifier circuit, the magnitude of the
voltage gain for the filter is given as a function of the feedback resistor divided by its
corresponding input resistor value and is given as:
Now, an ideal filter would give us specifications of maximum pass band gain and
flatness, minimum stop band attenuation and also a very steep pass band to stop band
roll-off (the transition band) and it is therefore apparent that a large number of
network responses would satisfy these requirements.
Not surprisingly then that there are a number of “approximation functions” in
linear analogue filter design that use a mathematical approach to best approximate the
transfer function required for the filters design. One such filter, which is perfectly
suited for this application is Butterworth Filter.
16
The frequency response of the Butterworth Filter approximation function is
also often referred to as “maximally flat” (no ripples) response because the pass band
is designed to have a frequency response which is as flat as mathematically possible
from 0Hz (DC) until the cut-off frequency at -3dB with no ripples. Higher frequencies
beyond the cut-off point rolls-off down to zero in the stop band at 20dB/decade or
6dB/octave. This is because it has a “quality factor”, “Q” of just 0.707.
Note that the higher the Butterworth filter order, the higher the number of
cascaded stages there are within the filter design and the closer the filter becomes to
the ideal “brick wall” response.
Figure 3.13: Frequency Response Curve of a Butterworth filter
For our project a third order filter seemed sufficient as the filter eliminated all
the upper harmonics above second overtone. Even the magnitude of the second
overtone was reduced to almost one-fifth of the input magnitude. By providing
sufficient pass band gain in the circuit, the effect of second overtone in the signal can
be neglected.
The third order Butterworth low pass filter was designed by cascading an
active second order filter and passive first order RC filter. The circuit was initially
17
designed and simulated on National Instruments Multisim 13.0 (Figure 3.14) and
tested with a signal generator and CRO later before testing it with the actual signal.
Figure 3.14: Simulation of Low Pass Filter on Multisim 13.0
3.2.3 Frequency to Voltage converter
To avoid the unnecessary complexities in programming the microcontroller, a
suitable method needed to be found out to reduce the coding redundancies in our
program. One way to do that was to compute the frequency of the input signal outside
of microprocessor. In order to that, the frequency must be represented to the
microprocessor in analog form, possibly as DC voltage. Hence, usage of a frequency
to voltage converter seemed an obvious choice.
A frequency to voltage converter is a circuit which maps the frequencies of
input signal to corresponding outputs. Texas Instruments manufacture an IC, called
LM2917, which is a Frequency to Voltage converter IC.
The LM2907, LM2917 series are monolithic frequency to voltage converters
with a high gain op amp/comparator designed to operate a relay, lamp, or other load
when the input frequency reaches or exceeds a selected rate. The tachometer uses a
charge pump technique and offers frequency doubling for low ripple, full input
protection in two versions (LM2907-8, LM2917-8) and its output swings to ground
for a zero frequency input.
18
The op amp/comparator is fully compatible with the tachometer and has a
floating transistor as its output. This feature allows either a ground or supply referred
load of up to 50 mA. The collector may be taken above VCC up to a maximum VCE
of 28V.
The two basic configurations offered include an 8-pin device with a ground
referenced tachometer input and an internal connection between the tachometer
output and the op amp non-inverting input. This version is well suited for single speed
or frequency switching or fully buffered frequency to voltage conversion applications.
The more versatile configurations provide differential tachometer input and
uncommitted op amp inputs. With this version the tachometer input may be floated
and the op amp becomes suitable for active filter conditioning of the tachometer
output.
Both of these configurations are available with an active shunt regulator
connected across the power leads. The regulator clamps the supply such that stable
frequency to voltage and frequency to current operations are possible with any supply
voltage and a suitable resistor.
Figure 3.15: Test Circuit of LM2917
19
The LM2907 series of tachometer circuits is designed for minimum external
part count applications and maximum versatility. In order to fully exploit its features
and advantages let's examine its theory of operation. The first stage of operation is a
differential amplifier driving a positive feedback flip-flop circuit. The input threshold
voltage is the amount of differential input voltage at which the output of this stage
changes state. Two options (LM2907-8, LM2917-8) have one input internally
grounded so that an input signal must swing above and below ground and exceed the
input thresholds to produce an output. This is offered specifically for magnetic
variable reluctance pickups which typically provide a single-ended ac output.
Following the input stage is the charge pump where the input frequency is
converted to a dc voltage. To do this requires one timing capacitor, one output
resistor, and an integrating or filter capacitor. The output circuit mirrors this current
very accurately into the load resistor R1, connected to ground, such that if the pulses
of current are integrated with a filter capacitor, then VO = ic × R1, and the total
conversion equation becomes:
VO = VCC × fIN × C1 × R1 × K, where K is the gain constant—typically 1.0
There are some limitations on the choice of R1 and C1 which should be considered
for optimum performance. The timing capacitor also provides internal compensation
for the charge pump and should be kept larger than 500 pF for very accurate
operation. Smaller values can cause an error current on R1, especially at low
temperatures. Several considerations must be met when choosing R1. The output
current at pin 3 is internally fixed and therefore VO/R1 must be less than or equal to
this value. If R1 is too large, it can become a significant fraction of the output
impedance at pin 3 which degrades linearity. Also output ripple voltage must be
considered and the size of C2 is affected by R1.
Hence after effectively choosing C1 and R1, the final circuit diagram of the
frequency to voltage converter was made and is shown in Figure 3.16 on the next
page.
20
Figure 3.16: Zener Regulated Frequency to Voltage Converter
3.3 Software Design – Arduino Mega 2560
3.3.1 Introduction
Arduino is a single-board microcontroller, intended to make the application of
interactive objects or environments more accessible. The hardware consists of an
open-source hardware board designed around an 8-bit Atmel AVR microcontroller, or
a 32-bit Atmel ARM. Current models feature an USB interface, 6 analog input pins,
as well as 14 digital I/O pins which allow us to attach various extension boards.
Introduced in 2005, it was designed to give students an inexpensive and easy way to
program interactive objects. It comes with a simple integrated development
environment (IDE) that runs on regular personal computers and allows us to write
programs for Arduino using C or C++.
1) Hardware: An Arduino board consists of an Atmel 8-bit AVR microcontroller with
complementary components to facilitate programming and incorporation into other
circuits. An important aspect of the Arduino is the standard way that connectors are
exposed, allowing the CPU board to be connected to a variety of interchangeable
21
add-on modules known as shields. Some shields communicate with the Arduino board
directly over various pins, but many shields are individually addressable via an I²C
serial bus, allowing many shields to be stacked and used in parallel. Official Arduinos
have used the megaAVR series of chips, specifically the ATmega8, ATmega168,
ATmega328, ATmega1280, and ATmega2560. A handful of other processors have
been used by Arduino compatibles. Most boards include a 5 volt linear regulator and a
16 MHz crystal oscillator (or ceramic resonator in some variants), although some
designs such as the LilyPad run at 8 MHz and dispense with the onboard voltage
regulator due to specific form-factor restrictions. An Arduino's microcontroller is also
pre-programmed with a boot loader that simplifies uploading of programs to the
on-chip flash memory, compared with other devices that typically need an external
programmer. This makes using an Arduino more straightforward by allowing the use
of an ordinary computer as the programmer.
At a conceptual level, when using the Arduino software stack, all boards are
programmed over an RS-232 serial connection, but the way this is implemented varies
by hardware version. Serial Arduino boards contain a level shifter circuit to convert
between RS-232-level and TTL-level signals. Current Arduino boards are
programmed via USB, implemented using USB-to-serial adapter chips such as the
FTDI FT232. Some variants, such as the Arduino Mini and the unofficial Boarduino,
use a detachable USB-to-serial adapter board or cable, Bluetooth or other methods.
(When used with traditional microcontroller tools instead of the Arduino IDE,
standard AVR ISP programming is used.)
The Arduino board exposes most of the microcontroller's I/O pins for use by
other circuits. The Diecimila, Duemilanove, and current Uno provide 14 digital I/O
pins, six of which can produce pulse-width modulated signals, and six analog inputs.
These pins are on the top of the board, via female 0.10-inch (2.5 mm) headers.
Several plug-in application shields are also commercially available.
The Arduino Nano, and Arduino-compatible Bare Bones Board and Boarduino
boards may provide male header pins on the underside of the board to be plugged into
solderless breadboards.
22
There are many Arduino-compatible and Arduino-derived boards. Some are
functionally equivalent to an Arduino and may be used interchangeably. Many are the
basic Arduino with the addition of commonplace output drivers, often for use in
school-level education to simplify the construction of buggies and small robots.
Others are electrically equivalent but change the form factor, sometimes permitting
the continued use of Shields, sometimes not. Some variants use completely different
processors, with varying levels of compatibility.
2) Software: The Arduino integrated development environment (IDE) is a
cross-platform application written in Java, and is derived from the IDE for the
Processing programming language and the Wiring projects. It is designed to introduce
programming to artists and other newcomers unfamiliar with software development. It
includes a code editor with features such as syntax highlighting, brace matching, and
automatic indentation, and is also capable of compiling and uploading programs to the
board with a single click. A program or code written for Arduino is called a "sketch".
Figure 3.17: Arduino IDE
Arduino programs are written in C or C++. The Arduino IDE comes with a software
library called "Wiring" from the original Wiring project, which makes many common
input/output operations much easier.
23
3.3.2 Arduino Mega 2560
The Arduino Mega 2560 is a microcontroller board based on the ATmega2560
(datasheet). It has 54 digital input/output pins (of which 15 can be used as PWM
outputs), 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal
oscillator, a USB connection, a power jack, an ICSP header, and a reset button. It
contains everything needed to support the microcontroller; simply connect it to a
computer with a USB cable or power it with a AC-to-DC adapter or battery to get
started. The Mega is compatible with most shields designed for the Arduino
Duemilanove or Diecimila.
Figure 3.18: Arduino Mega 2560
The Mega 2560 is an update to the Arduino Mega, which it replaces. The
Mega2560 differs from all preceding boards in that it does not use the FTDI
USB-to-serial driver chip. Instead, it features the ATmega16U2 (ATmega8U2 in the
revision 1 and revision 2 boards) programmed as a USB-to-serial converter.
Revision 2 of the Mega2560 board has a resistor pulling the 8U2 HWB line to
ground, making it easier to put into DFU mode. Revision 3 of the board has the
following new features:
24
● pinout: added SDA and SCL pins that are near to the AREF pin and two other
new pins placed near to the RESET pin, the IOREF that allow the shields to
adapt to the voltage provided from the board. In future, shields will be
compatible both with the board that use the AVR, which operate with 5V and
with the Arduino Due that operate with 3.3V. The second one is a not
connected pin, that is reserved for future purposes.
● Stronger RESET circuit.
● Atmega 16U2 replace the 8U2.
3.3.2.1 Summary
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 54 (of which 15 provide PWM output)
Analog Input Pins 16
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 256 KB of which 8 KB used by bootloader
SRAM 8 KB
EEPROM 4 KB
Clock Speed 16 MHz
3.3.2.2 Power
The Arduino Mega can be powered via the USB connection or with an
external power supply. The power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter
(wall-wart) or battery. The adapter can be connected by plugging a 2.1mm
center-positive plug into the board's power jack. Leads from a battery can be inserted
in the Gnd and Vin pin headers of the POWER connector.
25
The board can operate on an external supply of 6 to 20 volts. If supplied with
less than 7V, however, the 5V pin may supply less than five volts and the board may
be unstable. If using more than 12V, the voltage regulator may overheat and damage
the board. The recommended range is 7 to 12 volts.
The power pins are as follows:
● VIN. The input voltage to the Arduino board when it's using an external power
source (as opposed to 5 volts from the USB connection or other regulated
power source). You can supply voltage through this pin, or, if supplying
voltage via the power jack, access it through this pin.
● 5V. This pin outputs a regulated 5V from the regulator on the board. The
board can be supplied with power either from the DC power jack (7 - 12V),
the USB connector (5V), or the VIN pin of the board (7-12V). Supplying
voltage via the 5V or 3.3V pins bypasses the regulator, and can damage your
board. We don't advise it.
● 3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current
draw is 50 mA.
● GND. Ground pins.
● IOREF. This pin on the Arduino board provides the voltage reference with
which the microcontroller operates. A properly configured shield can read the
IOREF pin voltage and select the appropriate power source or enable voltage
translators on the outputs for working with the 5V or 3.3V.
3.3.2.3 Memory
The ATmega2560 has 256 KB of flash memory for storing code (of which 8
KB is used for the bootloader), 8 KB of SRAM and 4 KB of EEPROM (which can be
read and written with the EEPROM library).
3.3.2.4 Input and Output
Each of the 54 digital pins on the Mega can be used as an input or output, using
pinMode(), digitalWrite(), and digitalRead() functions. They operate at 5 volts. Each
pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor
26
(disconnected by default) of 20-50 kOhms. In addition, some pins have specialized
functions:
● Serial: 0 (RX) and 1 (TX); Serial 1: 19 (RX) and 18 (TX); Serial 2: 17 (RX)
and 16 (TX); Serial 3: 15 (RX) and 14 (TX). Used to receive (RX) and
transmit (TX) TTL serial data. Pins 0 and 1 are also connected to the
corresponding pins of the ATmega16U2 USB-to-TTL Serial chip.
● External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19
(interrupt 4), 20 (interrupt 3), and 21 (interrupt 2). These pins can be
configured to trigger an interrupt on a low value, a rising or falling edge, or a
change in value. See the attachInterrupt() function for details.
● PWM: 2 to 13 and 44 to 46. Provide 8-bit PWM output with the analogWrite()
function.
● SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). These pins support SPI
communication using the SPI library. The SPI pins are also broken out on the
ICSP header, which is physically compatible with the Uno, Duemilanove and
Diecimila.
● LED: 13. There is a built-in LED connected to digital pin 13. When the pin is
HIGH value, the LED is on, when the pin is LOW, it's off.
● TWI: 20 (SDA) and 21 (SCL). Support TWI communication using the Wire
library. Note that these pins are not in the same location as the TWI pins on
the Duemilanove or Diecimila.
The Mega2560 has 16 analog inputs, each of which provide 10 bits of resolution
(i.e. 1024 different values). By default they measure from ground to 5 volts, though is
it possible to change the upper end of their range using the AREF pin and
analogReference() function.
There are a couple of other pins on the board:
● AREF. Reference voltage for the analog inputs. Used with analogReference().
● Reset. Bring this line LOW to reset the microcontroller. Typically used to add
a reset button to shields which block the one on the board.
3.3.2.5 Communication
27
The Arduino Mega2560 has a number of facilities for communicating with a
computer, another Arduino, or other microcontrollers. The ATmega2560 provides
four hardware UARTs for TTL (5V) serial communication. An ATmega16U2
(ATmega 8U2 on the revision 1 and revision 2 boards) on the board channels one of
these over USB and provides a virtual com port to software on the computer
(Windows machines will need a .inf file, but OSX and Linux machines will recognize
the board as a COM port automatically. The Arduino software includes a serial
monitor which allows simple textual data to be sent to and from the board. The RX
and TX LEDs on the board will flash when data is being transmitted via the
ATmega8U2/ATmega16U2 chip and USB connection to the computer (but not for
serial communication on pins 0 and 1).
A SoftwareSerial library allows for serial communication on any of the
Mega2560's digital pins.
The ATmega2560 also supports TWI and SPI communication. The Arduino software
includes a Wire library to simplify use of the TWI bus; see the documentation for
details. For SPI communication, use the SPI library.
3.3.2.6 Programming
The Arduino Mega can be programmed with the Arduino software. The
ATmega2560 on the Arduino Mega comes preburned with a bootloader that allows
you to upload new code to it without the use of an external hardware programmer. It
communicates using the original STK500 protocol (reference, C header files).
You can also bypass the bootloader and program the microcontroller through
the ICSP (In-Circuit Serial Programming) header; see these instructions for details.
The ATmega16U2 (or 8U2 in the rev1 and rev2 boards) firmware source code is
available in the Arduino repository. The ATmega16U2/8U2 is loaded with a DFU
bootloader, which can be activated by:
● On Rev1 boards: connecting the solder jumper on the back of the board (near
the map of Italy) and then resetting the 8U2.
● On Rev2 or later boards: there is a resistor that pulling the 8U2/16U2 HWB
line to ground, making it easier to put into DFU mode. You can then use
28
Atmel's FLIP software (Windows) or the DFU programmer (Mac OS X and
Linux) to load a new firmware. Or you can use the ISP header with an external
programmer (overwriting the DFU bootloader). See this user-contributed
tutorial for more information.
3.3.2.7 Automatic (Software) Reset
Rather than requiring a physical press of the reset button before an upload, the
Arduino Mega2560 is designed in a way that allows it to be reset by software running
on a connected computer. One of the hardware flow control lines (DTR) of the
ATmega8U2 is connected to the reset line of the ATmega2560 via a 100 nanofarad
capacitor. When this line is asserted (taken low), the reset line drops long enough to
reset the chip. The Arduino software uses this capability to allow you to upload code
by simply pressing the upload button in the Arduino environment. This means that the
bootloader can have a shorter timeout, as the lowering of DTR can be
well-coordinated with the start of the upload.
This setup has other implications. When the Mega2560 is connected to either a
computer running Mac OS X or Linux, it resets each time a connection is made to it
from software (via USB). For the following half-second or so, the bootloader is
running on the Mega2560. While it is programmed to ignore malformed data (i.e.
anything besides an upload of new code), it will intercept the first few bytes of data
sent to the board after a connection is opened. If a sketch running on the board
receives one-time configuration or other data when it first starts, make sure that the
software with which it communicates waits a second after opening the connection and
before sending this data.
The Mega2560 contains a trace that can be cut to disable the auto-reset. The
pads on either side of the trace can be soldered together to re-enable it. It's labeled
"RESET-EN". You may also be able to disable the auto-reset by connecting a 110
ohm resistor from 5V to the reset line; see this forum thread for details.
3.3.2.8 USB Overcurrent Protection
The Arduino Mega2560 has a resettable polyfuse that protects your computer's
USB ports from shorts and overcurrent. Although most computers provide their own
29
internal protection, the fuse provides an extra layer of protection. If more than 500
mA is applied to the USB port, the fuse will automatically break the connection until
the short or overload is removed.
3.3.2.9 Physical Characteristics and Shield Compatibility
The maximum length and width of the Mega2560 PCB are 4 and 2.1 inches
respectively, with the USB connector and power jack extending beyond the former
dimension. Three screw holes allow the board to be attached to a surface or case. Note
that the distance between digital pins 7 and 8 is 160 mil (0.16"), not an even multiple
of the 100 mil spacing of the other pins.
The Mega2560 is designed to be compatible with most shields designed for the Uno,
Diecimila or Duemilanove. Digital pins 0 to 13 (and the adjacent AREF and GND
pins), analog inputs 0 to 5, the power header, and ICSP header are all in equivalent
locations. Further the main UART (serial port) is located on the same pins (0 and 1),
as are external interrupts 0 and 1 (pins 2 and 3 respectively). SPI is available through
the ICSP header on both the Mega2560 and Duemilanove / Diecimila.
30
CHAPTER 4
METHODOLOGY
4.1 Block Diagram
Figure 4.1: Block Diagram of the System
The above block diagram represents the working of the system. Although each
component or section of the system was explained in the previous chapter, here is a
brief description of every block in the system and how each component is
synchronized with each other:
● Picking: Picking is nothing but plucking of string using a finger or a plectrum
for the pickup to sense the note played and sending it to the sensor system for
analog processing. This provides feedback to controller. Picking may have to
be done twice or thrice, so that the tuning process is done is a number of
iterations and the final result is accurate.
● Sensor system: The sensor system is provided to capture the vibration of the
string and compute the fundamental frequency of vibration using an analog
circuit. The fundamental frequency is calculated and a corresponding voltage
is given at the output of the entire circuit. The reason for computing
fundamental frequency is that the representation of musical notes is done by a
single frequency. However, the signal from guitar or any other instrument for
that matter consists of overtones, which are responsible for the different timbre
or in other words tone colour.
31
● Microcontroller: A microcontroller, Arduino Mega 2560 in this case, is the
controller in the control system. It is to be programmed to receive current
input, compare it with the set point of the system and initiate the actuator to
compensate for the error.
● Servomotor: This is the actuator used to move the tuning key and change the
tension in the string. It provides precise control of angular position, velocity
and acceleration, and hence is suitable for this application.
4.2 Microphone Frequency Sensor
The very first task that was needed to be addressed was finding out a suitable
method to find frequency of the string that was being played. A suitable sensor was to
be found out that would capture the frequency of the input signal and to convert the
signal into its corresponding voltage. Initially it was suggested that a microphone was
to be used to detect the sound frequency because of its easy availability in the market.
Initially a sensor was needed to be found out that would catch the frequency of
the signal. It was suggested that we use a microphone to catch the signal from guitar.
A suitable circuit which converted frequency of the input signal to a corresponding
voltage was found out.
Figure 4.2: Microphone frequency sensor
First stage of the process is the amplification which takes the microphone
output and amplifies it by a gain of several tens or so. Then comes the Frequency to
voltage converter stage using the LM2917. This chip is divided to a tachometer
section and an op amp section. The chip used here is a ground-referenced tachometer
32
input and an internal connection between the tachometer output and the op amp
non-inverting input.
This circuit was rejected because the microphone is more susceptible to
noises. These noises cause disturbances in the actual signal whose frequency is to be
measured and because of this the frequency increases or decreases which in turn leads
to fluctuation in the voltage. As this happens it leads to the voltage going above 5
Volts which is not desired as tightening and loosening of the string cannot be done
using servo motor. As Arduino mega does not operate above 5 Volts. In this circuit
for every 1000Hz, voltage changes by 1 Volt which is not useful as our entire
operation operates in frequencies below 1000Hz.
4.3 String Mechanics
A steel guitar string with scale length L will vibrate at the fundamental
frequency and multiples of the fundamental, called harmonics. The fundamental
wavelength is directly proportional to the scale length and the harmonics are multiples
thereafter, as depicted in Figure 4.3.
Figure 4.3: Fundamental and harmonics output from a guitar string
Adjusting the tension on the string changes the fundamental frequency the
string will vibrate at. The tension required to vibrate at a specific frequency is
determined with the equation below:
33
The tension on the string has a non-linear relationship with the frequency
generated and the frequencies expected require very slight modifications of the
tension. For very slight adjustments to the tension, a stepper motor in combination
with a guitar tuning peg was selected. To make the guitar tuner fully automated, a
servo motor was included in the design. The servo motor, with attached guitar pick,
plucks the string and creates vibrations for the inductive pick-up coil.
4.4 Low Pass Filter
A Low pass filter was designed to pass the frequency below the cut off
frequency (400Hz) and eliminate the frequencies above the cut off frequency. The
circuit which was designed in the chapter 2 was tested using a Cathode Ray
Oscilloscope and a function generator. At first a signal was generated using the
function generator which is similar to the signal generated by the guitar while the
string is played. After the signal is detected the low pass filter eliminates the
frequencies but it doesn’t remove the 2nd overtone so a 4th order low pass filter was
made which didn’t create much of a difference in removing the 2nd overtone, so a
3rd order low pass filter was finally made for the process as the filter eliminated all the
upper harmonics above second overtone. Even the magnitude of the second overtone
was reduced to almost one-fifth of the input magnitude. By providing sufficient pass
band gain in the circuit, the effect of second overtone in the signal can be neglected.
34
Figure 4.4: Simulation of Low Pass Filter on Multisim 13.0
The output of the low pass filter was sent to the frequency to voltage converter. As we
are using an Arduino mega microcontroller which works when voltage is given as an
input between 0 to 5 Volts then it turns the knob of the key and thus tunes the guitar.
4.5 Frequency to Voltage Conversion
Initially 555 Timer was used to convert frequency into voltage as the Arduino
Mega requires an input in voltage.
Figure 4.5: Frequency to Voltage converter using 555 Timer
Here is a very simple circuit diagram of a frequency to voltage (F to V) converter.
Such a circuit finds numerous applications in projects like digital frequency meters,
tachometers etc. The circuit is mainly based on a LM555 timer IC. The IC is wired in
mono shot mode to convert the input frequency into a fixed pulse width, variable
frequency PWM signal. Resistors R4 and capacitor C2 provides the necessary timing
for the circuit. The transistor T1 forms a discharge path parallel to C2 which is
necessary for re triggering the IC. Capacitor C1 acts as an input DC decoupler. The
output of the circuit is not a pure DC but a PWM waveform. Additional circuitry is
required to convert this PWM waveform to pure DC.
This circuit was rejected because the frequency which is converted to voltage
doesn’t lie between 0 to 5 Volts. It was either above 5 Volts or below 0 Volts and
35
hence was not suitable for the process. So instead the LM2917 was selected because it
gave us the required output.
The LM 2917 series are monolithic frequency to voltage converter with a high
gain op amp/comparator design to operate a relay, lamp or other load when the input
frequency reaches or exceeds selected rate. The tachometer uses a charge pump
technique and offers frequency doubling for low ripple, full input protection and its
output swings to ground for a zero frequency input.
The op amp/comparator is fully compatible with the tachometer and has a
floating transistor as its output. This feature allows either a ground or supply referred
load of upto 50 mA. The collector may be taken above Vcc upto a maximum Vce of
28 Volts. The basic configuration offered includes an 8 pin device with a ground
referenced tachometr input and an internal connection between the tachometer output
and the op amp non inverting input. This version is well suited for single speed or
frequency switching or fully buffered frequency to voltage conversion applications.
The more versatile configurations provide differential tachometer input and
uncommitted op amp inputs. With this version a tachometer input may be floated and
op amp becomes suitable for active filter conditioning of the tachometer output.
36
Figure 4.6: Zener Regulated Frequency to Voltage Converter
4.6 Program
After the signal is processed and the frequency is represented in the form of
voltage, the microcontroller needs to be programmed such that it reads the input from
the circuit, compares it with the set point and initiates the actuator to compensate for
the error. The following flow chart illustrates the algorithm of the program.
37
Start
38
CHAPTER 5
CONCLUSIONS AND SCOPE FOR FUTURE WORK
The scope of the project lied within tuning the E4 string of the guitar. It may
later be expanded to include all the six string of the guitar. Also, the current setup is
merely a prototype to establish the concept of self-tuning; the implementation of the
system can be done on a real guitar, where micro servos will be coupled to the shaft of
warm gear. Guitar players using a movable bridge will find this system very useful as
using the tremolo arm often disturbs the tuning of the guitar.
The current system was built and calibrated to provide fine tuning. Coarse
tuning cannot be done using this system due to restriction in movement of servo
motors to 180 or 360 degrees, though a stepper motor can be used for the purpose of
course training. In that situation, the tuning keys on headstock can be fixed with
stepper motors to provide coarse tuning and knobs at the movable bridges can be
coupled with servo motors to provide fine tuning.
The whole system can also be implemented for different tunings used in
contemporary music like DADGAD, Dropped D, D Standard, DGDGBD, etc. In that
case a second input would have to be taken from the user and set values for each
tuning will have to be stored in the microcontroller and called when the corresponding
tuning is selected.
Although the auto-tuning process is achieved, the design of the system has
some minor flaws.
Firstly, the third order low pass Butterworth filter, set at a cut-off frequency of
400 Hz, completely removes third overtone (1318.51 Hz), only half of the amplitude
of second overtone (659.25 H) is removed. Since the element of second overtone is
very less in the signal, it is neglected after filtering.
One way to overcome this is selective placement of pickup across the length
of the string. This is based on the principle of nodes and antinodes, which is explained
below:
39
The picture shows three situations. The top diagram shows the first harmonic
of the string's pitch, called the fundamental.
The diagram labeled "2nd" is the second harmonic. As we, know, the string
can only vibrate at whole number multiples of the fundamental pitch (1x, 2x, 3x, etc.).
One cannot see it very well in a vibrating guitar string, but there are fat and skinny
spots. The point of minimum movement is called a node. The point of maximum
movement is called an antinode. The number of the harmonic is found by counting the
number of antinodes on the string.
Figure 5.1: Node and Antinode
The next picture shows the same three harmonics with the pickup positioned
midway along the string. The pickup only detects string vibration when the string is
vibrating near the pickup. In the top and bottom diagrams of Figure 5.2, the
fundamental and third harmonic, the string is moving a lot in the pickup's vicinity. But
for the second harmonic, the pickup is situated over a node, meaning that the pickup
does not hear the second harmonic.
40
Figure 5.2 Pickup placed midway across the length of the string
Now as interesting as that sounds, such a setup is not possible in a guitar as the
pickups are mounted near the bridge and not on the centre of the bridge. So this
design cannot really be implemented. Hence, the problem of removing the second
overtone is not addressed by this method.
41
REFERENCES
This project took a lot of research and in depth reading of the concepts
required to build the system. Here is a list of all the books and websites referred to
successfully complete the project.
Books:
● Ramakant A.Gayakward, Op-amps and Linear Integrated Circuits, IV edition,
Pearson Education, 2003 / PHI
● D.Roy Choudhary, Sheil B.Jani, Linear Integrated Circuits, II edition, New
Age, 2003
● John G. Proakis and Dimitris C. Manolakis, Digital Signal Processing
Principles, Algorithms and Applications, Prentice Hall of India, 3rd edition,
1996
● Hugh Young and Roger Freedman, University Physics, Vol. 1, Pearson
Education, 13th edition
Websites:
● http://www.performing-musician.com/pm/jan08/articles/gibsonrobotguita
r.htm
● http://www2.gibson.com/Products/Min-ETune.aspx
● http://www.gizmag.com/review-peavey-at200-auto-tune-guitar/26205/
● http://engin1000.pbworks.com/w/page/18942682/Automatic%20Guitar%
20Tuner
● http://brunopinho.com/seng466_spring_2013/?p=5
● http://www.convict.lu/Jeunes/Spielberg/Spielberg.htm
● http://www.seattlerobotics.org/encoder/200112/elik.htm
● http://www.instructables.com/id/Arduino-Audio-Input/?ALLSTEPS
● http://www.instructables.com/id/Reliable-Frequency-Detection-Using-DS
P-Techniques/?ALLSTEPS
● http://forum.arduino.cc/index.php?PHPSESSID=kl67agklaa1nu8h0ao08j
921j1&topic=191267.04
42
● http://stackoverflow.com/questions/5044289/how-to-find-the-fundamental
-frequency-of-a-guitar-string-sound
● http://www.circuitstoday.com/f-to-v-converter
● http://www.aqdi.com/pickups.htm
● http://www.phy.mtu.edu/~suits/notefreqs.html
● http://www.electronics-tutorials.ws/filter/filter_8.html
43
APPENDIX A
The program code written on Arduino IDE is:
#include <Servo.h>
Servo myservo;
int inputfromguitar = A1;
int pos = 0;
int targetvoltage= 114; //analoginputvalue
int inputvoltage;
void setup()
{
myservo.attach(9);
}
void loop()
{
inputvoltage = analogRead(A1);
if(inputvoltage>51)
{
myservo.write(0);
while(inputvoltage<=targetvoltage)
{
inputvoltage = analogRead(A1);
myservo.write(pos); // tell servo to go to position in variable 'pos'
44
delay(15);
pos=pos+1; } } }
45