Arduino audio integration

Hi, was hoping someone would be able to tell me if this is possible.

To begin with I want basicaly input audio into the arduino, then ouput it.

My setup consists of a mic, low pass filter, and speaker.

I was thinking of biasing the microphone to keep it positive then feeding that into one of the analog inputs of the arduino.

on one of the PWM outputs ide have the low pass filter to get rid of the frequency at which the pwm opperates.

On the code of the chip i was thinking something like just having this code in the main:


How does this look?

Cheers, Phil.

The sample frequency of analogRead() is 8 kHz which means you can process 4kHz audio, which is good telephone quality…

damn, i need to be able to sample upto 22Khz, is there anyway to make this possible?

Possible lead here


Im looking at that now, reading through the source code.

What do you meen about the rate of analogread would be determined by how often you call it?


I had been too short-spoken. You can ideed increase the conversion by reducing the resolution, though that is not really "Arduino". 8 bits rather than 10 will give you 32kHz rather than 8 kHz sampling! This most interesting implementation jackrae linked to is using only half of it, I think mostly because of lack of RAM to store all the data.

You have a "streaming" application here, best solved by parallel processing (as possible with processors as the ParallaxPropeller) or by extensiv interrupt handling. It is difficult though possible to do it within a polling loop.

Sorry that I did not mention the switching to a lower resulution. In fact it will make processing much faster when you use bytes only....

The end of ADC conversion is communicated by a flag, this is asynchronious but the conversion time nevertheless is fixed.

Thanks for your input, but it makes problems slightly worse in my head :frowning:

if i set the prescale to 16 by using the available code, this allows me to sample quicker.

if i bias the input mic by connecting to 100k resistors in series across the power rail, (5v), and connecting the mic and arduino to inbetween these resistors, would this not bias the mic to positive.

I would then use a simple RC circuit to filter out the pwm noise on the output.

The code I propse is the following, does this seem like it would work or am I missing some vital point here?

Thanks again, phil.
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

void setup() {

// set prescale to 16



void loop() {



Let me try and make things clearer as I feel I may have jumped the gun a little.

I need to build an electronic digital audiop filter, one which I can basicaly sweep with a 500Hz Bandwidth through the entire audio frequency.

I planed to do this with analog filters but the accuracy was no where near what I needed.

I dont need to do anything else other than the above, an Ideal setup would have a mic input into the board, a pot onto one of the analog inputs to simulate sweeping throught the range, and a headphone output on the other end.

Im prety good with the hardware and software side of things, I just want to check its feasable.

I would be uping the rate at which can be called to read the mic signal.

I was thinking that I could 'filter' out the correct frequency by determining how often I call the read function, basicaly If I call the function at a rate of 2000 times per second, would this not filter out everything bar the 2000Hz frequency?

Thanks for your help, Phil.

Ok Progress, however im yet to actualy test anything, the plan is as follows. Conecting a mic to one of the pwm inouts but having this biased at 0.5 and having the AnalogReferece set to internal (1.1V) This means that i am biasing the mic half way, and considering standard mics output between 50/200mV This allows for best resolution without saturation.

Then Pramgraming wise I was just going to adjust the AnalogRead Prescaler to allow it to perform quicker (Is this correct?).

Im going to be outputing on another PWM pin.

I was wondering if a PWM carrier frequency of ~500Hz is acceptable for this use. Do I need to up the frequency? Does this have any sense in it? Please can someone help out a little, Ive studied the link in the second post and it seems to confuse me abit, the coding that he uses does not look like C as I have been using it.

Thanks allot, Phil.

I can't help thinking that a simple analogue circuit would be best for this app (if the result, rather than the journey, is the main factor)?