SparkFun MEMS Microphone - INMP401 (ADMP401)
Overview
This wikipage is designed to give users an understanding of how to use the SparkFun MEMS microphone with the mbed platform. Using a $10 chip from Sparkfun allows one to build a recording device by interfacing with the mbed platform. Since the chip is provided on an IC breakout board it can be directly wired to the mbed without the need for an additional circuit to control the chip output. This allows for quick development to time and saves on cost, especially useful for prototyping. Example code is given to show users how to implement a simple recording and playback functionality. A youtube video is also provided as a live demo for the user.
Click here to order the MEMS microphone from Sparkfun.
Click here for the datasheet.
Using a Microphone for Analog Input
In order to input an accurate Analog Output into the mbed, Vcc should be connected to 3.3V and the microphone AUD output will float at one half Vcc when there is no sound. The amplifier on the chip has a gain of 67 and produces a peak-to-peak output of 200mV when the microphone is spoken into at arms length at normal conversation levels.
Wiring
The following components are required for the demo:
The table below describes how to wire the required components. See the linked pages in the demo section for more information on each individual component.
Microphone | MBED |
---|---|
aud | p15 (AnalogIn) |
gnd | gnd |
Vcc | VOUT (3.3V) |
Component | MBED |
---|---|
Speaker | pin 18 |
Record Pushbutton | pin 5 |
Play Pushbutton | pin 6 |
Red LED | pin 7 |
Speaker
A transistor is required to hook up the speaker. The R1 resistor is connected to pin 18 (Analog In). See picture below.
Record/Play Pushbuttons
For both the Record/Play push buttons the lower pin goes to ground while the upper pin for record goes to pin 5, and the upper pin for play goes to pin 6. Take care to use the internal PullDown resistor on the mbed. See picture below
Red LED
When looking at the LED. The shorter wire goes to ground while the longer wire is connected in series with a 220 ohm resistor to pin 7.
Schematic
Below is a schematic of the MEMS chip that produces microphone functionality. Most of the circuit elements are taken care of because the chip is implemented on an Integrated Circuit (IC) board. However it is possible to increase the sensitivity of the microphone by adding more resistors in series with the IC to record.
Demo
The following demo records the input from the microphone for one second when the recording push button is pressed. The audio on the speaker is played back when the playback push button is pressed. A red LED lights up when recording, and the on-board mbed LEDs light up depending on the volume of the sound detected.
Code
Provided below is a library that sets up interfacing between the microphone and mbed in an easy to use C++ class.
#include "mbed.h" AnalogIn mic(p15); //microphone input AnalogOut speaker(p18); //speaker output DigitalOut led1(LED1); // following leds are used to visualy show amplitude of sound DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); DigitalOut red(p7); //this powers a red LED that lights up when recording DigitalIn pbRec(p5); //pushbutton inputs to either begin recording or playback DigitalIn pbPlay(p6); void record(float* sampleArr) { //record sound for 1 second for(int i=0; i<8000; i++) { sampleArr[i] = mic.read(); //put samples in array wait(0.000125f); //sample rate of 8000 Hz } } void play(float* sampleArr) { //playback recorded sound wait(0.1); for(int i=0; i<8000; i++) { speaker = sampleArr[i]; wait(0.000125f); } } void volume(){ //the following lights up the onboard LEDs depending on the amplitude of sound led1 = (mic > 0.5f) ? 1 : 0; led2 = (mic > 0.6f) ? 1 : 0; led3 = (mic > 0.7f) ? 1 : 0; led4 = (mic > 0.8f) ? 1 : 0; } int main() { float sampleArr[8000]; //used to store sound pbRec.mode(PullDown); //use internal resistors for pushbuttons pbPlay.mode(PullDown); red = 0; while(1){ volume(); if (pbRec == 1) { wait(0.2); red = 1; record(sampleArr); red = 0; } if (pbPlay == 1) { play(sampleArr); } } }
Picture of Setup
Live Demo
Please log in to post comments.