I'm trying to use a microphone sensor to eventually trigger a stepper motor. Putting the stepper motor functionality aside for a moment, I can't get any sensitivity out of the mic module on it's own. Here's my code:
I've adjusted the gain potentiometer so that when the room is silent, the returned amplitude is around 2 to 4 in the serial monitor. I'm working on the premise that without sound, the output wave will sit relatively close to the baseline value. The problem is, unless I get about an inch or 2 from the mic and whistle like I'm calling a dog for dinner (in which case it jumps into the hundreds), I get no change at all. I've tried it with 3 different module all with the same result. I am using a 3.3/5V breadboard PSU jumpered to 5V, with the ground tied to the GND on my Mega 2560. My pinout on the module is as follows:
"G" - GND on the breadbord PSU and the MCU
"+" - Breadboard 5V
AO - A9 pin on the MCU
I've tried messing around with the gain potentiometer using different offsets, but no luck. If I tap gently on the mic i get pretty significant changes. I thought at first it was a dead board, but I've tried 2 with identical results. I tried it on digital, and it has the same sensitivity issues. I even pulled the felt off the mic just to see if it would help at all. It did not./Can anybody give me a push on this? Thanks all!
Showing a link to the specifications of the module would be a much better first step. So far, we do not have a clue about the module. Your results seem to indicate it has a digital output when the audio level exceeds some threshold.
Skip the printing. At the glacial baud rate of 9600, you are sampling the microphone and printing only about 100 times per second.
At that low sample rate, what is the chance that a peak value will be caught? The default analogRead() sample rate is about 10,000 per second (if not bogged down by other program code).
Fair point. Here's the datasheet. There's 2 outputs, DO (Digital Out) and AO (Analog Out). DO will output a 1 until a given volume threshold is detected, then it will invert and output 0. That threshold can be adjusted by the potentiometer. AO will output essentially a sine wave sitting on an offset voltage of 2.5V (5V / 2) with value either above or below that reference. I've been using it in analogue mode.
Thank you. Note, the reference does not include a schematic of the board. But it does tell us the adjustable control is the reference voltage for the comparitor, NOT a gain control! Also they hint that the analog output is just the output from the electret microphone. You have to supply any needed amplification.
Same result unfortunately. So here's something weird though. I've tuned the pot so that the ambient output sits as close to zero as I can get. I included the following code:
I created the Stepper object and all that, I just didn't show it here. With this code added, when I whistle nothing happens. If I tap the mic with my finger it actuates the stepper, but then it keeps running. If I include the original Serial.println statement, it shows an initial value of around 4-6, then once I tap it, it jumps up to around 30 (and turns the stepper) and stays at 30 even with no noise (doesn'r drop back down to 4-6). If I whistle again, it will go up to around 45ish, then drops back down to 30. It only resets when I kill the power to the module and the MCU.
Thanks for the reply. I was going off of this (from the datasheet):
"The sensor has 3 main components on its circuit board. First, the sensor unit at the front of the module which measures the area physically and sends an analog signal to the second unit, the amplifier. The amplifier amplifies the signal, according to the resistant value of the potentiometer, and sends the signal to the analog output of the module."
Yes, all electret microphones contain a transistor to bias the microphone, since it is a variable resistor. That could also be called an amplifier. It's output will be a few millivolts. But the whole description is suspect when they write that the front of the module measures the area physically!
The onboard OpAmp adds a bias voltage of 1/2 VCC to the audio signal. When capturing standard sound sources, such as a normal speaking voice a few feet away, the audio (AUD) output signal will register at about 200mV peak-to-peak. This helps provide a cleaner audio signal.