Lo-fi Arduino Guitar Pedal

267,553

351

95

Published

Introduction: Lo-fi Arduino Guitar Pedal

Bit crushing, rate reducing, weird noises: DIY 10-bit effects/guitar pedal with an Arduino for lo-fi DSP.

Check out the demo video on Vimeo.

Step 1: Materials

Tools

  • Arduino (Diecimila, or with auto-reset)
  • Soldering iron
  • Hot glue gun
  • Wire cutters
  • Drill press or dremel

Materials

  • Enclosure
  • Solder
  • Hot glue
  • Wire
  • Perf board
  • Audio jacks (I used 1/8") (x2)
  • Interface inputs, e.g.: 3 potentiometers
  • Interface outputs, e.g.: 3 LEDs and 3 150 ohm resistors
  • Resistors: 1 k, 10 k, 1.2 k (x2), 1.5 k, 390 k
  • Capacitors: 2.2 uF (x2)

Double the number of resistors and capacitors for stereo wiring.

Step 2: Preparing the Enclosure

I used a "fast ethernet media converter" for my enclosure. It's just a box that happens to fit the Arduino, some interface elements, and two audio jacks. It's pretty sturdy metal, which is important for a pedal. As an added bonus: it has a hinge on the back, which makes it easy to open and close.

The only modifications I had to make to this enclosure were some holes for the three pots (using a drill press) and cutting out some plastic for the USB connector.

Step 3: Connecting the Components

Once the enclosure is prepared:

  • Situate the Arduino
  • Install any of your interface components, like pots or LEDs
  • Install your input and output jacks

Remember that the LEDs need resistors between them and the pins on the Arduino. I used 150 Ohm resistors.

We'll be modifying the analog reference value, so if you want to use any pots you have to connect them to the AREF pin instead of the usual 5V pin.

For the 1/8" connectors (or anything that isn't on the same panel of the enclosure as the Arduino) be sure to use flexible wires. Otherwise it will be hard to close the case and the joints might break or other connections might come loose.

Step 4: Normalize the Input and Output

Input


This is the only real "trick" when it comes to the hardware for this system. Audio happens as an AC signal from -1 V to +1 V, but the analog inputs on the Arduino run from 0 V (Ground) to some positive voltage called the analog reference (5 V by default). You can specify this positive voltage in code or with an external reference.

Since -1 V to +1 V is a 2 V range, we'll choose something smaller than 2 V for our analog reference value. It turns out 1.1 V is specified as a built in internal reference, which works out nicely.

From here we have to normalize the -1 V to +1 V as 0 V to 1.1 V. I did this using a resistor in series followed by a voltage divider circuit. A guitar cannot directly drive this circuit, it needs a preamp (like another pedal) to drive it. I'm sure you could add a transistor or op-amp preamp to the perf board so you could plug into the pedal directly.

Output


For the output, we're going to be using PWM. With some low level hacks in software, you can get an 8-bit PWM running at 62kHz = 16 MHz / 28

There are some other methods for audio output on the Arduino. A good overview can be found at uC hobby. I got some great results from an R2R DAC, but considering it needs around 40 resistors for 10-bit stereo output, I decided against it. Instead I went with the weighted pins technique, which is kind of like a cross between standard PWM and a resistor ladder.

Building the Circuit


I built two of each circuit on one perf board. I had a ground strip down the center that helped for arranging things as neatly as possible. The first time I built the circuit, it was too tall and didn't fit in the enclosure, so I had to build it again.

When you have capacitors in series like this, they will cut off some of your low frequencies. WIth a 2.2 uF capacitor, it's low enough so it doesn't really affect sounds in our hearing range. The larger the value, the better; but capacitors tend to get physically larger as their value increases.

Step 5: Connect Remaining Components

Once your input and output circuits are made on your perf board, place it inside and start attaching all the wires that have yet to be attached.

  • The audio input goes into the input circuit, then into the Arduino's analog inputs
  • The pot taps go to the Arduino's analog inputs
  • Two LEDs go to PWM outputs, one goes to a digital output
  • Four PWM outputs go into the 8/2-bit weighted DAC circuit
  • The output of the weighted DAC circuit goes to the audio output

Step 6: Upload DSP Code

Download the code and you'll find two folders. One is the basic DSP code, "ArduinoDSP", that you can use to make your own pedal. "GlitchPedal" is the one I used for this specific setup. At some point, Vimeo removed the per-group file hosting I was using to host the code. For better reference, see this code from Tony Ivanov or follow Randy's Instructable instead.

ArduinoDSP


The includes in ArduinoDSP are useful for setting the proper PWM prescaling and analog input prescaling values. They turn pins 3 and 11 into the left outputs (8 and 2 bits respectively) and 5 and 6 into the right outputs, using Fast PWM settings with no prescaling so the PWM is as fast as possible. The ADC is also set to a low prescale value, 32, and the analog reference is set to 1.1 V (the internal reference).

To modify the basic ArduinoDSP code, just insert your own code to modify the variable "input" between the line "short input = analogRead(left);" and "output(left, input);".

GlitchPedal


The code I've already written does a few things. The LEDs provide visual feedback about the knob positions and input level, and the pots control settings for the DSP happening inside the microcontroller. The first pot controls the mode, the second controls a parameter of that mode, and the third controls an effective sample rate. The modes include:

  • Bitcrush: bit shift the input to the right and then to the left, chopping off N bits.
  • Bitshift : shift the input to the left, leading to a weird effect for the first few values and then eventually noise (i.e., the "dithering bits").
  • Overdrive: Multiply the input by a float from 1-20.
  • Binary impulse response: do various binary operations on the input and the last result (XOR, NOR, XNOR, NAND...)

Step 7: Variations and Notes

Variations

  • Add an RC low pass filter on the output with selectable corner frequency
  • Weirder modes: bit remapping? bit rotation?
  • Repeat last N samples? This is heavily limited by the ATmega's RAM.
  • Run off 9V wall adapter instead of USB power
  • 6 8-bit outputs running into a 5.1 speaker system?
  • Use an Arduino mini for a super small pedal
  • Patch bay as an interface?
  • Input volume knob

Notes


Because the ADC is really the primary bottleneck in this setup, any alternative ADC methods could be really helpful (there's a great reference of alternatives here, though ultimately it'd be easiest to use a dedicated ADC chip via SPI instead of implementing these manually). As the system is now, it's best to stick to mono inputs if you want to retain fairly accurate output.

Thanks to Andrew Armenia for help with input normalization, Dane Kouttron for explaining a few things about PWM on ATmega168s, James Miglietta for assuring me that guitar pedals run at normal audio voltages, and Blair Neal for wanting a bitcrusher/sample rate reducer in the first place.

Update


Another great technique using an audio buffer and doing "real" effects has been demoed by Martin Nawrath.

I think one of the biggest benefits of Martin's approach is that he has an interrupt for the ADC sampling. Normally, the ADC is called in a blocking way using analogRead() (i.e., the code doesn't go past analogRead() until the conversion is made). Martin's technique frees up the code to do other things while the ADC is being done.

Share

    Recommendations

    • Oil Contest

      Oil Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Water Contest

      Water Contest

    95 Discussions

    I played guitar and I think a great invention

    I'm having trouble getting sound from this build. I wanted to test the voltage on the input circuit to make sure I was getting values that looked righht, so I wrote a little dummy test to output my value of A0 in the serial console after going through the input circuit (I couldn't find my voltmeter!)

    Oddly enough, when no audio signal is coming in, I keep getting values between 405 and 409. Even stranger, when I connect the input to ground, I still get the same values. When I have a strong audio signal coming in, I get values between 405 and 620.

    The only thing I can think of is that I had to use a lower value cap (.1uF instead of 2.2uF) because it's all I had, but I thought that would just affect filtering. Otherwise I'm not sure what's going on. I've double checked the build of the circuit and resistor values. Any help would be appreciated!

    1 reply

    Nevermind, I realized I was a fool and forgot how voltage dividers worked! When I replaced the cap with the proper value 2.2uF I got a ground value of 495, which I realized is close to 512, which is where it's supposed to be since it's a DC offset audio signal, so it's going to oscillate around the middle of the voltage range. When I turned my volume all the way up, I got values between 13 and 1020, just as I should!

    Still no sound out of the other end though, but I haven't tested everything yet.

    The folder I downloaded is named "Arduino_Guitar_Pedal" including five files. There is not any GlitchPedal file. May you send me the link to the Glitchpedal code? I am doing something wrong..

    1 reply

    @CyrilHaumont, could not get reply working, so here are the answer:

    To make it work on newer IDE (>= 1.0) you need to replace all "Wprogram.h" and "Wconstants.h" with "Arduino.h"

    Hi,
    I'm doing a new version of your guitar pedal. But i have just one problem, I can't find any Wprogram.h or Wconstants.h...
    And i read all comments (randolfo's too), it seems nobody has this kind of problem ?
    can it be from my version of arduino ide ?

    Hi there,
    I am about to start building this specific project but I would like to know how I am going to upload the code to my Arduino and make it run. Where can I find the GlitchPedal code and do I have to load more code (libraries) to run it? I am noobie as you understood.. Thanks a lot!!

    1 reply

    there are no other libraries to run, just the GlitchPedal code. but i recommend you follow this new tutorial by randy https://www.instructables.com/id/Arduino-Guitar-Pedal/

    I'm a total arduino/electronics noob, but I think that some of the function libraries got migrated to a new location in some core revision to the arduino libraries.

    Basically, in dsp.cpp, replace

    #include "WProgram.h"

    with

    #include

    And then make the same swap in timers.cpp with

    #include "WConstants.h"


    The code at least compiled for me. Of course I am still having problems with the actual build. All I'm getting is a very faint square wave buzz that modulates with knobc.

    Why did I think this was going to be simple?

    hey man! this looks truly awesome. any chance of a video or mp3? also, how would keyboards/synthesizers/drum machines work through this? sweet project!
    -stefan1138

    1 reply

    I got the asynchronous analog read you discussed working, though not using interrupts but a standard loop. Vastly increases my sample rate. Ported the chorus/flanger to it.
    code: http://pastebin.com/thP70QFj

    Wrote a chorus!
    Pot 1 is chorus speed. Define LINEARITY for experimental sine wave LFO using pot 2 to blend between linear or sine (it has problems) and pin 13 which has a LED on most devices will display the rate visually.
    http://pastebin.com/nCNyXSsR
    Works really nicely on low values, with a subtle flange on high values. Can also do many silly noises with the chorus set really fast.
    Sample: http://soundcloud.com/nexekho/arduino-lo-fi-chorus

    3 replies

    Site note: buffers take up quite a bit of memory, might need to go mono for a Mega 168.

    Sounds MUCH BETTER in mono due to higher sample rate.
    http://pastebin.com/2ed16VD0
    http://soundcloud.com/nexekho/much-much-smoother

    Added a depth control that changes how far it sweeps. Very useful for getting good flange effects.
    Code: http://pastebin.com/cRmNHCdk
    Sample: http://soundcloud.com/nexekho/flange-this