Noob problems

Hey all,

The code i am using if from the adafruit website (Measuring Sound Levels | Adafruit Microphone Amplifier Breakout | Adafruit Learning System). This is supposed to print readings from my mic but when i click upload nothing happens. Should the COM26 window shown on the website come up automatically?

const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
 
void setup() 
{
   Serial.begin(9600);
}
 
 
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(0);
      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 * 3.3) / 1024;  // convert to volts
 
   Serial.println(volts);
}

Should the COM26 window shown on the website come up automatically?

No, click on the magnifying glass icon at the top right of the IDE window. The baud rate in the window frame must be set to the same as your code is using.

Hint. Use the serial plotter in the tools menu for a graphic output.

How can i change the output numbers from volts to dB?

sample = analogRead(0);
      if (sample < 1024)

Why?

How can i change the output numbers from volts to dB?

What is the conversion factor?

mrears92: How can i change the output numbers from volts to dB?

The measurement of dBs is a ratio. What ratio do you want to use for the comparison to the measurement? When you know you take ten times the log to the base 10 of this ratio.

This is a link to the microphone spec: https://www.adafruit.com/datasheets/CMA-4544PF-W.pdf

This is a link to the built in adjustable preamp spec: https://www.adafruit.com/datasheets/MAX4465-MAX4469.pdf

The output i'm hoping to achieve is dB SPL but i'm getting confused. So

. 1 Pa (pascal) equals 94 dB sound pressure (SPL) . The sensitivity of the microphone is -44dB, which gives 0.0063 Vrms . Lets assume my pre amp is at its minimum 2.4v

The dB equation for voltage is 20×log(V1/Vo)

20xlog(2.4 / 0.0063) = 51.62 dB

so will the SPL be (-44) + 51.62 = 7.62 + 94 = 101.95 Db SPL

. Lets assume my pre amp is at its minimum 2.4v

What does that mean?

+2.4V to +5.5V Supply Voltage Operation

And why should that matter apart from the dynamic range of the readings. It should not be a part of the calibration calculations.

ok, but does the rest sound right? and if not, why?

Well yes it is in the right track, you just need to find the voltage a zero dB SPL would give you.
I would not be too hopeful of its accuracy without calibration.