Sensing Volume levels with Electret Mic

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
dastels
 
Posts: 15655
Joined: Tue Oct 20, 2015 3:22 pm

Re: Sensing Volume levels with Electret Mic

Post by dastels »

Sure, averaging it electrically should work. People were doing audio processing with analog components for a long time before microprocessors showed up. An op-amp circuit is probably what you want to look at. I've used this from Sparkfun before (for binary sound detection, but it outputs the amplitude level as well): https://www.sparkfun.com/products/12642. There's a schematic under the documents tab.

Dave

User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

Post by Daft_vagabond »

Okay, I'm still fairly new so bare with me. You're saying I should replicate part of this design for my circuit? Or just get one of these? I can read most of that, but I'm not familiar with amplifiers.

At any rate, I gave the simple RC filter a try with a 5v/22uf cam and a 470ohms resistor. At times it seemed like it was working, but most of the time it all looked random again.

I'll be trying the default project code again when my replacement board arrives, hopefully it works just fine, then.

User avatar
dastels
 
Posts: 15655
Joined: Tue Oct 20, 2015 3:22 pm

Re: Sensing Volume levels with Electret Mic

Post by dastels »

A simple filter might not work, since you're not averaging a PWM signal.

Buy or build? It depends on how much time you have and how much you want to learn. I haven't used the envelope output, but the gate output (sound detect) works great.

Dave

User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

Post by Daft_vagabond »

Just updating on more tests I'm doing while waiting for the new board to arrive.

I finally got some consistency. I'm testing on an Uno and power the mic with 3v3.
Here's my code:

Code: Select all

const int OUT_PIN = 8;
const int SAMPLE_TIME = 10;
unsigned long millisCurrent;
unsigned long millisLast = 0;
unsigned long millisElapsed = 0;
int sampleBufferValue = 0;

void setup()
{
  Serial.begin(9600);
}

void loop() {

  millisCurrent = millis();
  millisElapsed = millisCurrent - millisLast;

  if (digitalRead(OUT_PIN) == LOW) {
    sampleBufferValue++;
  }

  if (millisElapsed > SAMPLE_TIME) {
    Serial.println(sampleBufferValue);
    sampleBufferValue = 0;
    millisLast = millisCurrent;
  }

}
It's idle stat has the values bounce between 1500 and 1650. I can speak into the mic and the values jump down form idle down to 250-ish. The plotter is upside-down from what I was expecting but it is consistent. The issue I'm having now is that I have to place the mic so close that it's almost touching my mouth, even when I increase the sensitivity.

This is the guide I followed:

https://arduino-tutorials.net/tutorial/ ... al-plotter

He has a different mic and also runs his at 5v, but not only do I want to find a method that works at 3v3 due to the board I want to use, but at 5v, all I get is noise at anything other than the lowest sensitivity. Even then, it doesn't seem to pic up my voice, only taps on the mic itself.

I know that much of what I'm seeing is due to the code. I'm just working through methods of getting the readouts I want.

User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

Post by Daft_vagabond »

The new board came in today.

So far I've swapped the board, changed the wires, copy-pasted the latest code, I only changed the number of pixel to 8.

I'm still having the same issue. The code starts running, the leds start low but slowly max out the graph and stay there for a while. After a bit, the leds start to bob and the values being printed as well as the graph being plotted don't seem to reflect the sound I'm making at all.

Even adjusting the gain on the back doesn't change anything.

At this point, I'm not certain what to do or try.

User avatar
dastels
 
Posts: 15655
Joined: Tue Oct 20, 2015 3:22 pm

Re: Sensing Volume levels with Electret Mic

Post by dastels »

That sounds like a data processing problem. Like it's not coming back down and when it hits the upper bound it starts oscillating.

Dave

User avatar
Daft_vagabond
 
Posts: 92
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

Post by Daft_vagabond »

I thought something like that.

I might be wrong, but when I've taken samples form an incoming signal before, I'd typically

Code: Select all

.clear
then once the list was full. I don't think that can be done with an array though. But I don't see anything that clears the samples, it just overwrites them. Maybe that has something to do with it.

If this code does work on the GEMMA M0, and unless I'm just the outlier in this, it might be safe to say that this code may not work for all Circuitpython boards.(but that wouldn't make much sense either)

I don't know if it's too much to ask, but I want to be certain that this isn't some rare occurrence, would it be possible for someone to write something they feel should detect volume levels and print them, or even just mic input in general, and display it in such way that I can tell it's responding?

The oscilloscope did it well enough. Maybe I should take a look at the code for that. (It was an Arduino project from a while ago)

User avatar
dastels
 
Posts: 15655
Joined: Tue Oct 20, 2015 3:22 pm

Re: Sensing Volume levels with Electret Mic

Post by dastels »

What does the REPL output from that code (the pendant) look like. Nothing jumps out to me in the code.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”