Sound Level Meter with max9814

 https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/measuring-sound-levels

The Audio signal from the output of the amplifier is a varying voltage.  To measure the sound level, we need to take multiple measurements to find the minimum and maximum extents or "peak to peak amplitude" of the signal.  

In the example below, we choose a sample window of 50 milliseconds.  That is sufficient to measure sound levels of frequencies as low as 20 Hz - the lower limit of human hearing.

After finding the minimum and maximum samples, we compute the difference and convert it to volts and the output is printed to the serial monitor.
/****************************************
Example Sound Level Sketch for the 
Adafruit Microphone Amplifier
****************************************/

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 * 5.0) / 1024;  // convert to volts

   Serial.println(volts);
}
sensors_Capture.jpg

OK, so that's not very exciting.  What else can you do with it?

댓글

이 블로그의 인기 게시물

ARIMA or ARMA

WSL2에서 X window를 세팅하는 법

How to Use SpaceDesk : Multi DIsplay