Introduction: How to Have Fun With Your Guitar and Arduino!

Hi, I'm Usher! Ever since I was a toddler, I have always loved two things: taking things apart (I was a highly mischievous child) and music. So when I had to make a project for school, what better thing is there to do than to combine both of them? That is what I have done here. This article consists of two projects that can be used together. One of them is a fuzz face made entirely out of spare parts (you can learn more about it and its inner workings here). While it isn't as beautifully sounding as an actual fuzz face (I would have likely needed to test every component for highly specific values), it does have its own unique glitchy sound, which is quite fun. The other, which is likely what you would use first, is a tuner! It was incredibly difficult to make, but I really enjoyed seeing it work properly. Hopefully, you will too once you see it in action!


To start off, I will briefly explain how I made it. It uses the arduinoFFT library. FFT stands for Fast Fourier Transform, and it is the type of calculation needed for the sound sensor's analog input to be interpreted as a digital frequency by the Arduino. Without this library, the sound sensor can only figure out how loud a sound is, which isn't particularly relevant to its use here. The way I used the library here is, I first strummed my guitar strings over and over again to see which dominant frequency it recorded (this can be checked by looking at the serial monitor of my final code). Once I noticed a consistent number for each string, I set a range of +/- 4 Hz for each string since the sensor may not be accurate 100% of the time. I then ran into the problem of some strings' dominant frequencies being quite close to each other, and my solution to that was to implement a button. This button, when pressed, changes which string is being tuned. In order for the user to know which string they're on, I added LEDs, with one more LED turning on each time you press the button (with 0 LEDs being the high E string). For reference, the default is one LED, and it denotes that the low E is being tuned. Once I had that all sorted, the code was good to go! Please note that you may have to alter the frequency ranges for each string based on the acoustics of your room and the sound sensor's placement.


The second, more straightforward thing I made, was a Fuzz Face. The fuzz face is a very famous guitar pedal popularized by Jimi Hendrix. Normally, you would make sure to use some very specific measurement components for it to ensure the best quality sounds, but I made it entirely using spare parts. The result is a very glitchy (in a digital sense) sounding distortion pedal. My only qualm with it is the lack of sustain, which would likely be alleviated by soldering it or just using better value capacitors and potentiometers. The biggest changes I had to make were connecting two 470-ohm resistors together instead of using a 1k potentiometer (you can use less or more resistance based on your preference), and a 100kA potentiometer instead of a 500kA potentiometer for volume. Lastly, I also connected two 10uF capacitors in parallel instead of using a 22uF capacitor, as I did not have one.


Supplies

The materials needed for this project are as follows:


Fuzz Face:

Breadboard ($11)

2 470Ω Resistors ($0.14 each)

2 18.2kΩ Resistors ($0.14 each)

2 3.9kΩ Resistors ($0.15 each)

2 2N3904 Transistors ($0.57 each)

0.01 uF Capacitor ($0.35)

2 10uF Capacitors ($0.33 each)

2.2uF Capacitor ($0.16)

2 1/4" Jacks ($3.09 each)

100kA potentiometer ($2.41)

9V Battery Clip ($0.99)

Jumper Wires ($16.99)


Guitar Tuner:

Arduino Uno ($46)

6 LEDs ($6.50 for 100)

Pushbutton ($0.58)

Jumper Wires ($16.99)

6 330Ω Resistors ($0.15 each)

Sound Sensor ($7)

Step 1: Making the Fuzz Face

To start off, you want to take a your 2.2uF capacitor and and connect it to the base of one of the 2n3904's. Also connect a 100k resistor to the base as well as connect the emitter to ground:

Step 2:

Attach the 2nd transistor's collector to the resistor we connected to the base of the other one. Also, add a wire connecting the collector of the first one to the base of the other one (very confusing but you'll see what I mean in the picture. Lastly, take your 2 18.2k resistors (or just a 33k if you have that) and in series, connect them to power and the base of the other transistor.

Step 3:

Add in the 0.01uF capacitor and connect it to the collector of the 2nd transistor using the 2 3.9k resistors in series (or an 8.2k if you have that). On the same side, connect the 330 ohm resistor to the same side of the capacitor and connect it to power.

Step 4:

Add in your input jack. Connect the positive end to nothing for now and the other side into ground. Now take our 100kA potentiometer. Connect the middle terminal to the positive end of the input jack. Connect 1 side to ground and connect the other to the side of the 0.01uF capacitor that nothing is connected to.

