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) Amazon

Additional Materials:

(1x) usb cable Amazon
(1x) breadboard (this one comes with jumper wires) Amazon
(1x) jumper wires Amazon

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>Would the interrupt code be any different for an ATmega 32u4?</p>
<p>Awesome tutorials, been looking at interrupts and timers, this has given me a whole lot more stuff to play with .</p><p>Thank you </p>
<p>Could you please explain your choice of values for the decoupling capacitor. As far as I can tell, the choice is based on the required cut-off frequency and the input impedance of the ADC input using 1/2&pi;RC. Values of input impedance seem to vary from 10k to 100M from different sources. So, what did you consider in designing this circuit? What is the purpose of the 47nF cap?</p>
<p>Thank you so much for blessing us with this basic tutorial!</p>
<p>Used the amplifier portion of the circuit to make a reactively-controlled LED display for my electric guitar. Thanks!</p>
<p>Very cool. I'm building a guitar, myself, and plan on using the arduino as a DSP and LED control. I'm thinking of mounting LED's on the fretboad that are responsive to various frequencies produced by the strings. I'd like to see your guitar when you get it finished.</p>
<p>Ah, confusion. Although I am in fact building a guitar from scratch, the LED panel was meant to be mounted on my amp. Signal gets split between the amp and the LEDs. You can see the project here:<br><br><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/QeGpHfKHnvU" width="500"></iframe></p><p>Here's a pic of the guitar though, just for fun:</p>
<p>That's awesome, even if it isn't on the guitar itself!</p><p>I love that body style. Did you build the body yourself? If so, what wood did you use? I'm planning on building mine out of korina with a maple neck. It will be a Thunderbird style.</p><p>I'm thinking I'm going to have to use two pieces, one for the front, and one for the back, just so I can route out a cavity for all the electronics I'll be using inside of it.</p>
<p>Thanks! I built everything myself out of solid mahogany. That's an interesting way of making a 2-piece body. Most builders use left-right halves instead of front-back. Every hand router I've seen has a depth stop so there are no worries about routing all the way through.</p>
<p>I'm not worried about depth stop. I'm worried about wire routing, and having big enough channels to acommodate bigger wires such as USB or Cat5.</p>
<p>That's impressive! Genius!</p>
<p>I'm building an electric guitar, and I want to mount an arduino inside the body that will receive the signal from the pickups and do signal processing on it (such as reverb, delay, distortion, etc...), and pass it to the output jack of the guitar. It will also have some led functionality. My question is can I use the same op amp for an electric guitar pickup signal that you used for the mic signal, and also, is there a way to write code that will do signal processing on audio signals for the arduino? I plan on utilizing an SD card, as well.</p>
I know old instructable, but I was wondering how much work can I have the arduino do while still checking the audio input?
<p>Great! </p><p>I have a question. How can I change de sampling rate in the code of Arduino?</p>
<p>Hi! Great Instructable, congrats... Now, my question is: Can I do it (or somethink like) on the AtTinny85? Thanks again.</p>
<p>Good question, I want to know! I think it possible in theory, the question is what's the size of the compiled code because of limit memory available on the Attiny. Besides, the Attiny operates at 8 or 16Mhz. </p>
<p>so guys I am trying to make my ardunio turn on or off a led based on if my speaker is playing music or is on but not playing music <br><br>anyone got any tips how I could modify this tut for that or any other links or really any help. </p>
Good day Amanda, I want to ask a question. Can you help me how to input Frequency of 25khz? Thank you.
<p>Hi!<br><br>Is it possible to make the arduino react to the melody of my clarinet as I play the notes?<br>Is there any possibiolity to this without having to record myself previously? Maybe through the microphones the arduino can analyze the melody coming from my instrument?</p>
<p>Could you describe the DC offset part a bit more? Thanks</p>
<p>Thanks so much for this tutorial, it definitely helped clear up some questions I was having about dc-biasing. However, as many diy circuit tutorials do for me, I am left with almost as many (different) questions as I had when I started!</p><p>In your circuit, you use an op-amp that requires a positive and negative voltage power supply. Is there a reason you need this type of op-amp? Powering it via two 9 volts works fine for this example, but in a real work situation, I can&rsquo;t imagine wanting to build something I have to keep running with two 9 volt batteries! How would you change this circuit to run off 9v DC (could you?) or better yet to use the 5v power from the Arduino? As someone who&rsquo;s circuitry experience mostly comes from playing around with DC, these kinds of things in tutorials tend to get me.</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>RexHex,</p><p>Do you mind sharing a diagram of how you wired the project with one 12v power supply?</p>
look to the rason.org link I posted above. it's the schematic I found that uses a single source with the same chip.
<p>Did you utilize the DC offset in addition with the single source?</p>
yes you still need to use the DC offset. the arduino only reads 0-5v so it needs to be offset to 2.5 to get solid data.
<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>RexHex, your link to the Op Amp design page was very helpful! Good addition to this instructable</p>
<p>I am trying to use this but I also want to be able to save the audio file to a micro SD card, can anyone help please?</p>
<p>Nice post. Well detailed and explained. I like how you built up the code, adding optional features with each version.</p><p>The link to the source code is not working. It looks like it was moved to 'SuperAwesomeRobots'. Please update the link for others.</p><p>Thanks.</p>
<p>Hi! Thank you for this really detailed instructable! <br>I am planning on connecting my analogue synth to my arduino. I'm afraid I am a bit of a novice when it comes to this so my question is, once I have input the audio into the arduino using your tutorial, how do I get sound back out of the arduino? I have seen you put up a tutorial on how to do this whilst generating wave forms inside the arudino but I was wondering if there was a way of having the sound come out of my computer speakers? </p><p>Thanks again!</p>
<p>can I use an electret microphone with amplifier(<a href="https://www.adafruit.com/products/1063" rel="nofollow">https://www.adafruit.com/products/1063</a>) to get an audio reading instead of the microphone and circuit?</p>
<p>Hey! Thanks a lot for this tutorial!</p><p>I did it, it works great! Now I'm trying to read stereo signal, but it seems very complicated, since arduino appears to read only one AI at a time... Have you ever made it to work nicely? Because I cannot even read separate signals, even delaying between analogReads.</p><p>Oh, a suggestion: you actually don't need the amplifier. Just set an offset of ~0.5V (R1 = 9xR2) and set analogReference(INTERNAL). :)</p><p>Thanks again!</p>
<p>Can you explain a bit more your suggestion of not using the amplifier, please </p>
<p>Thank you for posting this project. It looks like a very interesting project! However, while making this, I ran into a slight head-scratcher ...</p><p>I set up the circuit like the schematic in Step 4: DC Offset. Feeding into the 10uF capacitor, I have a mono input from my MP3 player with the common from the plug going to ground.</p><p>I loaded the code from Step5: Simple Analog In but modified the setup and loop functions to do some Serial.print's to see what values are being assigned to the variable incomingAudio.</p><p>On my Uno it works fine - I see varying numbers in, what I assume are a reasonable range. However, when I tried to use my Arduino Micro in place of the Uno the code only prints numbers ranging between 494-507 for incomingAudio.</p><p>So I set up my Uno on one breadboard and the Micro on a second breadboard each with their own complete set of components/input circuits. So the boards are exact duplicates except for the Arduino boards. I went over the wiring several times to ensure both were correct.</p><p>The Uno board still works and the Micro does not. So I ran the 5V, gnd, A0 inputs from the Micro board to the Uno breadboard and it the Uno works fine. Then I ran the inputs from the Uno board to the Micro board and still not good. I switched the wires back and the Uno still works while the Micro still refused to cooperate.</p><p>Additionally I compiled the same code from your sample and loaded it to both boards - selecting the correct board/port in the Arduino IDE.</p><p>So I'm not sure why the Micro cannot see/read what is coming into pin A0 when the Uno acts fine. Maybe something different in how the Uno performs the analogRead(A0) vs the Micro?</p><p>My main reason for trying to migrate to the Micro is I have this project working: <a href="https://www.instructables.com/id/Arduino-Powered-Musical-Christmas-Lights/" rel="nofollow">https://www.instructables.com/id/Arduino-Powered-Mu...</a> and now I am trying to migrate to the Micro to use transistors or MOSFETs to switch some 5v DC lights I have. The main goal is to set up a small Christmas tree on my desk at work and run it off a small wall-wart power supply or even a USB type backup battery.</p><p>Any ideas on why the Micro is so fussy?</p><p>Thanks,</p><p> Mike</p>
not sure but the teensy board is a great one. I would buy one of those because its also small and should work just fine.
<p>should I keep my Oscilloscope source as AC or DC, to check the audio signal after dc offset has given ...</p>
<p>Thank you very much for your reply...It helps me a lot...</p>
glad to be able to help. that threw me off for a little bit too.
<p>Hey, I was just wondering can we use PWM pins of arduino for DC offset generation and if so will it be more power efficient?</p>
<p>Thanks a lot Amanda..Mine working fine....</p>
<p>Hi there! Thank you very much for this tutorial. </p><p>I am thinking about implementing a guitar tuner with my Arduino for a class project, but my professor only have access to simple microphones and Grove kits. Do you think that I can determine the sound frequency with that?</p><p>Thank you again!</p>
<p>Hi! Thank you so much for this tutorial. Only one thing I do not get. If I wan to make the VU meter with this, how do I work around the offset? If I just subtract the value and make it absolute the thou out put is far from precise and sometimes its all over the place. Please can someone help me with this?</p>
<p>I might be able to help but I dont understand the question. </p>
<p>excellent thank you</p>
<p>Hi !!<br>I have a project where i want to give input to arduino through 3.5mm cable.<br>i want to play a music on my hone or laptop or ipod and send it to arduino through AUX cable !!<br>Is it possible to detect the beats in the music ?<br>THANKS<br><br>PS : I'm very new to practical electronics </p>
<p>Hi! Thank you so much for this tutorial. Only one thing I do not get. If I wan to make the VU meter with this, how do I work around the offset? If I just subtract the value and make it absolute the thou out put is far from precise and sometimes its all over the place. Please can someone help me with this?</p>

About This Instructable




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: