Electronic – arduino – Input sound to arduino via microphone jack

amplifierarduinoaudiomicrocontrollersignal

I'm designing a gadget which will light up LEDs using a microcontroller. I'd like for it to respond to an audio signal, so I was thinking there are a lot of ways I could do it: If I can accurately sample the voltage from a microphone or an analog signal (microphone out) fast enough I can run an FFT algorithm on the microcontroller and find out the gain at any arbitrary audible frequency, and flash the lights in tune, or other fancy fun stuff.

If it cannot sample at 44kHz, I can still get some meaningful data subject to aliasing. I'll need to flip through some textbooks in that case…

If my microcontroller is too slow to do a fourier transform, I figured I could still create an AC band-pass filter (can do it with two capacitors and two resitors) and amplify it so i could still give my microcontroller a couple of analog inputs representing certain frequency intensities.

So I think I am pretty sure how this plan works on a big-picture level, but I'm not sure where to start to figure out how to wire together my components. I have a couple of different op-amps, a few BJT's, some assorted resistors. My assorted capacitors are still in the mail. I have a few arduinos which will hopefully be sufficient for prototyping. I also have the requisite materials for printing my own circuit boards (copper plated laminate, etching acid, laser printer, iron) and stuff for soldering. However I do not have an oscilloscope or function generator, only a DMM and a current- and voltage-controlled DC power supply.

So an audio signal is carried over two wires. The difference in potential between the wires (and perhaps to some degree the current??) represents some function of the air pressure displacement due to sound at the point in space occupied by the microphone. This is due to the common design aspects of nearly all speakers and microphones. This would mean that this voltage will go both positive and negative (no DC bias, as I understand it) and therefore would require offsetting so the analog input read will not clip half of the waveform. How many volts would the amplitude of the signal be, from the headphone out on a sound card for example? What about an iPod? Could I play an mp3 of a sine wave on my computer, and examine the AC voltage on the audio jack using my DMM? How do I know what frequency range the DMM will make accurate AC voltage measurements?

Best Answer

If the Arduino is anything like a PIC µC then you have no hope of sampling at 44KHz. Most simple µC have quite a slow sampling rate (like 100's of samples per second).

If you want faster then you'd be looking at using something like a dsPIC which has an actual audio grade ADC in it, or use an audio ADC externally that can send I²S data to a µC that is fast enough to respond to it.

I have done some similar work recently while designing a digitally controlled amp.

I had the output of the first stage of the amp going into an analog input on the controlling PIC to then control a bargraph of LEDs for a simple VU meter.

For an output from a PC soundcard you're probably looking at around 1 to 2 volts voltage swing. For my system I wasn't too fussed about frequency and such - just pure peak amplitude - so I passed the signal through a small shottky diode first to trim off the negative voltages. This simplified my design a whole lot.

I am also designing a small frequency analyzer at the moment, and am looking at having selectable op-amp based band-pass filters based around this design: http://www.wa4dsy.net/robot/bandpass-filter-calc which so far has given quite good results. I am varying some of the resistor values by a combination of digital pots and analog multiplexers.

I would certainly recommend at least protecting your analog input(s) with op-amps to limit the maximum voltage they get - just in case. You don't want a voltage spike blowing up your Arduino now do you? Easier to replace a blown op-amp.

And as for a signal for testing? There are many free signal generators for the PC available for download if you do a little google for them. They will let you select waveform, frequency, amplitude, phase, etc. Even allow summing of waveforms to give new waveforms if you're lucky.

You can even use your PC soundcard as a rudimentary scope as well with the right software and a small home-made probe. There is software and designs around for this too on the net.

Oh, and remember to isolate different stages / voltage levels with capacitors in the audio signal. As a rule of thumb, if I am changing PSU voltage levels, I always introduce a capacitor to isolate the stages. So, I had one on the input signal, one on the stage 1 -> stage 2 (+/-5V to +/-12V power supply), one on the stage 1 -> analog input, and one again on the output. It pays to take no chances with stray DC offsets wandering into the wrong part of the circuit.