The easiest way to connect an audio signal to your arduino, is to build a simple 3 components (2 resistors plus cap) circuitry shown on the first drawings on right side. Disadvantage: there is no amplifier, and consequently sensitivity would be low, hardly enough to work with headphones jack output. For low level signals, like output of electret microphone, amplifier is necessary. Here is the kit, which included board, electronic components and NE5532 Operational Amplifier IC:
Super Ear Amplifier Kit
Other option, from SparkFun Electronics:
Breakout Board for Electret Microphone
Note: I don’t recommend to replace NE5532 OPA with popular LM358 or LM324 due their pure frequency response above > 10 kHz.
Configuring AtMega328 ADC to take input samples faster:
void setup() {
ADCSRA = 0×87; // freq = 1/128, 125 kHz. 13 cycles x 8 usec = 104 usec.
// ADCSRA = 0×86; // freq = 1/64, 250 kHz. 13 cycles x 4 usec = 52 usec.
// ADCSRA = 0×85; // freq = 1/32, 500 kHz. 13 cycles x 2 usec = 26 usec.
// ADCSRA = 0×84; // freq = 1/16 , 1 MHz. 13 cycles x 1 usec = 13 usec.
// ADCSRA = 0×83; // freq = 1/8, 2 MHz. 13 cycles x 0.5 usec = 6.5 usec.
// ADCSRA = 0×82; // freq = 1/4, 4 MHz. 13 cycles x 0.25 usec = 3.25 usec.
ADMUX = 0×40; // Select Analog Input 0
ADCSRA |= (1<<ADSC); // Start Conversion
Timer1.initialize(T_PERIOD); // Sampling with TimerOne library
Timer1.attachInterrupt(iProcess);
}
Reading and storing samples to array via ISR ( Timer Interrupt Subroutine ), Timer1 in this example:
void iProcess()
{
static uint8_t n_sampl;
if (ADCSRA & 0×10)
{
int16_t temp = ADCL;
temp += (ADCH << 8);
temp -= sdvigDC;
ADCSRA |= (1<<ADSC);
xin[n_sampl] = temp;
}
if (++n_sampl >= FFT_SIZE )
{
n_sampl = 0;
process = 1;
}
}
Don’t like to solder all this components from the drawings above? Here is easy way around, if you, by chance, have a spare USB speakers. Something like this:
For more detail: Audio Input to Arduino