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
Sensing Volume levels with Electret Mic
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- dastels
- Posts: 15655
- Joined: Tue Oct 20, 2015 3:22 pm
- Daft_vagabond
- Posts: 92
- Joined: Thu May 28, 2020 2:53 pm
Re: Sensing Volume levels with Electret Mic
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.
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.
- dastels
- Posts: 15655
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Sensing Volume levels with Electret Mic
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
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
- Daft_vagabond
- Posts: 92
- Joined: Thu May 28, 2020 2:53 pm
Re: Sensing Volume levels with Electret Mic
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:
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.
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;
}
}
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.
- Daft_vagabond
- Posts: 92
- Joined: Thu May 28, 2020 2:53 pm
Re: Sensing Volume levels with Electret Mic
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.
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.
- dastels
- Posts: 15655
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Sensing Volume levels with Electret Mic
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
Dave
- Daft_vagabond
- Posts: 92
- Joined: Thu May 28, 2020 2:53 pm
Re: Sensing Volume levels with Electret Mic
I thought something like that.
I might be wrong, but when I've taken samples form an incoming signal before, I'd typically 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)
I might be wrong, but when I've taken samples form an incoming signal before, I'd typically
Code: Select all
.clear
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)
- dastels
- Posts: 15655
- Joined: Tue Oct 20, 2015 3:22 pm
Re: Sensing Volume levels with Electret Mic
What does the REPL output from that code (the pendant) look like. Nothing jumps out to me in the code.
Dave
Dave
Please be positive and constructive with your questions and comments.