How can I output a signal from an electric guitar to an amp with arduino uno?

I am trying to make an electric guitar with an Arduino in it so I can give effects like distortion, delay, chorus digitally. My original plan was to connect the guitar's output jack wire to an analog input on my Arduino UNO and do some software stuff and output the audio through a digital pin to a guitar amp. I tested with a cheap humbucker pickup(which is working fine and the sound is great) connected to an analog pin and a 20w Fender guitar amp(which is also working fine) connected to a digital pin. When I simply did something like this,

int input = A6;
int output = 7;
int val = 0;
void setup() {
pinMode(output, OUTPUT);
Serial.begin(9600);

}

void loop() {

val = analogRead(input);

Serial.write(val);
analogWrite(output, val);

}

I could see the signal though serial but nothing came out of the amp. So I did this,

val = analogRead(input) * 5;

and I did get a sound but it wasn't anything like a guitar sound. What should I do?

Hi. Nice to meet people who interested at learning and Doing It Self.
Start with reading a basics, like

  1. which data types exist in Arduino IDE
  2. what is PWM and how to handle it
  3. how work analog reading and how to handle it
  4. be helpful to know how electric guitar pickup works

I wish you success

@taeminshin0708 pin 7 on an UNO is a pure digital pin. It cannot be used to output an analog signal.

Technically speaking, none of the pins on the UNO can output an analog signal. You can approximate an analog output with one of the PWM-enabled pins (3, 5, 6, 9, 10 or 11) and an RC-filter.
However, you will run into unsurmountable signal quality issues; an Arduino UNO just isn't made to be a digital signal processor.

Hi, @taeminshin0708
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

analogWrite does not actually output an analog level, it outputs a PWM wave, the duty cycle from 0 to 100% represented by values from 0 to 255.

AnalogRead on a UNO has values 0 to 1023.

So your code just samples and converts to a PWM waveform.
You also will have to make sure you have a sampling rate high enough to get a proper waveform at your highest audio frequency.

The UNO may not be fast enough to do much processing anyway.

What is your electronics, programming, arduino, hardware experience?

Tom... :smiley: :+1: :coffee: :australia:

electric guitar pickup give out a waveform with positive and negative voltage. the last can Arduino analog input not handle.

Before I go all negative on you...

There are a couple of changes that should make your code "work":

1- You need to bias the input so you can read the negative-half of the waveform. That simply requires two equal-value resistors and a capacitor as shown at the bottom of this post.

For a guitar (high impedance) increase the resistors to 1M or higher. With the higher-value resistors you can (optionally) use a lower-value capacitor of 0.1 or 0.01 uF.

2- Since the analog input is 10-bits and the PWM output is 8-bits, you should divide the values by 4 (or bit-shift right by 2-bits).

3- The default PWM frequency is about 500Hz which is smack-in-the-middle of the audio range and it will overwhelm your actual audio. You need to increase the PWM frequency above the audible range. (I've never done this.)

4- Since the output also can't go negative and it's also biased, you should add a capacitor in series with the output to filter-out the "DC" bias. (Again about 0.1uF will work into a guitar amp).

5- Unfiltered PWM is a "nasty" signal and the the full 0-5V PWM signal is present even with "silence" and it can sometimes do "bad things" to an amplifier! You might want to start-with some cheap powered computer speakers so you don't possibly burn-up your guitar amp.

A low-pass filter can remove the PWM to give you true-analog, but a simple RC filter may not be enough to completely remove the PWM. (You can research that yourself how to make a low-pass filter.)

6- Serial.write() will probably slow-down the loop to the point where you can't properly "sample" the audio. You can use it to make sure you're getting good readings but then take it out (or comment it out) for your "real program".

...Some people have made guitar effects with the Arduino so you might want to Google. Of course you can do more with digital but most regular guitar pedals are analog and depending on what kind of processing you're doing, analog might be better and easier for a DIY project.

Now for the negative...

The Arduino is under-powered for audio processing (slow, not much memory). The ADC is only 10-bits and a little slow for high-frequencies (but probably OK for the guitar). As you know by now, there is no built-in DAC so no true analog-output, and the default PWM is only 8-bits. And, the memory is limited. I wouldn't use an Arduino for audio processing.

I'm not sure how much computing power is needed for various DSP functions, and I don't know how to calculate/estimate that. Changing the volume is simple and distortion can be simple but filtering and other effects can be computationally intensive.

Most DSP requires a known sample rate. Your code doesn't require that because it's reading & writing at the same (unknown) sample rate and you aren't doing anything related to the frequency.

There are specialized DSP chips but they are more expensive and the hardware/software development kits are usually expensive too. A Raspberry Pi might be better than an Arduino. And it's probably best to learn DSP programming on a regular computer.

DSP (digital signal processing) is "advanced programming". If you were studying computer science in college you wouldn't learn DSP until the 3rd or 4th year. The Audacity web site has a little-simple Introduction to digital audio. I have a Digital Audio Programming book but I haven't actually done any audio programming. (I've just been interested in audio & programming for a long time. The book is "generic", not specific to the Arduino.)

Additionally, interrupts will mess up the audio processing on an already underpowered (for this purpose) Atmega328. Even if you get it to sort of work, expect glitches and other nasty audio artifacts multiple times per second. It's going to be ugly...but might be fun to try.

Thank you! I think this will be very helpful to me. I don't have a lot of knowledge about audio processing so I will have to research a lot based on your list here but still it will be very helpful.

Will 10 bit be enough for a guitar?

compare NES music and SNES :wink:

High-Resolution Audio files have a sampling frequency of 96 kHz/24 bit, which is significantly higher than the 44.1 KHz/16 bit sampling frequency of CDs.

Maybe this - https://www.electrosmash.com/pedalshield-uno.

Remember that is only the input, the output is only 8 bits.
Enough is a very subjective word. You will get results but nothing like a Zoom peddle.

I discuss simple audio effects for the voice in my book, but there is no reason why you can't use a Guitar as an input:-
Arduino Audio
Arduino music & Arduino projects
Chapter 15 shows you the extra hardware you will need to get a 12 bit output as well as a 10 bit input.
If you want to up your game you need to up your processor. The Raspberry Pi Pico controller (not to be confused with the Raspberry Pi computer) is powerful to do all the effects shown in the book but without additional hardware. Of course with both you need an amplifier on the front end and a filter and headphone amplifier on the back end.
Part one of this project is currently out, available at W.H. Simth's and other places. The free to download PDF can be found here:-
https://magpi.raspberrypi.org/issues/106
Part 2 is out at the end of this month (June 2021).

Have you looked at the Arduino-compatible Teensys? They have an Audio library making DSP super-easy, and there's audio shields for 16 bit audio
in and out. The Audio library already has objects for chorus, delay, distortion,
filtering, etc etc.

1 Like

So I researched what you said and found out that there's an audio adapter(쿠팡!) for Teensy 4.0(쿠팡!). So if I use these will I get a clear sound without all those resistor and capacitor stuff?

Hi,
This might be of help.

Tom... :smiley: :+1: :coffee: :australia:

No, why do you think all the resistor and capacitor stuff is in there in the first place?
You know engineers don’t just add components for the fun of it.

If you mean by using such a module all the many resistors, capacitors and chips are
neatly contained on a single PCB for your convenience, yes!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.