0

Sensing Volume levels with Electret Mic
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Sensing Volume levels with Electret Mic

by Daft_vagabond on Fri May 13, 2022 5:49 pm

I recently purchased one of these for a project:

https://www.adafruit.com/product/1063

And I'm using a Feather M4 express. Since I've never used a mic in my projects before, I thought I'd start by reading this guide and changing what's needed to make it fit for the Feather M4.

https://learn.adafruit.com/sound-reacti ... ython-code

My end goal is to have the mic sense volume levels, plot and map the readings, and have a servo rotate from 0-180 based on how loud the the mic says the sound is.

I'm a little lost, however. I know the mic detects more than just volume, since it can record audio samples and all, I'm just not certain how to go about picking out that value.

I thought maybe I could pic apart the audio-levels meter part of the code featured in the guide and find the variable that changes based on the volume of the sound around it, but I can't get anything to respond the way I'd like. Every signal seems more-or-less random, jumping up and down rapidly.

Daft_vagabond
 
Posts: 86
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

by dastels on Fri May 13, 2022 6:21 pm

I looked through that code and it's extracting volume information from the sound. A sound wave is a complex combination of sine waves. That's what a mic detects. Extracting the volume is a matter of sampling over time and computing a rolling average of the min/max values. That's what the guts of the code in that project does. So you seem to be on the right track.

Dave

dastels
 
Posts: 10123
Joined: Tue Oct 20, 2015 3:22 pm

Re: Sensing Volume levels with Electret Mic

by Daft_vagabond on Sat May 14, 2022 7:15 pm

From what I can tell, I followed everything in the guide and I'm still having issues.

I decided to follow the guide and get the mic and led string working normally, then afterwards I would start playing around with it.

I've confirmed and reconfirmed that I've done everything correctly. I copy-pasted the code, changed the LED pin to the pin I'm using, confirmed that the pin supports PWM, wired everything up properly, changed the length of my led string in the code to match the length of the string I'm using, and it still doesn't seem to be responding to any sounds I'm making. It seems to be acting totally random.

Even when sitting in complete silence, the led string idles at the top, most of the time. The readouts are telling the same story, that whatever values the board is sending are somewhere near the peak, consistently.

I tried adjusting the noise value a few different times, but that acts just the same. I'm gonna keep looking at everything just to make sure I followed everything 1:1, but I'm nearly certain that I have.

Daft_vagabond
 
Posts: 86
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

by Daft_vagabond on Sat May 14, 2022 7:18 pm

I just wanted to add that I've also tried adjusting the gain from the back of the mic, too.

Daft_vagabond
 
Posts: 86
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

by dastels on Sat May 14, 2022 10:25 pm

Can you post clean photos of the wiring & connections?

Dave

dastels
 
Posts: 10123
Joined: Tue Oct 20, 2015 3:22 pm

Re: Sensing Volume levels with Electret Mic

by Daft_vagabond on Sat May 14, 2022 10:43 pm

Sure thing!

(hastily taken just a moment ago)
Attachments
wiring.jpg
wiring.jpg (439.46 KiB) Viewed 106 times

Daft_vagabond
 
Posts: 86
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

by Daft_vagabond on Sat May 14, 2022 11:44 pm

I was fiddling around and happened to notice something. Right next to the EN pin, that resistor has a component next to it, I can see it in the macros on your site, but if you zoom into the picture I posted, mine doesn't have that, just five empty solder pads.

I don't have the know-how to determine if this would effect anything with what I'm doing, but it sure is weird and I thought I'd bring it up.

Daft_vagabond
 
Posts: 86
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

by dastels on Sun May 15, 2022 11:19 am

Yeah, That's either the charger or the regulator. Since you have code running, I'm guessing that's the charger. In any case there's something missing. I doubt it would effect reading the mic, but it's not right.

Please email support@adafruit.com with a link to this thread, your order number, and request the replacement of one Feather M4 Express.

Dave

dastels
 
Posts: 10123
Joined: Tue Oct 20, 2015 3:22 pm

Re: Sensing Volume levels with Electret Mic

by Daft_vagabond on Mon May 16, 2022 12:34 pm

Is there a way you might recommend me testing the mic itself? I tried the same project using the Arduino code instead and on a different board, I also replaced the pixel strip with a different one, just in case, and I'm still getting the same result. The readout says that the mic is bobbing around that same values, seemingly unaffected by the noise around it.

Daft_vagabond
 
Posts: 86
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

by dastels on Mon May 16, 2022 1:57 pm

Do you have an oscilloscope (or access to one)? That would let you look at the signal from the mic.

Dave

dastels
 
Posts: 10123
Joined: Tue Oct 20, 2015 3:22 pm

Re: Sensing Volume levels with Electret Mic

by Daft_vagabond on Mon May 16, 2022 2:29 pm

Yeah. Which things should I test? If the "OUT" pin looks fine, is there some other component on board I can test?

Daft_vagabond
 
Posts: 86
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

by dastels on Mon May 16, 2022 3:30 pm

If OUT of the board looks fine, then it's not an issue with the mic board. I'd look again at the software and the use of the analog input, then.

Dave

dastels
 
Posts: 10123
Joined: Tue Oct 20, 2015 3:22 pm

Re: Sensing Volume levels with Electret Mic

by Daft_vagabond on Mon May 16, 2022 6:11 pm

I'm definitely a bit stumped, now. I hooked the mic up to the oscilloscope, set it for 3v3, and it seems to be working fine. Every snap, pop, and hum I making into it gives me waves relative to the volume at which I produce them.

You mentioned looking again at the software and the use of the analog input. Could you elaborate on that for me?

Daft_vagabond
 
Posts: 86
Joined: Thu May 28, 2020 2:53 pm

Re: Sensing Volume levels with Electret Mic

by dastels on Mon May 16, 2022 6:51 pm

OK, the mic board works.

The next thing to look at is the wiring. make sure the connections are correct and good: replace the wires, move to a different area of the breadboard.

Then it's the code. This was written for a SAMD21 so it should just work on the SAMD51. Make sure you have the latest code by grabbing it directly from github: https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Sound_Reactive_NeoPixel_Peace_Pendant/code.py

But your Feather does have a problem (missing charger) from fab, so there could be other issues.

Dave

dastels
 
Posts: 10123
Joined: Tue Oct 20, 2015 3:22 pm

Re: Sensing Volume levels with Electret Mic

by Daft_vagabond on Mon May 16, 2022 7:02 pm

Okay, I'll test this later when I'm able to.

I had an idea I wanted to ask about.

A few months back I had a project where I was measuring sound intensity in much the same way, except the signal was PWM rather than analog. I was having trouble calculating consistent averages, which was important because, just like this project, I only needed to keep track of the intensity of the sound, nothing else really mattered.

The route I ended up going with was sending the PWM through an RC filter. That smoothed everything out and gave me a nice, easily readable audio intensity level. I don't know if that sort of thing would work for an analog signal coming from a microphone, but I thought it worth asking.

Daft_vagabond
 
Posts: 86
Joined: Thu May 28, 2020 2:53 pm

Please be positive and constructive with your questions and comments.