Go Down

Topic: Interfacing a Microphone  (Read 97 times) previous topic - next topic

Babycobh1

Hello everyone,

I am trying to interface a microphone with my Arduino Mega. This microphone can be found here. https://www.robotshop.com/media/files/pdf/sound-sensor-module-arduino-datasheet.pdf

I have my microphone connected as follows.

-DO to Nothing
- (+) terminal to 5V
- (G) to Ground
- A0 to analog input A0

Here is my problem. I would like to display the voltage reading from the register as a dB reading from 48-66dB

The analog to digital converter is 0-1023 so 10 bits. I came up with a little program to simulate this and represent the voltage value in dB. I keep on getting 110 as my answer on the serial monitor when it should be between 48 and 66 dB.

Say for instance we get a reading on the ADC of 80. We would take 80/1023 to get 0.078.

Next we would find where that answer is on the scale using some algebra on a scale from 48 dB to 66dB

48 = 251.18 and 66 = 1995.26. I got these by doing algebra with this 48 = 20log(A1/A0) and 66 = 20log(A1/A0)

next we would do this 0.078*(1995.26 - 251.18) + 251.18 = 387.218 after that we simply put that answer into our formula 20 log (387.218) = 51.75dB

See it works!!! My math is correct. My program does not work however. Here it is.

Code: [Select]


int AnalogReading = A0;
void setup() {
  // put your setup code here, to run once:

Serial.begin (9600);

}

void loop() {
  // put your main code here, to run repeatedly:
 
int SensorValue  = analogRead (AnalogReading);

float maximundB = pow(10, 3.3);
float minimum = pow(10 , 2.4) ;
float dB =  20 * log(  (SensorValue / 1023) *((maximundB) - minimum) + (minimum));

delay (750);

Serial.println ( dB, DEC );

}

























sherzaad

#1
Sep 21, 2019, 07:45 am Last Edit: Sep 21, 2019, 07:45 am by sherzaad
Your math might be correct, but its not really making any sense (at least me)!

what gain are you trying to calculate?

e.g voltage gain: then that would 20log(A1/A0) where A1 would be your voltage output and A0 is the votage input.

you can check out other definitions here https://en.wikipedia.org/wiki/Decibel


on the other hand if all you are doing is using a dB meter to read the dB value and find the corresponding ADC reading then ASSUMING a linear relationship you could using the 'map' function to print out the dB level for a given ADC value.

hope that helps...

PerryBebbington

Hello Babycobh1,
Welcome to the forum.
For posting your code properly on your first post ++Karma;

Have you read the data sheet for the microphone module? Do you have a circuit diagram for it? From what I can see on the data sheet, and it's not at all clear, the analogue output is just the buffered and possibly amplified output of the microphone, which means it is an AC signal of whatever the microphone is picking up. If you simply sample that with the Arduino's A2D input then you are taking a random (random with respect to what you are sampling) sample of an AC signal, which could be at any point on a cycle from 0V to whatever the peak happens to be. That means you just get a random series of readings that do not represent anything much about the original signal. If you want get a dB reading from that, or indeed any other useful kind of data, then you have to do some more processing to get a measurable signal. I suggest that for what you are trying to do you need to take many samples and then find the peaks, probably average them over a short period and only then do your calculations.

Babycobh1

what kind of code would I need to use to sample and take the average then calculate? I am new to the arduino.

PerryBebbington

I am new to the arduino.
Then you need to work thorough the various examples in the Arduino IDE and in the various forums and tutorials on here to get a working understanding of how to write Arduino code. Also look on the internet for C and C++ tutorials.

Go Up