Feedback!

Electret Ear

Views: 6696 Difficulty: 2 Status: Complete
Electret_ear_main

A breakout board for an electret condenser microphone shaped like an ear.

To get the sound values from an electret microphone into an arduino you have to amplify them. We use these mics in a ton of our projects. This ear-shaped board uses the LM386 amplifier (and a couple resistors and capacitors) to give a nice arduino-detectable signal. See the code below on how to detect volume from the analog waveform. You can get your own ear-shaped board at our store. Sparkfun also offers a condenser microphone breakout board similar to ours in terms of the schematic, but theirs doesn't look like an ear! Adafruit also offers a breakout board and theirs has adjustable gain.

Silkscreen Ear

Screen_shot_2013-01-17_at_10.06.12_pm
Onomatopoetic electronics look like what they do. This electret condenser microphone breakout board looks like an ear because it can listen!

Printing Sound Level to the Serial Port Electret Breakout Board Video

Our electret ear hooked up to an arduino via an analog in pin, hooked up to a laptop via USB printing out the sound values to the serial port.

Arduino Code to Detect Volume from Sound Buffer

This little code snippet listens to the analog pin 0 stores ten values in a buffer and outputs the range of that buffer to the serial port. If you have an audio amplifier circuit hooked up to the electret condenser microphone then this code tells you the volume of the noise the mic is picking up. The function that finds the range of the buffer goes like this
  int find_range(int* array, int length){
  int minimum = array[0];
  int maximum = array[0];
  for(int i = 1; i < length ; i++){
    if(array[i] < minimum) minimum = array[i];
    if(array[i] > maximum) maximum = array[i];
  }
  return maximum-minimum;
}
Why can't we just output the current value of the microphone input? Because sound is a wave, and the volume is the amplitude of that wave. Any single reading from the microphone represents the sound wave at one moment in time. To find the volume, we look at the sound wave over several moments in time (this is the buffer), then we find the range of the buffer using the function above. We have to find the range of
/* LucidTronix Electret Condenser Microphone 
 * http://www.lucidtronix.com/tutorials/22
 * Prints out the range of the noise buffer
 * The range of the buffer roughly represents
 * the amplitude of the sound wave, 
 * So you can use this code to detect sound volume.
 */
const int buffer_size = 10;
int noises[buffer_size];
int cur_index = 0;
int microphone_pin = 0;
void setup() {
  Serial.begin(9600);
}

void loop() {
  // read the value from the sensor:
  noises[cur_index] = analogRead(microphone_pin);
  cur_index = (cur_index + 1) % buffer_size;
  int range = find_range(noises, buffer_size);  
  Serial.print(range);
  Serial.print("   ~    ");
  Serial.println(noises[cur_index]);
  delay(200);
}

int find_range(int* array, int length){
  int minimum = array[0];
  int maximum = array[0];
  for(int i = 1; i < length ; i++){
    if(array[i] < minimum) minimum = array[i];
    if(array[i] > maximum) maximum = array[i];
  }
  return maximum-minimum;
}

Download Arduino Code for Volume using Electret Microphone

Download the Arduino code from above.
Click Here to Download: Download Arduino Code for Volume using Electret Microphone

Download EAGLE files and code

Click on the button below to download a zipped archive of the EAGLE files and some arduino code to get sound into you projects.
Click Here to Download: Download EAGLE files and code

Parts

Title Description # Cost Link Picture
Electret Ear PCB Ear shaped electret condenser mic breakout board. 1 $4.0 Link Screen_shot_2013-02-15_at_6.34.37_pm
Electret Condenser Microphone MIC COND ANALOG OMNI -44DB Value: -44dB ±2dB 20Hz ~ 20kHz 1 $0.96 Link Screen_shot_2012-12-28_at_7.35.36_pm
LM386M IC AMP AUDIO PWR .325W AB 8SOIC Value: 4 V ~ 12 V 1 $0.91 Link 8-soic_751
Capacitor CAP CER 10UF 10V Y5V 0805. Ceramic Capacitor. Value: 10µF 3 $0.16 Link 0805(12_5mm_thickness)
Resistor Chip Resistor - Surface Mount RES 10K OHM 1/8W 5% 0805 SMD Value: 10k 1 $0.1 Link Screen_shot_2012-12-28_at_7.29.44_pm
Permalink: http://lucidtronix.com/tutorials/22
Combine an electret microphone, Arduino and a heart matrix for a sound-sensitive wearable device....
Standalone programmable Heart-Shaped LED display....
The heartduino is a heart-shaped arduino clone complete with onboard sensors and a 70 pixel LED matri...
This L293D Stepper motor controller lets you precisely control a stepper motor with just two signal l...
The MCP79410 breakout board gives easy access to this cute little timekeeper....
Control a 120v outlet with a 5V arduino....
Handheld gaming machine, based on the Arduino Leonardo, equipped with joystick, SD card and more....
32 buttons for a fully-functioning hand-held USB keyboard....