This max4466 module project has been one which I keep coming back to and never get it to work.
The code listed below is straight out out of an example from this site.
In trying to figure it out I discovered that:
- With no wires plugged in I get a reading on .02
- With a wire plugged in the reading goes to .85
- If I touch the insulation about 6" from the arduino the reading goes to .40 and changes only a little if I touch the bare lead.
- If I take the arduino off the arm of my chair and sit it on the table it goes to 1.5 and then to .85
- With the max4466 plugged in I get a reading of .02 and tapping on the mic does not help.
My questions are this:
- I thought the analog pin was reading voltage. Why is it seeing voltage not even plugged in?
- Is there a common mistake people make with the sound sensing modules? I've tried several with no luck.
void loop()
{
unsigned long startMillis= millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(4);
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
double volts = (peakToPeak * 5.0) / 1024; // convert to volts
Serial.println(volts);