loading
Picture of 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.
 
Remove these adsRemove these ads by Signing Up

Step 1: Materials

Picture of 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

Picture of Preparing the Enclosure
2721186162_d5b84440bc.jpg
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

Picture of 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

Picture of Normalize the Input and Output
schematic.gif
schematic.jpg
2720361283_71272a0713.jpg

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

Picture of 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

Picture of 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.
1-40 of 93Next »
nuelma2 months ago

I played guitar and I think a great invention

benrosenbach2 months ago

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!

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..

Did you ever get the proper code? I'd also like to see it!

nimmis2 years ago
@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!!
kylemcdonald (author)  arduinolover2 years ago
there are no other libraries to run, just the GlitchPedal code. but i recommend you follow this new tutorial by randy http://www.instructables.com/id/Arduino-Guitar-Pedal/
could someone tell me why the compiler tells me that analogWrite is not defined within scope?
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
kylemcdonald (author)  DJsoundestroyer3 years ago
check out the video on vimeo
nexekho3 years ago
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
nexekho3 years ago
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
nexekho nexekho3 years ago
Site note: buffers take up quite a bit of memory, might need to go mono for a Mega 168.
nexekho nexekho3 years ago
Sounds MUCH BETTER in mono due to higher sample rate.
http://pastebin.com/2ed16VD0
http://soundcloud.com/nexekho/much-much-smoother
nexekho nexekho3 years ago
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
LukaR4 years ago
Is there a way to add an on/off switch to the circuit (like the one on the picture), making a stomp box out of this?
switch.gif
nexekho LukaR3 years ago
You can make a bypass with a SPDT which will select either the Arduino output or the guitar input, but it will likely "suck tone" and as such you will need a DPDT to isolate the Arduino input as well.
Yes it would be possible, in tonepad.com you can see a wiring diagram for these switches. It would have to be a DPDT or 3PDT.
Hope this helps:
http://www.muzique.com/lab/truebypass.htm
kylemcdonald (author)  LukaR4 years ago
I don't usually make guitar pedals so I'm not familiar with the way that switch is wired. If it actually toggles between two sources, you just need to wire the "clean" input directly to one side of the switch, and the distorted output to the other.

On the other hand, if it is a momentary switch you'll need to wire it to an interrupt pin on the Arduino and modify the code to watch for that interrupt, not applying any effects when the toggle is on.

I'm sure there are also plenty of schematics out there for making toggle boxes with these switches, in which case you would just wire your clean signal to one input and the distorted signal to the other.
nexekho3 years ago
Hey, I just built one of these on perfboard, made a mistake on the inputs (biasing with A7 rather than 5V, will correct in the morning) and while almost everything works (the dials work, etc.) I can't get a sound wave out. If I just take a standard flashing light example script and tell it to whack a PWM to pin 3, it outputs a very loud square wave. Using your code, nothing is output. This is my first Arduino project. I'm using a Nano but it's a Mega328P Nano which should work right?
nexekho nexekho3 years ago
I've fixed it now. It was an issue with the timer registers. Thanks for the design.

I've attached some photos of my custom build.  Small size was a priority here so I built the output filters under the Arduino itself which was a fun challenge.
ArduinoBoard.jpg
kylemcdonald (author)  nexekho3 years ago
wow! awesome, and congratulations on your first arduino project. glad everything worked out. your design is super compact, it looks great :)
Made some code changes and got it as good as it'll ever be in terms of sound cleanliness. Using 10-bit in, 16-bit out, and a prescale of 8.
Sample: http://soundcloud.com/nexekho/almost-perfect
(note: I'm using a POD as a preamp and distortion, the Arduino is just clean passthrough at the moment and then a Valvecaster post-amp before going into my PC's line in)
Code: http://pastebin.com/9zphwpvA
I'm finding that using a tone dial to roll off the highs makes a far cleaner sound.
nexekho nexekho3 years ago
(also note: I'm not being silly, I'm trying to output a 100Hz triangle wave using your code instead of passthroughing the input ;])
nexekho nexekho3 years ago
Also, the schematic describes a high-pass-filter for the output. Is that right? It feels like it should be low pass.
Or23 years ago
I'm new the the arduino scene, is Diecimila the same as Duemilanove ?
zoltzerino4 years ago
How crucial is the ratio between resistors R and 256R, the guy in the shop couldn't tell the difference between orange and brown so I have R = 1.5k and 256R = 190k...

Could I use my 190k and two 330R in series (R=660, 256R should equal (ish) 170R (but would be 190R)? Or is that not a close enough match?

I've checked all of my wiring and joints, guitar was on, amp was on, audio leads functional, used a chorus pedal to boost the input (you used a tuner).

Thanks in advance :-)
kylemcdonald (author)  zoltzerino4 years ago
using the two 190k resistors in series against the 1.5k gives a ratio of 253 which is totally acceptable. the resistor manufacturing tolerance will probably be the bigger error. good luck!
yesiam4 years ago
This looks great! I was wondering if this can be used with a synth or laptop audio. And if not, if it can be modified to do so..
kylemcdonald (author)  yesiam4 years ago
anything you can plug into a guitar pedal should work fine. and definitely laptop output, i primarily used my laptop for testing this while i developed it.
j03tv4 years ago
Weak!
missingmax5 years ago
I see you used ceramic and electrolytic caps. Which one works better? 
Also, what would be the polarity if you used the electrolytics in your schematic?
kylemcdonald (author)  missingmax5 years ago
I didn't evaluate ceramic vs electrolytic for their "sound" really, so I can't say which one is "better". You'll have to try both out and let me know if you hear a difference!

I vaguely remember, on the outputs, the electrolytic caps facing the output. But again, you should try it both ways -- this was two years ago now and I have been writing a lot more code that making circuits since then :)
 Any chance you could post a picture with the other side of the perfboard circuit for the DAC? I'd like to have a go at this project but am having a little trouble with this stage.

Someone should make an audio input/output sheild for the Duemilanove with all the DAC on board for projects like this!
kylemcdonald (author)  loneguitarist5 years ago
Sorry, I don't have this pedal any more, I made it for a friend!

If I remember correctly, the perf board wasn't connected on the back and everything was manually soldered. So hopefully the diagrams/schematics on this page will explain anything missing from the pictures. The pictures were meant more as a layout guide for fitting the components in a smaller space.
jsd785 years ago
I was wondering what kind of preamp is necessary. I don't own a tuner that acts as a preamp (more like a filter). Is it possible to build a preamp that's not too difficult?
1-40 of 93Next »