Audio / Sound level meter

Hello everyone,

I made a small circuit that has a microphone MAX9814 , an Neopixel ring 32 LEDS, and Arduino UNO R3.

Here is my code:

#include <Adafruit_NeoPixel.h>

#define PIN 6         // Pin where the NeoPixel is connected
#define NUMPIXELS 16  // Number of pixels in the pixels
#define AUDIO_PIN A0  // Pin where the audio input is connected
#define DELAYVAL 1    // Time (in milliseconds) to pause between pixels

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  pixels.show();  // Initialize all pixels to 'off'
  Serial.begin(9600);
}

void loop() {
  while (1 > 0) {

    // Clear the pixels first
    pixels.clear();
    pixels.setBrightness(100);

    int audioValue = analogRead(AUDIO_PIN);

    // Map the audio value to the number of LEDs to light up
    int numLedsToLight = map(audioValue, 0, 1023, 0, NUMPIXELS);

    // Light up the LEDs based on audio level
    for (int i = 0; i < numLedsToLight; i++) {
      //light only the current pixel
      if (i < 16) { pixels.setPixelColor(i, pixels.gamma32(pixels.Color(0, 96, 2)));}  //Dark Green
      else if (i < 21) { pixels.setPixelColor(i, pixels.gamma32(pixels.Color(0, 96, 2)));}  //Light green
      else if (i < 26) { pixels.setPixelColor(i, pixels.gamma32(pixels.Color(235, 215, 0)));}  //Yellow
      else if (i < 29) { pixels.setPixelColor(i, pixels.gamma32(pixels.Color(251, 109, 1)));}  //Orange
      else if (i < 32) { pixels.setPixelColor(i, pixels.gamma32(pixels.Color(255, 0, 0)));}  //Red
      
      //switch off the other pixels
      int k;
      for (k = numLedsToLight; k < pixels.numPixels(); k++) {        
        pixels.setPixelColor(k, pixels.gamma32(pixels.Color(0, 0, 0)));  // assign color, using gamma curve for a more natural look
      }
    }
    pixels.show();    // Send the updated pixel colors to the hardware.
    delay(DELAYVAL);  // Pause before next pass through loop    
  }
}

There is a problem with this circuit:

  1. when is quiet , I have lit 4 led on the ring

  2. on the maximum sound input, i have 10 led lit (no more, no matter what) The mapping from 0 ...1023 to 0 to max number of LED is done, but ...is not working as I wanted
    Do I need a resistor or capacitor connected?

  3. If I make the circuit to work right, then I would like to have input from a 3.5 audio jack . What resistors, capacitors I would need in that case?

Thanks for help

Did you test it by entering various values and using serial.Print() to show the results?

Unfortunately that microphone has automatic gain control. So when it is quiet it will increase it's gain to pick up quiet sounds and when it is loud it will decrease the gain so the the loud signals won't saturate the output.

It also has a 1.25V offset so when there is no sound the output will be 1.25V. You should subtract out the 1.25V and then take the absolute value before you map the ADC value.

Maybe you might want to look at an Adafruit I2S MEMES microphone? Somewhere on the YouTube feed, they have the microphone connected to a ready-made WS2812 panel and were demonstrating something like a spectrum analyzer trace (with WS2812).

Here it is... the Sparkle Motion... skip to 4m30s.

Have you confirmed the neopixel ring itself works? Also the MAX9814 (was just using it actually) is more specifically for frequency detection. If you have something more like a KY038, I think you'll be in a better shape.

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