Send sound into your Arduino.  This Instructable will show you how to prepare audio so that it can be sampled and processed by an Arduino to make sound responsive projects and audio effects.  (This article is a companion to another Instructable I've written about building an audio output circuit for an Arduino, find that here)

Some ideas that come to mind include:

beat detection- trigger lighting effects, build a set of turntables that beat match themselves, or make a robot that dances along with the music you play for it
amplitude detection- make a simple vu meter with LEDS
frequency analysis- you could make a project that reacts to different frequencies in different ways, recognizes certain melodies, turns audio into MIDI data, or translates incoming frequencies into square waves with the tone() library
digital effects boxes/digital signal processing- check out what I did with my vocal effects box (all processing done with Arduino), lots of possibilities here: pitch bending, distortion, sampling, delay, reverb, granular synthesis, mixing, and much more...  I've provided code in this Instructable that lets you sample at up to 38.5kHz.  Here is another instructable describing how to set up a simple audio out circuit with Arduino.
digital recorder- with the addition of an SD card of course (the Arduino has very limited memory by itself), this opens up the possibility of looping large samples and doing lots of other digital manipulations to pieces of stored audio  The circuits and code provided here are compatible with SD card shields that communicate via SPI.
graphical representations of sound- Arduino oscilloscope/visualizer

Feel free to use any of the info in this Instructable to put together an amazing project for the DIY Audio Contest!  We're giving away an HDTV, some DSLR cameras, and tons of other great stuff!  The contest closes Nov 26.

Parts list:
(x1) Microphone Radioshack 33-3038
(x1) TL072 Digikey 296-14997-5-ND or TL082 Digikey 296-1780-5-ND (TL081/TL071 are fine too)  I used a tl082 in my examples
(x2) 9V battery
(x2) 9V battery snap connector Radioshack 270-324
(x1) mono audio jack 1/4" Radioshack 274-340  or Radioshack 274-252 or 1/8" Radioshack 274-333 or Radioshack 274-251
(x1) LED Digikey C513A-WSN-CV0Y0151-ND
(x1) 10kOhm potentiometer linear Digikey 987-1301-ND
(x3) 100kOhm 1/4watt resistors Digikey CF14JT100KCT-ND
(x1) 10uF electrolytic capacitor Digikey P5134-ND
(x1) 47nF ceramic capacitor Digikey P4307-ND
(x1) Arduino Uno (Duemilanove is fine too) Sparkfun DEV-09950

Additional Materials:
22 gauge wire

Step 1: Preparing audio signals for Arduino

If  you've ever recorded audio on your computer, you may have seen it represented as a waveform like the one in fig 1.  If you zoom in on this wave (as in fig 2) you will see that the shape is made of thousands of tiny oscillations back and forth.  This is called an audio signal and when we are dealing with audio signals in electronics, these oscillations represent oscillating voltages over time.

When we look at an audio signal with an oscilloscope, we see a similar picture (fig 3).  Notice how the audio signal in fig 3 oscillates around a center voltage of 0V; this is typical of audio signals.  The amplitude of an audio signal is the distance between its center voltage and its high or low peak.  The amplitude of the wave in fig 3 is 2V: it reaches a maximum voltage of +2V and a minimum voltage of -2V.  This is a problem if we want to measure the audio signal with one of the Arduino's analog inputs because the Arduino can only measure voltages between 0 and 5V.  If we tried to measure the negative voltages in the signal from fig 3, the Arduino would read only 0V and we would end up clipping the bottom of the signal.  In this Instructable I'll show you how you can amplify and offset audio signals so that they fall within this 0-5V range.  Ideally you want a signal with an amplitude of 2.5V that oscillates around 2.5V (like in fig 7) so that its min voltage is 0V and its max voltage is 5V (see the calculations below).

Min voltage = Center Voltage - Amplitude
Min voltage = 2.5V - 2.5V = 0V

Max Voltage = Center Voltage + Amplitude
Max Voltage = 2.5V + 2.5V = 5V

Fig 4 shows the signal coming straight out of the microphone on an oscilloscope.  The signal is relatively weak, with an amplitude of only 200mV, you may find that signals from other sources (ipods, guitars, record players...) also produce audio signals with small amplitudes.  These signals need to be amplified to get them up to the amplitude we want (2.5V).  Amplification means increasing the amplitude (distance between the center point and max or min) of a signal.  Amplification also buffers the audio source (in my case this was a microphone) from any loads that you may put on it later in the circuit, which is a good thing because it prevents distortion.

Fig 5 shows the same microphone signal after amplification, you can see how the height of the peaks has increased so that the wave has an amplitude of 2.5V.  But since the center voltage of the wave is still 0, the wave is oscillating between -2.5 and +2.5V.  It will need to be DC offset to correct this.  DC offset means changing the center voltage that the wave oscillates around (the average voltage of the wave).  Fig 6 shows the signal after it has been DC offset; it still has an amplitude of 2.5V, but the center voltage is 2.5V instead of 0V, so the wave never drops down below 0V.  (Note- the slight change in shape between the signals in figures 5 and 6 is dues to changes in my voice between the two pics, it has nothing to do with the circuit).  The signal in fig 6 is ready to go to an Arduino analog input pin.

<p>Hi! Thanks for this post (and the next ones!) it's just what i'm looking for<br>But, you know you can make the circuit more versatile, by making an adder device where one pin of R1 is the input for the offset, and where is R2 is the input of the signal I fed the OP AMP with +-10V, this circuit amplifies the signal with offset (is an inverter too so thats why I added another inverter at the end)<br>and BTW Can I do a filter with the arduino?</p>
<p>Thank you for posting this instructable, </p><p>This is exactly what I needed to get my LED lamps to start dancing to music. I have been using the arduino to make interactive lamps and have been wanting to get audio into the mix. The concept makes sense about needing a mid range of 2.5v rather than 0v from the original audio source. I have done my best to duplicate what you posted, and it all looks right, but am not getting the best results. </p><p>An absence of audio reads about 190 to 210. Attaching audio with a beat results range from 140 to 1023 when the bass hits. As the bass note goes out it will drop from 1023 slowly back down. What this makes me think of is that I have too much input. </p><p>The POT is a 10kA and with a multimeter I can read it varies between 0v and 1v. This does not make any difference on the audio out of the amplifier. Even if changed the gain I am not convinced I would get a good signal.</p><p>With the multimeter on DCv I can read a range of 0.002 to 0.03v on the original audio source. The multimeter then reads a range of 5v and higher to 0.6v going out of the amp. </p><p>I would like for the POT to fix the gain but I dont know what Im doing wrong. </p><p>Any Ideas out there? </p>
<p>My major issue was that I am using a single supply. I did not understand that your circuit uses two 9v batteries and one is used to ref -9v. After lots of research on op amps, thanks to texas instruments documents, and then finding this gem (http://www.rason.org/Projects/opamps/opamps.htm) I was able to create a fine amplified circuit with one single 12v power source. </p><p>I modified this linked circuit so that R2 is the 10k pot allowing me to control the gain. Everything looks perfect on my oscilloscope which I bought so that I could analyze this circuit. The price was about 30$ on amazon, highly recommend it to anyone who is reading this and does not have one. Here is the link for that.(http://www.amazon.com/JYE-DSO-138-Open-Source/dp/B... </p><p>Now my issue is that I am unable to shift the graph up 2.5 volts so it oscillates between 0 and 5 volts. I have hooked up the arduino for 5v ref with the DC offset and cap just like you have in the circuit you made for this tutorial. My multimeter reads a perfect 2.5v in the junction. My oscilloscope reads the same as it does with out the DC offset oscillating on 0 rather than 2.5v. </p><p>Does anyone have any ideas why adding this 2.5v DC offset is not shifting the oscillation from 0v to 2.5v? </p>
<p>So using the oscilloscope on AC mode will always oscillate on 0v. putting it to DC brings it up to 2.5v. It would have been nice to have gotten a response at some point but Im thankful for this intractable. I hope that my additions may help someone at some point. </p>
<p>Thank you for this Instructable. I'm so excited to get started! I have a question regarding your choice of microphone, though I'm not sure if I read anything pertaining to it in particular. Would it be possible to use an electret microphone? Perhaps something similar: https://www.adafruit.com/products/1063</p>
<p>Hi , I have builded the same circuit and i have used the copde which mentioned in Arduino frequency detection.</p><p>And Can see -1hz always in serial as an ouput,what could be the reason,Kindly help.</p>
<p>hi </p>
<p>Amazing Instructable! Thanks for sharing! really nice!</p>
<p>What arduino board are you using?</p>
<p>Hay amanda</p><p>Great instructable. I would like to seek your help for taking this one step further. I am working on a project that carries out some audio processing from a mic and another audio input at the same time and outputs them to two separate DACs, so i would need to use two analog pins (say A0 and A1 for mic input and the other audio input respectively), and use two of the arduino ports(say D and B) as the DAC. Your code for using the interrupts on pin A0 was difficult for me to understand how I could use the same thing for pin A1. which part of the code in the setup() that specifies which pin to sample from. </p>
<p>Hello, great tutorial, question regarding the audio output portion, i have built the R2R ladder in your other tutorial and upon hooking it up, i notice that the audio coming out is +/- about 100mv for some reason (the input i have verified with my oscilloscope at 0-5v) but the code for both the 10 and 40k processing output the audio to the ladder at a significantly lower voltage, anyone else have this problem? thanks in advance</p>
What does the 47nF capacitor do?
<p>This 47nF capacitor is called a bypass capacitor, its role is to filter out to ground undesirable AC noise that is inherent to any circuit. In this case it is important to have it here so that this noise is no mixed with the input signal. This page gives a good description of what they are and how they fit in a circuit: http://www.seattlerobotics.org/encoder/jun97/basics.html</p>
<p>I enjoyed reading this instructable, as I just today experienced the effect of a missing DC offset with my mic input to my Arduino. Great work!<br>However, I also stumbled over the AC bypass cap: Isn't 47nF an order of magnitude too large for audio signals in this case? If I am not completely wrong, the bypass cap forms a low pass with the 50k impedance of the voltage divider (again parallel to the Arduino's input impedance which should be negligible here). The 3dB point of such an LPF is ~68Hz. Wouldn't it be better to take a value in like 220pF or even smaller? That would increase the 3dB point to be higher than 10kHz at least.<br>I am asking this not to be pedantic, but I am just still learning basic electronics and therefore try to analyse building blocks like RC filters when I come across them. It could be that I made a fundamental mistake here, something that renders my result completely wrong. So I would be really happy, if someone could explain to me, if and why I am wrong! :)</p>
<p>there is still noise in my input. how do i fix it? as you said the capacitor function to filter the noise. but mine is still unstable</p>
helps remove noise in the input signal
<p>Hey Amanda, I haven't yet had time to go through all of the comments so I apologize if you have already answered this.</p><p>I've done everything in your instructable and it works fantastically, thank you for such a detailed walk through, it definitely helped. What I'm not trying to do is manipulate a LED's with certain audio frequencies and I was wondering if you know how I could go about doing this. I am trying to make three output lines reacting with low, mid, and high frequencies. Should I use byte reading and select a range for each and depending on the byte data, it determines which pins are output?</p>
<p>Do you mean you want to have an LED to indicate high, medium and low frequency volumes? It wasn't too clear from your comment. If you want to do that, you need to run a FFT (Fast Fourier Transform) on the incoming signal, which lets you see the incoming frequencies, and then average the frequency bands you want to use as 'high', 'medium', and 'low'.</p><p>I think these could help you a lot:</p><p><a href="https://learn.adafruit.com/piccolo" rel="nofollow">https://learn.adafruit.com/piccolo</a></p><p><a href="https://learn.adafruit.com/fft-fun-with-fourier-transforms" rel="nofollow">https://learn.adafruit.com/fft-fun-with-fourier-tr...</a></p>
<p>A simple way to use only one 9 volts bat:</p><p><a href="https://drive.google.com/open?id=0B2Nd3eQ---IJUEpZVy0yQU1TWHc&authuser=0" rel="nofollow">https://drive.google.com/open?id=0B2Nd3eQ---IJUEpZ...</a></p>
<p>Hello!</p><p>my question may sound dumb but can you please let me know where to connect the probes of oscilloscope to get the figure 1 in step 5(simple analog input) ?</p><p>and am i supposed to enter the following code to get the results of figure 1 step 5?</p><p>int incomingAudio;</p><p>void setup(){</p><p> for (byte i=0;i&lt;8;i++){</p><p> pinMode(i,OUTPUT);//set digital pins 0-7 as outputs (DAC)</p><p> }</p><p>}</p><p>void loop(){</p><p> incomingAudio = analogRead(A0);//read voltage at A0</p><p> incomingAudio = (incomingAudio+1)/4 - 1;//scale from 10 bit (0-1023) to 8 bit (0-255)</p><p> if (incomingAudio&lt;0){//deal with negative numbers</p><p> incomingAudio = 0;</p><p> }</p><p> PORTD = incomingAudio;</p><p>}</p>
<p>Its terrific</p>
<p>Its superb</p>
<p>the frequency appeared on my serial monitor is kind of unstable. how to solve this? arduino still get the measurement even if i don't connect with the mic. can someone help me?</p>
<p>Hi! Is it possible to replace the microphone with piezo pulse? right now, i'm doing sthetoscope and want to collect sound from the lung. Is it possible to do so? ty</p>
<p>Thanks for this instructable. I've managed to get the sampling rate up to 153.8ksps with a prescaler of 8 (16Mhz / (13 * 8)). Any lower and the reading become unreliable.</p>
<p>Hi, can i use this on my guitar tuner project</p><p> for acoustic guitar. TY </p>
<p>i am also having problem using wire in accoustic guitar. Do you know the solution ?</p>
<p>Thats tremendous</p>
<p>Hi all I have written a <a href="http://yaab-arduino.blogspot.com/2015/02/fast-sampling-from-analog-input.html" rel="nofollow">post on my blog</a> to discuss the same topic just focusing on achieving higher ADC sampling rates.</p><p>Hope you find it useful.</p>
<p>Amanda, thanks a lot for <br>sharing your knowledge, i learned A LOT from this project, how to design using a <br>standalone microcontroller (without using an arduino board), how to how to process <br>the signal, how to design a PCB in altium designer, and finally how to send a <br>PCB to a fab house, it took me around 2-3 weeks to understand all the perfectly <br>clear explained details in both your entry&rsquo;s plus the time to make it happen, i could have done it in a breadboard but, wheres the fun in that?! I finally did it thanks to you, along with my 1stmanufactured PCB</p><p> and it works perfectly fine, thanks a a lot Amanda</p>
<p>Very useful instructable thanks! Got it working pretty quickly. I decided to try and implement an auto gain adjust by replacing the 10k pot with a digital SPI pot (MCP41010-I/P-ND) and it kind of works but I am seeing a strange artificial clipping at some DC bias value. The SPI pot is powered by the Vcc and Gnd from the Adruino. Replacing the SPI pot with manual one set at the same value as the SPI pot gives a perfect full audio wave. I was testing with a 1KHz audio tone.</p>
<p>what are you using fro an oscilloscope?</p>
<p>You may be exceeding the max current of the MCP41xxx at wiper extremes, though it's hard to speculate. At any rate you could try substituting a variable-gain (VGA) op-amp like an LMH6505. This wouldn't be directly SPI controllable like the MCP, but you can tie the gain input pin on the 6505 to an Arduino analog out pin to control gain programatically.</p>
<p>Thanks, ended up using Programmable Gain Amp from microchip with SPI interface. MCP6S22.</p>
<p>Hi, I am trying to implement Automatic Gain Controller using Ardunio. </p><p>Have you implemented your &quot;Auto Gain Adjust&quot; ? Can you please send me the documents or necessary instructions to make this successful asap. </p><p>My mail ID: kuet0909011@hotmail.com</p>
<p>I apologize for being a newbie! First, this is a great tutorial. </p><p>I have a newbie question about voltage. If I'm running off a straight 9volt wall wart (with line condition) will that be enough and do I need to change the circuit at all? </p><p>Still don't understand the. +- 9 volt but I'm researching that! </p>
<p>Hi Amanda,</p><p>Many thanks for this instructable. </p><p>What commands should I use to get the full 10 bits from ADC? I understand that it takes twice as much to read, I would be happy with a sample rate of 16 KHz. The analogRead() would be too slow, as I understand, 8 KHz is not enough. </p>
<p>Sorry, forgot to say before, my query is regarding the 40 (38) kHz configuration.</p>
<p>How far don CAN i scale the clock and still use the interrupt?</p><p>Can I sample at 10k?</p>
<p>How far don CAN i scale the clock and still use the interrupt?</p><p>Can I sample at 10k?</p>
<p>Hi Amanda,</p><p>First of all, thank you for writing such a detailed instructable. </p><p>If you have time and still monitor this thread, I would quite like to understand what is actually going on in the setup code and was wondering how you came up with this solution, how did you approach the problem and did you acquire all of the information you needed for configuring the uno chip from the datasheet alone or did you use multiple sources?</p><p>Thanks once again.</p>
<p>Sorry, forgot to say before, my query is regarding the 40 (38) kHz configuration.</p><p>Thanks</p>
<p>I am working on a similar project but can't seem to figure out how to write to an SD card fast enough, could you share your SD card code as well? I have been using the SD.h library, but it is just too slow for audio.</p>

About This Instructable


576 favorites


Bio: I'm a grad student at the Center for Bits and Atoms at MIT Media Lab. Before that I worked at Instructables, writing code for ... More »
More by amandaghassaei: OTCA Metapixel - Conway's Game of Life "9 Degrees of Freedom" IMU Twitter Controlled Pet Feeder
Add instructable to: