Tinkerlog header image 2

Tinkerlog

Alex’ blog

Cheap Sound Sensor for AVR

May 20th, 2007 · 68 Comments · avr, sensor, sound

I searched the web for a cheap method to let the ATmega respond to sound. My knowledge in analog circuits is very limited, but what I do remember, is that you can not attach a electret mircophone to a controller pin. The signal of the microphone is just too small and has to be amplified. There is much of information out there, especially on diy amplifiers. I stumbled upon this little circuit here. It consists only of a handful of components:

  • 2 resistors 10k
  • 1 resistor 100k
  • transistor 2N3904
  • 1 capacitor 0.1u
  • electret microphone

Prototyping the amplifier

Putting things together on a breadboard.

IMGP1255

Actually I had no 2N3904 around, so I replaced it with a BC337. The circuit is a emitter circuit with voltage degeneration (I dont know if that exists in english). I dropped the couple capacitor and took the signal right away at the collector.

Prototyping with the ATmega

The sound sensing is done with the ADC of the ATmega. A simple program reads the analog value of the amplifier over and over. If the value (loudness) exeeds a specific level, an LED is lit.
IMGP1253

The schematic for rebuilding.
mic-schematic

The code can be found here mic_sensor.c. It is just hacked together and has lots of room for improvements.

Video

Here is a video that I made. Has lousy quality, for both, video and audio.



Click To Play


Conclusion

It was easy and worked pretty well. I enjoyed looking at the LED responding to the music. I haven’t recorded anything with this amplifier, it might sound awfull. Next steps could be playing the sound back or be able to analyze the sound (FFT). And (re-)learning more on analog circuit design.

Links

