Cheap Sound Sensor for AVR

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

Here is the code. It is just hacked together and has lots of room for improvements.

/* -----------------------------------------------------------------------
 * Title:    sound sensor
 * Author:   Alexander Weber
 * Date:     19.05.2007
 * Hardware: ATmega8
 * Software: WinAVR 20060421
 * 
 */

#include <inttypes.h>
#include <avr/io.h>
#include <util/delay.h>

#define LED_BIT PD4

/*
 * get_adc
 * Return the 10bit value of the selected adc channel.
 */
uint16_t get_adc() {

	uint16_t value;

	// warm up the ADC, discard the first conversion
	ADCSRA |= (1 << ADSC);
	while (ADCSRA & (1 << ADSC)); 
	value = ADCW;
	
	ADCSRA |= (1 << ADSC);				// start single conversion
	while (ADCSRA & (1 << ADSC)); 		// wait until conversion is done

	return ADCW;
}

int main(void) {

	uint8_t i = 0;
	
	DDRD |= 0x1c;	// PD2-PD3: col 6-7, PD4: debug LED

	// select channel
	ADMUX = 5;

	// ADC setup
	ADCSRA = 
		(1 << ADEN) |						// enable ADC
		(1 << ADPS1) | (1 << ADPS0);		// set prescaler to 8	
			
	// say hello	
	for (i = 0; i < 5; i++) {
		PORTD |= (1 << LED_BIT);
		_delay_ms(10);
		_delay_ms(10);
		_delay_ms(10);
		_delay_ms(10);
		_delay_ms(10);
		PORTD &= ~(1 << LED_BIT);
		_delay_ms(10);
		_delay_ms(10);
		_delay_ms(10);
		_delay_ms(10);
		_delay_ms(10);
	}
	_delay_ms(10);
	_delay_ms(10);


	while (1) {
		
		if (get_adc() > 180) {
			PORTD |= (1 << LED_BIT);
			_delay_ms(10);
			PORTD &= ~(1 << LED_BIT);
		}			
		
	}

	return 0;

}

Video

The video got lost :(

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 Comments

  1. 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.

    Like

  2. 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

    Like

  3. 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.

    Like

  4. 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.

    Like

  5. 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
    https://tinkerlog.com/2007/10/22/diy-tengu-on-a-breadboard/ for a more integrated amplifier.
    Cheers,
    Alex

    Like

  6. 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

    Like

  7. 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?

    Like

  8. 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

    Like

  9. 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.

    Like

  10. 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.

    Like

  11. 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

    Like

  12. 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

    Like

  13. 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

    Like

  14. 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

    Like

  15. 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

    Like

  16. 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…

    Like

  17. 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:

    DSCF6009

    Like

  18. 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!

    Like

  19. 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.

    Like

  20. 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.

    Like

  21. 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?

    Like

  22. Hello,

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

    Like

  23. 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?

    Like

  24. 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?

    Like

  25. 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.

    Like

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

    Like

  27. 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?

    Like

  28. 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

    Like

  29. 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?

    Like

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

    Like

  31. 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?

    Like

  32. 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

    Like

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

    Like

  34. 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

    Like

Comments are closed.