A breakout board for an electret condenser microphone shaped like an ear.
const int buffer_size = 15; int noises[buffer_size];The audio waveform is detected by keeping a buffer of sound values from the electret microphone. Every 300 milliseconds we print out the current volume and sound input. The volume or amplitude is detected by finding how much the noise buffer varies. The minimum and maximum variances are kept track of in the lines:
max_var = max(var, max_var); min_var = min(var, min_var);See the entire code below:
/* 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 = 3;unsigned long last_shift = 0;unsigned long max_var = 0;unsigned long min_var = 99999999;void setup() { Serial.begin(9600); for (int i = 0 ; i < buffer_size; i++) noises[i] = 512;}void loop() { // read the value from the sensor: noises[cur_index] = analogRead(microphone_pin); cur_index = (cur_index + 1) % buffer_size; if (millis() - last_shift > 300){ last_shift = millis(); unsigned int avg = average(noises, buffer_size); unsigned long var = variance(noises, buffer_size); max_var = max(var, max_var); min_var = min(var, min_var); Serial.print("Volume:"); Serial.print(var); Serial.print(" ~ Raw input:"); Serial.println(noises[cur_index]); }}int average(int* array, int length){ int sum = 0; int i; for(i = 0; i < length ; i++){ sum += array[i]; } int avg = sum / length ; return avg;}unsigned long variance(int* array, int length){ long sum = 0; long avg = average(array, length); for(int i = 0; i < length ; i++){ sum += (array[i] - avg)*(array[i] - avg); } unsigned long var = sum / length; return var;}
| Title | Description | # | Cost | Link | Picture |
| Electret Ear PCB | Ear shaped electret condenser mic breakout board. | 1 | $4.0 | Link |
|
| Electret Condenser Microphone | MIC COND ANALOG OMNI -44DBValue: -44dB ±2dB 20Hz ~ 20kHz | 1 | $0.96 | Link |
|
| LM386M | IC AMP AUDIO PWR .325W AB 8SOICValue: 4 V ~ 12 V | 1 | $0.91 | Link |
|
| Capacitor | CAP CER 10UF 10V Y5V 0805. Ceramic Capacitor.Value:10µF | 3 | $0.16 | Link |
|
| Resistor | Chip Resistor - Surface Mount RES 10K OHM 1/8W 5% 0805 SMDValue: 10k | 1 | $0.1 | Link |
|
Comments: