Lessons and the learning game

Build a digital effects pedal

A guitar effects pedal on an Uno, with a function generator for the guitar.

The finished pedal

Build a digital effects pedal runs every lesson on the same board:

  • The guitar: a function generator, a 220 Hz sine, 2 V peak, centered on 0 V like a pickup's signal.
  • The input: a 1 uF capacitor into A0, held at 2.5 V by two 10 k resistors: the bias.
  • The brain: an Arduino Uno, its ADC running free on A0 and Timer 2 interrupting 15,625 times a second.
  • The output: 8-bit PWM at 62.5 kHz on pin 9, smoothed by 1 k and 100 nF, then 1 uF to a piezo that shows the pitch it hears.
  • Controls: a potentiometer on A1, and two footswitches: MUTE on pin 2 stops the strings, FX on pin 3 switches the effect.

This is a digital guitar pedal. It is a different thing from the sim racing pedals in Build load cell pedals.

How it works

In and out. The capacitor blocks DC and the divider puts the swing in the middle of the ADC's 0 to 5 V; the code subtracts 128 to take the bias off. Each interrupt takes the latest sample, runs the effect and writes OCR1A. The knob is read eight times a second by borrowing the ADC for a sample.

Gain and clipping. Multiply, then limit: hard clipping cuts flat at the rails; soft clipping bends through y = 1.5t - 0.5t^3 first, from a 256-entry table.

Delay. A ring buffer of 1,280 bytes, all the Uno's 2 KB can spare beside the stack: 81 ms at most. Feedback writes some of the echo back for repeats, and MUTE measures the tail.

Tremolo. A slow phase accumulator, an LFO, scales every sample between 1 - depth and 1, as a triangle or a square.

Wah. Chamberlin's state-variable filter in fixed point, its band-pass output swept from 200 Hz to 2 kHz by the knob or by an LFO for auto-wah.

Latency. Sample by sample, the output follows the input within a tick. Working in blocks of 64 or 256 adds 4.1 or 16.4 ms, measured with MUTE.

The course

  1. Audio in and out: the bias, the swing, sampling and Nyquist, and why a real input needs a buffer.
  2. Gain and clipping: clean gain, hard and soft clipping, and harmonics.
  3. Delay: a ring buffer, feedback, the tail, and the 2 KB limit.
  4. Tremolo: an LFO's rate, depth and shape.
  5. Wah: a swept band-pass, auto-wah and Q.
  6. Latency: sample by sample against block processing.
  7. Project: a two-effect pedal: drive and tremolo in a chain, bypass, and the order swapped.

Every checked step is tested against the running circuit.