Step 5:

Lastly, take your two 470-ohm resistors and connect them to each other via the middle pin. Now, on one side of them, connect it to the emitter of the first transistor (which is connected to ground). Take your two 10uF capacitors and connect them to each other in parallel. Attach the middle of the two resistors (where they both overlap) and connect it to them. Connect the two capacitors to ground. Now, connect the last side of the two resistor setup and connect it to the emitter of the other transistor. Connect the positive side of the input jack (1/4-inch jack) to the negative side of the 2.2uF capacitor and the negative side to ground, and you're all done with the circuit! Remember to add in a 9V battery clip to the power and ground of the breadboard for the circuit to be usable.

Step 6: Wiring the Guitar Tuner

In terms of the guitar tuner, there is :

The pushbutton going to digital pin 2

The LED signifying the Low E is being tuned on digital pin 3

The A LED going to pin 4

The D LED going to pin 5

The G LED going to pin 6

The B LED going to pin 7

The LED that lights up when you are in tune going to pin 8

In case the picture does not give a clear idea, I have attached the TinkerCAD wiring diagram of my circuit.

Step 7: Code

Now lets get into how the code works. First off, the necessary library called "arduinoFFT" is included. This library provides functions that allow the Arduino to perform Fast Fourier Transform (FFT) calculations, which are used to analyze the guitar signal.

Some constant values are defined. "SAMPLES" specifies the number of points used for the FFT calculation, and it must be a power of 2. For an Arduino Uno, the maximum value is set to 128. "SAMPLING_FREQUENCY" determines the sampling rate of the audio input, which should be at least twice the highest expected frequency of the guitar. An instance of the "arduinoFFT" class is created and named "FFT". It will be used to perform the FFT calculations.

Several variables are declared for different purposes. "samplingPeriod" stores the time between each sample in microseconds. "microSeconds" is used to measure the time elapsed during sampling. The variables "redled", "Eled", "Aled", "Dled", "Gled", and "Bled" represent the Arduino pins connected to LEDs for different guitar strings. "buttonPin" represents the pin connected to a push button. "count" keeps track of the current state of the button, which corresponds to the string being tuned. "buttonState" and "lastButtonState" are used to monitor changes in the button state.

In the "setup()" function, the serial communication is initialized with a baud rate of 115200, which will be used to display the peak frequency. The "samplingPeriod" is calculated based on the "SAMPLING_FREQUENCY" value. The "buttonPin" is set as an input with a pull-up resistor, and the LED pins are set as outputs.

The main part of the code which is in the "loop()" function, repeats over and over again.

First, the code samples the guitar signal "SAMPLES" times. Inside a loop, it measures the time using "micros()", reads the analog value from pin A0 using "analogRead(0)", and stores it as a real value in the "vReal" array. The imaginary part (vImag) is set to 0 for simplicity. The code then waits for the remaining time to complete the sampling period.

After sampling, the FFT is performed on the acquired samples. The "Windowing()" function applies a windowing function to reduce spectral leakage. Then, the "Compute()" function calculates the FFT. Finally, the "ComplexToMagnitude()" function converts the complex FFT output into magnitude values.

The code determines the peak frequency using the "MajorPeak()" function and assigns it to the "peak" variable. If the peak frequency is below 365 (a threshold), it is printed to the serial monitor. I have it set like that so I'm not givena completely irrelevant frequency every 0.35 seconds. You can remove this if you'd like.

Next, the code controls the LEDs. Depending on the value of "count", which represents the current string being tuned, a specific LED is turned on. Each string has an associated frequency range (e.g., for the low E string, the peak frequency should be between 162 and 170). If the detected peak frequency falls within the expected range, the red LED is turned on for 2 seconds.

The code then checks the state of the button. If the button state has changed (different from the last button state) and the button is currently pressed, the "count" value is increased by 1. If "count" exceeds the maximum value of 5 (representing the highest string), it is reset back to 0.

Finally, there is a delay of 350 milliseconds before the "loop()" function repeats.

In summary, this code helps you tune your guitar by analyzing the guitar signal, finding the dominant frequency, and indicating which string needs tuning using LED indicators.

Step 8: Videos!

Here are some videos where I show both my projects working as well as briefly explain how they work:




Ignore me being sideways for half of this video, my phone doesn't appear to let me rotate mid-video.