Audio Input to Arduino

The easiest way to connect audio signal to your arduino, is build a simple 3 components (2 resistors plus cap) circuitry shown on the first drawings on right side. Disadvantage: as there is no amplifier, sensitivity would be low, hardly enough to work with headphones jack output.  For low level signals, like 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 around. Something like this:

Note: Speakers should use USB port as a power source, not AC power outlet!

1.  Open box up, and look  what kind of chip (IC) Power Amplifier inside, on the PCB board:

2.  TEA2025 in this example, but could be different in yours. Not big deal, just write down the name, than go on-line and try to find a data sheet for your particular chip. My favorite links:  1   and   2.  From the data sheet you will find pin numbers of two outputs, for left and right channels. Just solder couple of wires to ground and to one of the output and that’s it!

3. If printing on the IC body is unreadable, or couldn’t find a data sheet, it is possible to trace two wires from the speaker to IC. Most likely, there would be an electrolytic cap installed in series, between chip output and speaker. Solder a signal wire on the chip’s side of the cap, or near IC. There is a slim chance, of course, that IC configured in bridge configuration, and wouldn’t be any caps. It’s even better, just use ether of two speaker’s wires as a signal line, and ground as ??? a ground.

Be careful, use different color of wires for ground line and signal line. There would be no protection, and wrong polarity could damage an analog input of the arduino board, and in some occasions Power Amplifier IC. To prevent this, I’d strongly advise to install 10 kOHm resistor in series with signal wire.


[original story: coolarduino]