In the beginning I though to make a more or less accurate noise vu meter, giving me actual noise dBSPL, but after playing around for some time with electret microphone, and reading about sound pressure level decibels (dBSPL) and microphone datasheet, I think what at the end came up is just a graph where only relative values are meaningful.
Sound and microphones are not so simple as I expected. Key parameters of microphone datasheet are:
- Sensitivity, -46dBV for electret, calculated as 20*log(sensitivity in mV/Pa / 1000mV/Pa), which gives: 5.01 mV/Pa. So, from the mV output of electret I can calculate the sound presure level in Pascals, taking into account that 94dBSPL = 1Pa as a reference. If recommend these readings to clarify concepts:
- SNR, 58dB for electret, which means that I cannot measure less than 94-58= 36dBSPL, as noise will generate a similar output in electret as equivalent 36dBSPL sound, its well explained here.
- Frequency response, +-3dB linear, 0 dB at 1Khz
- Maximum SPL that microphone can measure, 110dB for electret
So, whith these values in mind, taking into account that it is a 1euro microphone, and that the amplifier stage with LM386N1 has a voltage gain of 20, theoretically I could calculate dBSPL.
The amplifier stage is done with LM386-N1, as recommmended in this web.
About LM386 some important tips from my point of view:
- when used in a breadboard noise was much bigger than in the soldered board, I suppose for the wires acting like antennas.
- the capacitor of 10nF at pin 7 (bypass), made important updrade for me, and it is not commonly mentioned in the webs I read
- also made important improvement the 100nF and 100uF from supply to ground, near to the vcc pin of the chip
- using the capacitor between 1 and 8 generated much noise, so I quit it and stay with a gain of 20
Amplifier output is connected to atmega 10bit ADC, and as LM386 bias the input signal to half of the supply voltage, we should have more or less 512 reading ADC in atmega in a perfect silence. I have made this table to see which values should be expected in an ideal situation:
The electret voltage is calculated as output from LM386 divided by gain of 20, Pascals are obtained using the electret sensitivity 5.01 mV/Pa.and dBSPL is calculated using the reference 94dBSPL = 1 Pascal.
Don't know very well how to interpret this, as looking to dbSPL references, I can see for example the expected value for a very calm room is 30dB. I get 61dBSPL for perfect silence, so I interpret, SNR value means that aat 94dBSPL of test sound, electret generate a noise of 94 - 58 = 36dBSPL, so supossing this is true for all the dynamic range of the microphone, and supossing this noise is added to real audio, if I substract this 36dB to the dBSPL column I would obtain a value similar to reference tables: 26dBSPL for calm room, and 96 for max output, beacuse 900 is the maximum ADC value I can get in my tests.
After all this tests and calculations, only thing I really trust is that I can get relative values, not abdsolute ones, at least accurately. So taking the value obtained at silence as 30dB and shifting the dBSPL column values 30dB down is enough for my project.
This is a photo os the final board, it has some more things than electret, LM386 and Atmega328p, as electret sound measurement was just part of the project, the final objetive is to reproduce a sound depending on noise measurements and time, using ds1307 rtc and wtc020sd-16p audio module from Sparkfun. I will write about the wtc020sd-16p module in another post, it' a great and cheap way to reproduce acceptable quality sound at low cost in your projects.
The atmega is configured to work at 16Mhz, because it was intended in the beginning to do some audio processing, any kind of echo or something like that, but I realized later that I had not enough space in atmega to store audio samples. Taking as a reference 64kbps audio pcm, as if it was voice (This comes from human voice been 4Khz max, sample at 8Khz by the Nyquist Theorem, which means 8000 samples per second, and 8bits per sample= 64kbps). I will need 64/8 = 8KBytes per second, even with a small sketch it will rest around 15 o 20 KB free memory inside Atmega Flash, for maximum 1 second of sound, not enough for my purposes. So I could have used atmega internal RC oscillator at 8Mhz and saved the crystal and a couple of capacitors. In another post I will write about how to configure atmega at 8Mhz.
Excel file for calculations.