In this tutorial, you'll learn to build and program an Arduino-powered guitar pedal.

Arduino Guitar Pedal

INTRODUCTION

In this tutorial, you'll learn to build and program an Arduino-powered guitar pedal. You'll start by wiring up the electrical components on a breadboard, and then will learn to program simple effects. You'll then extend the pedal with control knobs, a rotary switch and a stomp switch, and get to program your own effects. This should take around 3 hours, with more time required to solder the components together to fit into a metal casing for a more durable pedal.

Only basic programming skills are required for the main first part of this tutorial. You'll need some soldering experience for the extended sections.

Contents
  1. COMPONENTS
  2. ASSEMBLY
  3. PROGRAMMING
  4. CONCLUSION


COMPONENTS

For this project, you'll need to source various electronics and additional components. You'll also need to have access to a soldering iron and a drill.

General Capacitors Resistors

BREADBOARD ASSEMBLY

After aquiring all the components, it's now time to put them all together.

Before doing any soldering, we will assemble the electronics using a breadboard. For this section, you can either follow the tutorial step by step, or analyse the schematic and do the wiring yourself. The schematic is built upon the pedal design by Randy Sarafan and Kyle McDonald, with some updates. To open the diagram, you'll need to download Fritzing, an open-source tool for designing circuits.


Link to Fritzing Diagram


Pre-amp
The first part of the diagram that we'll wire-up is the preamp. The preamp amplifies the signals coming from the guitar, as well as inverting it. This is necessary for the Arduino to be able to process the input later on. We make use of the TL082 integrated chip, which contains two operational amplifiers (op amps). The pre-amp's pin mapping is as follows:

Starting with the TL082 placed across the middle of the breadboard, wire the following components, checking the schematics for the specifics of the components.

Guitar input
The next step is to wire the input from the guitar to the op-amp. The components new to this step have been marked with a red dot. The yellow wire is where we'll eventually wire the input audio jack to.

Arduino input
From the TL082, we need to wire the input through to the Arduino. The Arduino UNO has a built-in Analag-to-Digital Converter (ADC), which will convert the input from a continuous voltage to a 10-bit digital representation when we use the `analogRead()` function. The standard reference maximum voltage is 5V, so the input, between 0 and 5 volts, gets mapped to a value in the range 0 to 1023. Later in the tutorial, we'll be setting that analog reference to 1.2 volts.

The Arduino will be running in a loop, reading the input, midifying it and outputting it again.

Arduino output
After the Arduino has processed the input, it needs to output it back to the op-amp using the 'analogWrite()' function. However, while the Arduino UNO has an Analog-to-Digital converter, it does not have a Digital-to-Analog converter. Instead, it outputs the value using PWM - Pulse Width Modulation. PWM uses binary on-off voltage pulses of varying widths in order to simulate an analog output. The diagram shows how PWM (blue) is used to output the desired voltage (red).

In order to convert the PWM output to a single voltage, we'll need to build our own Digital-to-Analog converter. While these vary in complexity, the following simple DAC will sufficient. We'll be using a 3.9k-Ohm resistor together with a 0.1uF capacitor.

The red dot marks where the new components have been added.

Amplifier output
Finally, after the input from the guitar has been through the op-amp and the Arduino, it needs to be passed to the output audio jack.

The inputs and the ouputs need to be wired to the two audio jacks. If you don't have a soldering iron handy, you might be able to get by using electrical tape instead. This should be done according to the picture below.

We wire the output and input wires to the insert opposite the largest metal contact, on each audio jack.

In order for the electronics to draw power from the 9V battery only when two leads are plugged in, we wire the ground passing through the two jacks. The jacks each provide two inserts that are only in contact when a lead is plugged in. We connect one from each of the jacks to the other jack, and wire the two black cables below to connect to the battery and to the breadboard.

The basic wiring of the Arduino and pre-amp is now done. This makes up the core parts of the guitar pedal. Before adding additional components, we will first test that everything is working as it should and program some simple effects.


PROGRAMMING

We are now ready to program some effects. We'll be using the ArduinoDSP library, written by Kyle McDonald, which includes code to speed up the inputs and outputs to the Arduino. It does this by modyfying the PWM prescaling and analog input prescaling values. It also sets the Analog Reference value to 1.1V.

The ArduinoDSP requires an older release of the Arduino IDE, which you can grab from the Arduino website. Download version 0021, which is available on Windows, MacOS and Linux.

Once you've downloaded the IDE, you can grab the library from here:


Link to code


In addition to the ArduinoDSP library, you'll find a basic template for the main program:

#include "dsp.h"
void setup() {
  setupIO();
}

void loop() {

  // Input
  int input = analogRead(left);

  /* Effects go here */

  // Output
  output(left,input);
}



Effect 1: Bitcrusher

The first effect that we'll program will be a Distortion effect. More specifically, we'll distort the input using the Bitcrusher effect. From the Wikipedia article - a Bitcrusher is a lo-fi digital audio effect, which produces a distortion by the reduction of the resolution or bandwidth of digital audio data.