68 responses so far ↓

  • 1 Alan // Aug 22, 2007 at 00:05

    Nice job, it seems to follow the music quite well!

  • 2 Philippe // Oct 23, 2007 at 14:23

    30 years ago I built something like that… it was all analog and involved lighting a 115v bulb.
    Funny thing is that it probably cost more to build at the time.

  • 3 Justin // Nov 12, 2007 at 05:29

    Thank you so much for the link to the schematic for the mic and LED, I have made a 4X4X4 RGB LED cube that is going to go to sound but I had no way to read it, I just got the parts and it works great. I have to code the LEDs though. Thanks a lot,
    Justin

  • 4 alaa // Jan 10, 2008 at 17:30

    I need small sound sensor can sense high noise, working by battery, working in open area(high limitation). the output of this sensor is a sound also as handset or small speaker without display screen or indication lamp.
    for example: i use hanset in my ears to say to me how the noise level is.

  • 5 odiernod // Jan 24, 2008 at 18:09

    I put this circuit together too and am happy to say that it works just fine, however, “how” does it work? What is the capacitor for? Why is there a resistor in parallel with the base and collector of the transistor? I am used to using transistors in switching applications, however I am interested in why this circuit can do what it does.

  • 6 Alex // Jan 24, 2008 at 20:08

    Hi odiernod,
    cool that it worked for you!
    The capacitor is used to decouple the mic from the transistor. It is used to transmit only the changes in voltage. I am quite sure that the resistor is used to adjust the amplification, but my knowledge in analog circuits is quite limited.

    You can also take a look at
    http://tinkerlog.com/2007/10/22/diy-tengu-on-a-breadboard/ for a more integrated amplifier.
    Cheers,
    Alex

  • 7 odiernod // Jan 25, 2008 at 06:54

    I made a colorful lamp out of my sound sensor circuit. No singing faces or anything, but it still looks cool. I’ll post a vid sometime next week or so.

    Dom

  • 8 Azda // Jan 26, 2008 at 17:30

    hi, i am interested in building this for a school project and i am wondering if this simple circuit will work as it is on its own?

  • 9 Alex // Jan 26, 2008 at 20:00

    Hi Azda,
    what do you mean by “work as it is on its own”?
    It can be powered by batteries, then it will work on its own.
    If you mean, if it could work without the microcontroller, yes, I think it would work. You have to attach another transistor to the collector of the first one and use it as a switch to control the LED. I haven’t tested that, but it could work.
    Cheers,
    Alex

  • 10 Azda // Jan 26, 2008 at 21:09

    thanks for the help alex

  • 11 Azda // Jan 28, 2008 at 16:56

    would a MIC1 work with this circuit, and could you possibly post/send images of this circuit bread boared on its own- as on the top image without the microcontroller using a battery.

  • 12 Michael H // Mar 18, 2008 at 17:16

    Alex,
    I know this is a little off topic, but I’m not finding answers elsewhere. Can you help me figure out how I could use a setup like this with a 12V neon car light? (4 ft, and I think probably 2.5 amps?) I know this is possible, I just am unsure of what to change.

    Thanks for the off topic help.

  • 13 Alex // Mar 18, 2008 at 23:32

    Hi Michael,
    hmm, not sure about a 12V setup. You will need really powerful transistor to switch 2.5 amps at 12V. I am not into analog electronics, more microcontrollers. But I am sure you wont need the microcontroller for your purpose.
    Cheers,
    Alex

  • 14 karim // Mar 23, 2008 at 08:33

    is this circuit can be used to detect alarms without any false indications

  • 15 Alex // Mar 23, 2008 at 08:43

    Hi karim,
    yes, I think it can be used as sensor for an alarm.
    Without any false indications? That depends on your environment.
    Cheers,
    Alex

  • 16 karim // Mar 23, 2008 at 08:56

    Thank you very much

    i’m really amazed of your fast response

  • 17 BIGBUG // Apr 20, 2008 at 23:02

    THANK YOU! This little circuit, with a few minor changes, is just what I was looking for to add bidirectional hearing to my oobug robot. Was looking for something for weeks.

    Ted
    Savage Innovations
    http://www.oobug.com

  • 18 Alex // Apr 21, 2008 at 00:28

    Ted, great to hear that. I am waiting to see the final result.

  • 19 BIGBUG // Apr 21, 2008 at 04:29

    Alex,

    Could you share the part number for the electret you used in this project?

    Have you done any experimenting with the sensitivity of the circuit?

    Ted

  • 20 Alex // Apr 21, 2008 at 07:42

    Ted,

    here is the link for the mic http://www.reichelt.de/?;ACTION=3;LA=4;GROUP=IA2;GROUPID=3604;ARTICLE=11357;
    The id is “MCE 100″.

    No, I haven’t done anything with the sensitivity.

    Cheers,
    Alex

  • 21 Reece // Jun 10, 2008 at 16:42

    Wait a minute…In the instructions it says ‘electret microphone’, but in the schematics there are only TWO connections to the microphone shown. Is it an electret or a condenser mic? I’m confused…

  • 22 Alex // Jun 10, 2008 at 18:57

    Hi Reece,
    following Wikipedia http://en.wikipedia.org/wiki/Electret_microphone it is an electret microphone which is a subtype of a condenser microphone. The one that I used has only two connections.
    Cheers,
    Alex

  • 23 Reece // Jun 26, 2008 at 04:47

    Ok. So I THINK I found the right microphone element in my box of goodies (old circuit boards from random stuff). I got it from an old cordless phone. I built the circuit for a project I’m doing. I haven’t tested it yet, though…

    Here is a pic of the completed circuit:

    http://www.flickr.com/photos/7507189@N04/2612530416/

  • 24 Reece // Jun 26, 2008 at 16:01

    Yup. It works great. The butter zone trigger value is ~150 from the ADC. Great circuit; it’s so simple and I didn’t even need to make a complex op-amp one with all those capacitors and resistors. Great for a simple electronic ‘ear’ that can recognize simple handclaps. Thanks for the simple design!

  • 25 Alex // Jun 26, 2008 at 20:35

    Great to hear that it works.
    Kudos for the design goes to Andrew, who posted the design on Reconn’s world.
    http://www.reconnsworld.com/forum/read.php?9,10

  • 26 Reece // Aug 21, 2008 at 03:10

    I’m making another one of these, but this time I need it to be more sensitive. What can I do to increase the sensitivity? Thanks in advance.

  • 27 Alex // Aug 22, 2008 at 07:56

    Reece,
    the amplification is dependent on the transistor. You can try to find others with a higher gain. Another option is to use two transistors or start with op-amps.

  • 28 Reece // Aug 22, 2008 at 18:15

    I know of some op-amp circuits, but I want to keep this simple. Will adding a second transistor essentially double the sensitivity? How do I modify the circuit to accept another 2N3904 transistor? OR what other transistor can I use that is easily attainable (aka via radioshack). A 2N222?

  • 29 아두이노를 위한 초저렴 사운드 센서 - Suapapa’s Blog // Sep 16, 2008 at 02:19

    [...] 찾기 힘들었는데- 위 기사의 도움으로 드디어 찾았습니다. 만세! 그 블로그 포스팅의 회로도 중 사운드 센서 부분만을 다시 정리하면 아래 회로도와 [...]

  • 30 Justin // Mar 26, 2009 at 13:46

    Hello,

    Was just wondering if this circuit would work with an arduino board?

  • 31 Alex // Mar 26, 2009 at 19:22

    Hi Justin,
    yes, that should work.
    Cheers,
    Alex

  • 32 QuantumKate // Apr 3, 2009 at 19:10

    Ok folk. New problem. Does anyone have any idea how to make this, only a lot smaller. (Small enough to fit inside 3/4″ pvc pipe). Any suggestions?

  • 33 Bogdan // Apr 22, 2009 at 13:34

    I want to measure the output of the microphone. What does the input read on the ADC represents? Decibels? A digital representation of the analog input with no measuring unit? I need to measure it in a international sistem unit, for example decibels, or something else. Can u please explain how can i do that? What to do with the ADC input?

  • 34 Alex // Apr 22, 2009 at 15:19

    The ADC measures the voltage on the pin and converts it to a digital value. The range is 10 bit, 0 to 1023 for 0 V to 5 V, if you use 5 Volt VCC. If you want to measure decibels, that would depend on your microphone, how much voltage it puts out for a given decibel value.

  • 35 Bogdan // Apr 23, 2009 at 19:25

    i am using the MCE-100 microphone…

  • 36 Lee // Jul 22, 2009 at 22:00

    I was looking at your code and was curious on how the .h file look like (avr/io, util/delay, and inttypes)

  • 37 Alex // Jul 22, 2009 at 22:36

    These are part of the avr-gcc toolchain.

  • 38 Josh // Sep 26, 2009 at 00:08

    Hi,

    I just built a copy of this circuit and whilst it appears to amplify the mic, it doesn’t give anywhere near the kind of response yours does in the video.

    I’m using the 2N3904 and it gives me an ADC value of around 800 (using 10-bit mode). If i blow on the mic the value changes (so it’s definitely recieving input) but that implies it’s only responding to massive levels of noise.

    Reckon the microphone is narked or have i just built the circuit incorrectly..?

    What kind of ADC result do you get from your mic if you talk into it?

  • 39 Alex // Sep 26, 2009 at 08:09

    Hi Josh,
    this is a very limitted amplifier.
    If I remember it correctly, I had values around 150, so maybe there is an error in your circuit.
    If you want a circuit, that is more sensitive, you have to look for a more complete amplifier circuit, e.g. this one, using a piezo: http://www.nerdkits.com/videos/sound_meter/
    Cheers,
    Alex

  • 40 James // Oct 13, 2009 at 14:16

    Hi, I bought a sound sensor which was attached to 2 neon light tubes. There is a transformer circuit just before the input to the lights. I think I had somehow damaged part of the circuit when I was trying to replace the neon light with LEDs. Is there anyway I am able to remove the transformer circuit?

  • 41 teguhginanjar // Mar 10, 2010 at 12:25

    thank u..
    i was make it,
    it works..

  • 42 purpulhaze // Apr 14, 2010 at 03:35

    I was wondering how well something like this would work for a flickering blowout led candle.

  • 43 alex // Apr 20, 2010 at 13:44

    Hi, Thank You for sharing Your project. I am about to do something similar. I want to use that curcuit with more than 1 led – 8, would that be enough sensitive to catch noise in this resolution?

  • 44 Alex // Apr 20, 2010 at 19:13

    Hmm, I doubt it. Maybe a piezo is better for that. Try this one: http://www.nerdkits.com/videos/sound_meter/

  • 45 smart // Jun 8, 2010 at 21:04

    Hello Alex!
    I would like to thank you for wonderful site, your work is very interesting to me! I have read almost all your blog, unfortunately I do not speak english very well and my reading speed is low.
    I would like to ask your advice. There is an idea to implement audio spectrum analyzer, with the LEDs. I found many interesting videos on youtube, but could not find a single implementation. As I understand I the need to expand the program signal into its component frequencies. Perhaps you will come across such an algorithm or similar device, or may be you have had experience in developing such devices.

    Regards,
    Aleksey

  • 46 Alex // Jun 9, 2010 at 09:50

    Hi Aleksey,
    thanks! If you want to do a full spectrum analyzer, take a look at this: http://elm-chan.org/works/akilcd/report_e.html
    It’s all assembler if I recall correctly.
    Cheers,
    Alex

  • 47 smart // Jun 9, 2010 at 20:06

    Thanks you! I try to understand! :)

  • 48 niladri // Sep 17, 2010 at 07:33

    hi..
    i want to make a car which will move with sound sensing.. can you help??

  • 49 Designing Simple Sound Sensor Circuit Diagram | Schematic Wiring | Electronics Circuit Diagram // Oct 14, 2010 at 17:37

    [...] following page outlines detail description and explanation on how to design a Simple Sound Sensor Circuit Diagram [...]

  • 50 Marcel // Mar 8, 2011 at 15:19

    Hi Alex, can you hep me with some advice on how to add ADC part to this circuit so i can put it into the Arduino Digital ports..

    Thank you for this great circuit..

    Marcel

  • 51 Amitabh // Apr 13, 2011 at 02:05

    Hello all, Interesting post.
    Hereis what I am looking for. Did analog circuit design 25 years ago. Looking for up to date methods:

    I have an Alpine card CD receiver that has an Interrupt lead. I would like to take an iPod headphone out and generate a trigger from a circuit every time there is audio on the headphone jack. the trigger signal wil be connected to the interrupt lead on the head unit. I also need to hold the lead high for say 1-4 seconds once the headphone out goes higher than a preset value.

    How do I do this?

    Thanks in anticipation. Cheers. -Amitabh

  • 52 Pieter // Apr 21, 2011 at 10:11

    Hello Alex,

    Great tutorial, very well explained! I tried to recreate the setup, but it doesn’t work very well. It only responds when I blow into the speaker.

    I used exact the components you described at the beginning, including the 2N3904.

    One difference, but I don’t know if it matters: my electret is connected via two cables of about 20 cm. Could this influence the gain? Any other idea why my preamp performs so badly?

    Thanks!
    Pieter

  • 53 Alex // Apr 30, 2011 at 09:07

    Hi Pieter,
    the gain of the original circuit is really really small. Try to log the values you get while it’s silent. Then log the values while you are blowing or playing loud music. Maybe that can help.
    Otherwise you may want to choose another circuit with more gain.
    Cheers,
    Alex

  • 54 NOOR // May 21, 2011 at 10:03

    Hey!
    just a simple question the output should be analog or a trigger ?!

  • 55 Alex // May 21, 2011 at 10:10

    The output is analog but I needed only a trigger.

  • 56 Vignesh // Aug 19, 2011 at 16:10

    Hey, great tutorial! I’m thinking of recreating it, though not exactly the same.. Could you tell me if you really need capacitors C2 and C3 which are connected to ports 9 and 10 on the schematic above? Also, is Q1 needed? I’m thinking of using making the following circuit, connecting the “Output to next stage” to an ADC pin, and a servo to an output pin. http://www.reconnsworld.com/audio/simplepreamp.gif

    Thanks for your time,
    Vignesh R.

  • 57 Raj // Aug 29, 2011 at 10:17

    Hi,
    I have no knowledge in microcontrollers but i can work with labview. I am searching for sound sensor that hear the noise from a pump. Do you have any idea to do this. I had a pump that can give noise when inside the storke is touched to mechanical parts. I need to adjust it by using sound sensor. Can you help with any idea,

  • 58 anzal // Dec 9, 2011 at 14:04

    yaa i have no idea about sound sensor.may i know how much money should i have to spend for this projet??

  • 59 Alex // Dec 24, 2011 at 10:08

    It’s only a couple of bucks. Only cents if you don’t count the microcontroller.

  • 60 Moritz // Jan 15, 2012 at 14:54

    Hi,
    thank you for this great setup. We built a RGB-LED Controller in a project and I added the Sound Sensor. We used only SMDs, so I choose the MMBT3904 instead of the 2N3904. Well, it does work. But I have the same problem as Josh(#38). My ADC output value is allways around 800 (10bit). And it only varies about +/- 10 when I play some sounds, so it is very tricky to find the right trigger level. What is your difference between silence and sound? I used an MCE101 instead of the MCE 100 but the only difference should be the cable… Has anyone an idea what could cause my high level?

  • 61 Moritz // Jan 15, 2012 at 15:26

    Sorry for the double post.
    It works just fine with a value of 800 now!
    My problem was, that I sent every single value to my console with printf and therefore the programm was to slow. Now it is really sensitiv, even to the sound of me writing on my keyboard!
    Again thank you for this real simple but great sound sensor!

  • 62 saqib // Jan 30, 2012 at 17:46

    hey, i was jus wondering if i can put the output from the amplifier into an arduino uno?

  • 63 Krzysiek // Jan 30, 2012 at 23:34

    The diffrence between adc output is probably caused by AVREF specification. In atmega88 u can choose between AVcc/1.1V/AREF . I calculated aprox values with diffrent VRefs and thats what i got:

    for AVcc ~ 176
    for 1.1V ~ 800

    the formula is very simple ADC = AIN/AVREF * 1024

    PS. I used BC337 and output voltage was 0,86V.
    PS2. Nice and simple amp :)

  • 64 Cory // Feb 16, 2012 at 07:36

    In the tutorial, you say you used 2 capacitors at 0.1uF but, i only see one in your design and schematics. Where is the second one located (if there is a second)?

  • 65 Alex // Feb 16, 2012 at 08:20

    You’re right, it’s only one.

  • 66 Designing Simple Sound Sensor Circuit Diagram | Circuit diagram wiring // Mar 19, 2012 at 20:50

    [...] following page outlines detail description and explanation on how to design a Simple Sound Sensor Circuit Diagram [...]

  • 67 Luu // Mar 27, 2012 at 11:11

    Hi Alex,I measured the output of the BJT used VOM and found it to stand still in a position (with sound-needle run).
    The sound sensor true or false? I don’t connect with AVR,i just test by voltage-VOM!
    PL help me,thank for your watching my question!

  • 68 Alex // Mar 30, 2012 at 13:43

    Hi Luu,
    you probably can’t see changes on a voltmeter because it’s too slow and the changes are too small.
    Cheers,
    Alex