Trying to Understand Analog Pin values while trying to do sound sensor.

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);

imart:
My questions are this:

  • I thought the analog pin was reading voltage. Why is it seeing voltage not even plugged in?

Your sketch is showing the difference between the highest sample and the lowest sample. Electrical noise would explain why the results are non-zero without noise being applied.
Does your microphone module have 'adjustable gain'? If so, have you tried adjusting it to see if you can get a response to noise?
The values are quite low so you might want to look into using the INTERNAL analog reference (1.0-1.2V) instead of the default 5V reference. This will use more of the available range of the a/d converter. If you want the result in volts, be sure to change the '5' in your sketch to match the analog reference voltage (measure between the AREF pin and ground with a good meter).

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.