Instructables

Arduino Audio Input

Featured
Picture of Arduino Audio Input
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
solder
 
Remove these adsRemove these ads by Signing Up
1-40 of 195Next »
sparkyluki15 days ago

would this circuit work using and electret microphone rather than the radioshack one?

amandaghassaei (author)  sparkyluki11 hours ago

yes it should work with any oscillating signal, but you might need to change the level of amplification to get it in the 0-5V range for the Arduino.

asheble3 days ago

Is it okay if i use an LM741 or LM358 opAmp?

amandaghassaei (author)  asheble11 hours ago

yes

opaulycyesterday

Hi! Great project! I just built it, and I think it is working fine since the clipping LED functions well. I have a question... How can I add a second input audio source? What do I need to add to the last code you uploaded? My intention is to use both audio sources at the same time but with different clipping LEDs.

Thanks in advance!

amandaghassaei (author)  opaulyc11 hours ago

that's a little tricky, you may have to lower the sampling rate to achieve that. It involves changing the code in the setup that puts A0 in continuous sampling mode, you'll have to get into the atmega's datasheet to find the answer. I'm not sure.

thanks for this instructable,

If I want to send this audio signal via bluetooth using BT-Shield, do you have any suggestions what should I do?

amandaghassaei (author)  mabdulaziz11 hours ago
never tried, please post it if you get it to work!
kleina21 days ago

Thanks for your great work. I'm thinking about testing a mono summer circuit before it comes to the opamp stage. However i'm a bit concerned with accidentally feeding more than 5v to the adc.. Would a simple 5v zener do the trick here, tied to the A0?

amandaghassaei (author)  kleina9 days ago

yes that would work

I can only assume because the opamp stage doesn't work with my summed output, but works with each one of my stereo signals.. I need to find an alternative solution (the summer is just a couple of resistors in line with the signal)

sniffrumble1 month ago

I made it yay! although I cannot make the output tutorial since the op amp / chip is now discontinued.... can you please update that tutorial or update where to buy the chip? Thanks!

that's a good point about the op amp, I hadn't thought of that.

super

tpoe21 month ago

I made it yay! although I cannot make the output tutorial since the op amp / chip is now discontinued.... can you please update that tutorial or update where to buy the chip? Thanks!

marxys2 months ago

¡¡excelente trabajo!! :D

asc81172 months ago

best explanation ever. Any newcomer can easily understand.

Can you please guide me about any command/code performing following action...

1. If ADC output count is 0-250 then write HIGH on output pin-1( LOW on others, 251-500 then write HIGH on OP pin 2 etc...)

Thanks again

lynettequek2 months ago

is it possible for the arduino to analogread negative voltage (eg. -5V) input? and change them to become positive numbers?

amandaghassaei (author)  lynettequek2 months ago

no, you will have to offset the voltage before sending it in

Osias Cesar2 months ago

Awesome explanation about the project! I'm wondering if it's possible to using communication (as UART or I2C) whithout decrease the sampling rate, like to tell to the PC every 100ms how much reads it have already did

amandaghassaei (author)  Osias Cesar2 months ago

not sure about UART or I2C, let me know if you try

jiffymanager2 months ago

super

calmlunch3 months ago

good

sheepbars3 months ago

that's a good point about the op amp, I hadn't thought of that.

Scaling from 10 bits to 8 bits may be quicker with bit shifting instead of that extra math:

amandaghassaei (author)  creditrepairaid3 months ago

yes it is! I just wanted it to be clear what was going on :)

cmars43 months ago

is +5 - 0 ok too (the arduino power) for vcc+ and vcc- ? (if we want to amplify bigger input signals ?)

amandaghassaei (author)  cmars43 months ago

I don;t think that will work with the tl082, but you can try

azalesov3 months ago

Should such scheme work with regular input from a mp3 player instead of mic? I constantly getting just 3 values 0 1023 and something around 512. I dont have an osciloscope but it obviously It does not look like a waveform. tripple checked the scheme.

amandaghassaei (author)  azalesov3 months ago

yes it should work with any analog signal. is there a hackerspace near you where you can get on an oscilloscope?

stupsi994 months ago
Awesome tutorial!!! Thank you very much, this helped me a lot! Now I already have an amplified signal, might have to apply DC Offset to it though (not a big problem with your tutorial!) . I would like to record it to an sd card!
I've searched the web and so far couldn't find the right information. The file needs to be able to be played on a computer later. Any idea how to get this done?
amandaghassaei (author)  stupsi994 months ago

use the sd library, here's an example of logging analog data to it.

clickyummy4 months ago

super

raghavlite4 months ago

i tried the fast sampling code and it seems like the serial monitor gets struct up with these setup commands .for now i am testing with giving zero input at the A0 pin .
I copied the whole of your code and executed it.is there anything else i am missing

the code is .........



int a;

void setup()

{

Serial.begin(9600);

Serial.println("started");

delay(1000);

cli();//disable interrupts

//set up continuous sampling of analog pin 0

//clear ADCSRA and ADCSRB registers

ADCSRA = 0;

ADCSRB = 0;

ADMUX |= (1 << REFS0); //set reference voltage

ADMUX |= (1 << ADLAR); //left align the ADC value- so we can read highest 8 bits from ADCH register only

ADCSRA |= (1 << ADPS2) | (1 << ADPS0); //set ADC clock with 32 prescaler- 16mHz/32=500kHz

ADCSRA |= (1 << ADATE); //enabble auto trigger

ADCSRA |= (1 << ADIE); //enable interrupts when measurement complete

ADCSRA |= (1 << ADEN); //enable ADC

ADCSRA |= (1 << ADSC); //start ADC measurements

sei();//enable interrupts

//if you want to add other things to setup(), do it here

pinMode(2,INPUT);digitalWrite(2,HIGH);

attachInterrupt(0,up,FALLING);

// Serial.begin(9600);

a=1;

}

ISR(ADC_vect) {//when new ADC value ready

Serial.println("yes");

// incomingAudio = ADCH;//update the variable incomingAudio with new value from A0 (between 0 and 255)

}

void up()

{

a=0;

}

void loop()

{

Serial.println("aaaa");

if(a==0)

{

Serial.println("0000");

delay(5000);

}

a=1;

}

amandaghassaei (author)  raghavlite4 months ago

remove the line:

Serial.println("yes");

you can't put any commands that take a long time in the interrupt - Serial.print takes a long time to execute.

foobar86755 months ago
This is really excellent Amanda. thank you. I have a few questions
  1. Instead of the mic, I have an old USB mic. Can I use that instead?
  2. I'm having a hard time finding the 47nF cap. Can I use a larger one instead? Or is it not necessary as akellyirl says? If it is, is there a rule of thumb that can be applied to the size of the capacitor to remove the signal noise?
amandaghassaei (author)  foobar86754 months ago

you should be fine w/o the 47nf cap. Does your mic output digital usb data? that will not work, you need to use an analog signal.

mavriksc4 months ago

How is the 0V reference not a short?

bearblue4 months ago

wonderful

raghavlite5 months ago

hello amanda,
that was a great tutorial,can you please tell me how to extend this sampling at 40khz to some other(say 3) analog pin of arduino.

anyway thanks in advance

1-40 of 195Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!