The following audio file demonstrates the un-altered input, followed by the bitcrushed input:


Play
Exercise:
When we load in the input in the code, we run int input = analogRead(left);. int is a 16-bit integer, but the Analog-toDigital converter is only 10-bit, so the value stored in input is a value between 0 and 1023. The first exercise of this tutorial is to program an effect that will reduce the resolution (to a resolution of your choice).
Solution:

Click to reveal solution

#include "dsp.h"
void setup() {
  setupIO();
}

void loop() {

  // Input
  int input = analogRead(left);

  /* Effects go here */
  input = (byte) input;  
  // another answer: input = input & 65472;
  // another answer: input = input >> 6 << 6;

  // Output
  output(left,input);
}

The only line we need to add is input = (byte) input, which typecasts input to a byte down from an int. Another method that achieves the same result is to use the & operation. The number 65472, in binary, is 1111111111000000. When a number is &-ed with this number, the lower 6 bits get nulled while the upper 10 bits stay the same. Yet another method is to shift the number using the >> operator by 6 bits, followed by a shift in the opposite direction. All of these methods make input a 4-bit value down from a 10-bit value. You can adjust how much resolution is lost for differing effects.








Effect 2: Delay

The next effect that we'll be programming is the Delay Effect. As the name suggests - we want to play the sound coming from the guitar after a constant time. For now we will use a fixed time delay, but will later add the ability to vary that time with a control knob on the pedal.

The following audio file demonstrates the un-altered input, followed by the delayed input. However, using another control knob that will be added later, it's also combined with the original input so that every note coming from the guitar is played twice.


Play
Exercise

In this second effect, you'll need to somehow store the input so that it can be accessed at a later time. See the Arrays reference for help on how to do this.

Note that an Arduino Uno only has 2k bytes of SRAM, which is where variables are stored. In order to store more information, you would either have to use a different board (e.g. the Arduino Mega has 8k bytes of SRAM) or use an external RAM module. For example, the 23K256 chip can provide an additional 32k of SRAM to the Arduino Uno (see Spi RAM reference for more information).

Solution:

Click to reveal solution

#include "dsp.h"
int array[1000];
int index = 0;

void setup() {
  setupIO();
}

void loop() {

  // Input
  int input = analogRead(left);

  array[index] = input;

  index = (index + 1 ) % 1000;

  // Output
  output(left,array[index]);
}

The provided solution works by keeping an array of 1000 ints used to store the past 1000 inputs. It stores an index to track the oldest input. Everytime the loop runs, it removes overwrites that oldest input with the current input, and then plays the next oldest input.

Note that you can't just make the Arduino sleep for a time period using the delay(ms) function because you would lose the input from when the Arduino is idle.







Click for extention components


EXTENSION

Now that we have the basic code running, we want to turn it into a proper guitar pedal. We first want to add some controls, which will include three potentiometers, a 6-position switch and a stomp pedal. First, we setup up a potentiontiometer to control the volume of the output coming from the Arduino. This step inolves just adding the potentiometer and a cable.

We also want to be able to merge in the clean audio that hasn't been through the Arduino. We take the output of the first op-amp in the TL082, pass it through a potentiometer and wire it back to the second op-amp in the TL082.

Exercise:
The next three components are a potentiometer going straight into the Arduino, a 6-position switch and a stomp pedal. All of these components are quite simple to wire up by following the schematic.
Exercise:

All the components have been wired and you've (hopefully) tested everything, it's time to start all over. This time, however, you'll use the prototyping shield. This will let you fit it all into the metal casing.

At the end of it, it should look something like this (hopefully yours won't be as messy as mine):

Now that everything is nice and compact, we can start to assemble it into its final form. Measure out and drill the metal box that you'll be using, to have holes for the potentiometers, switches and audio jacks. Optionally, you can also drill a hole for a USB cable, for easier Arduino programming.

Now that everything is ready, put it all together, making sure that the Arduino and shield aren't touching any metal components that might short them. Use the cork mat to help with this, lining the top and bottom of the box with it.

If everything has gone according to plan, you should now have an awesome programmable guitar pedal that you have built from scratch.

We now have to our disposal a potentiometer going straight into the Arduino, with which we can modify the effects based on its value. We can also store different effects and select them using the 6-position switch. You can access both of these values using analogRead(2) and analogRead(3), noting that the values will be between 0 and 1023. Use this function to do this:

void readKnobs(){
  //read the rotary switch
  //and determine which effect is selected
  //dividing by 75 ensures proper discrete values
  //for if statements
  mode = analogRead(2);
  mode = mode / 75;
    
  //reads the effects pot to adjust
  //the intensity of the effects
  fx = analogRead(3);

}

CONCLUSION

That concludes this tutorial on building an Arduino-powered guitar pedal. So far, you've only programmed some very simple effects, barely scraping the full potential of your brand new programmable guitar pedal. What you do from here with it is entirely up to you. Some potential ideas you could persue are: