Convert voltage to dB

maybe the formula should be

dB = -16.801 * log(sensorValue/1023.) + 9.872; // note the additional minus..

Thanks for the suggestions, but not even the minus sign didn't work. The values I get are almost static, they barely change.
Im not sure if this formula could work, although on the website I found it says it is compatible with Arduino Uno.

:expressionless:

The formula is fine. Maybe you should print some of the sensor values and work things out by hand.

louisbourdon:

maybe the formula should be

dB = -16.801 * log(sensorValue/1023.) + 9.872; // note the additional minus..

Thanks for the suggestions, but not even the minus sign didn't work. The values I get are almost static, they barely change.
Im not sure if this formula could work, although on the website I found it says it is compatible with Arduino Uno.

:expressionless:

formula produces values from just under 10dB to about 60dB...

Screen Shot 2014-10-03 at 8.06.54 PM.png

Screen Shot 2014-10-03 at 8.06.09 PM.png

Thank you all so much about your replies and effort to help me sort this problem out.

It was after all a hardware issue. I had to change 2 sound modules as they were not giving the expected results - I suspect a problem in their variable resistors.

Now I have some results that sort of simulate a dB scale. It is not accurate for sure, but closer to my needs.

Cheers!

Hi,

I'm using this program and the sound sensor doesn't read correctly. It only detects three values of decibelius.

double db = (20. * log(10)) * (sensorValue / 5.); I use this formula but it doesn't work.

What's the problem?

Thanks

Your formula is incorrect.

The log() function provides the natural logarithm, not base 10.
Thus, log(10) is the natural logarithm of 10, which is a constant.
The log10() function provides logarithms to the base 10.

Perhaps you meant

double db = 20.0 * log10(sensorValue / 5.0) ;

But of course I know nothing about your sensor so I can only guess.
I like to put a zero after the decimal point just because it makes it more obvious that a decimal point is there.

What's the problem?

The problem is that you have unrealistic expectations. You post a snippet of code, using mixed mode arithmetic, and you want us to guess what the problem is.

Use op-amps to rectify and then envelope your AC signal.
This shall result in a DV voltage 0..5V for ADC.
At last 20*log10(analogread(A?))

I'm using a sound detection circuit http://letsmakerobots.com/files/sound_circuit.jpg. This circuit send a signal to my Arduino Leonardo. It convert Voltage to dB and if the number is over 68dB, it will open a light. I'm using thi program and it has a mistake but I don't know what it is.

int sensorPin = A0; // analogic output
int relayPin = 10; //digital output
int sensorValue = 0;
int db=0
void setup() {

pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW);
Serial.begin(9600);
}

void loop() {

sensorValue = analogRead(sensorPin);

const int analogInPin = A0;

double db = (20. * log(10)) * (sensorValue / 5.);

Serial.print("db = ");
Serial.println(db);

delay(500);
if db > 68 {digitalWrite (relayPin, HIGH};
delay (5000);
}

void loop (){
sensorValue =analogRead (sensorPin);
const int analogInPin=A0 :
double db = (20. * log(10) * (sensor value / 5.);
Serial.print ("db =");
Serial.println(db);
delay (500);
if db < 55 {digitalWrite (relayPin, LOW};
delay (2000) ;
}

thanks

help me for make decibel meter with arduino,i dont know how to convert ADC to dB in arduino.....i thought logarithm doesn't exsist in arduino...help please. :confused:

See reply #25 of the 3 month old thread that you brought back from the dead.

can you help me for creating the completly program of this...

this my proggram

#include <LiquidCrystal.h> // 0

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // 1
int val; // 2
int dB; // 3
const int sensorPin = A0; // 4

char in; // 5
int sensorVal = 0; // 6
int smoothedVal = 200; // 7
int samples = 4; // 8
void setup() { // 9

pinMode(6, OUTPUT); // 10
pinMode(7, OUTPUT); // 11
pinMode(8, OUTPUT); // 12
pinMode(9, OUTPUT); // 13

lcd.begin(16, 2); // 14
lcd.setCursor(1,0); // 15
lcd.print("DESIBEL METER"); // 16
lcd.setCursor(5,1); // 17
lcd.print("W-Tech"); // 18
delay(300); // 29
lcd.clear(); // 20
// Print a message to the LCD.
Serial.begin(9600); // 21

}

void loop() { // 22
//int val;
lcd.clear(); // 23

val = analogRead(sensorPin); // 24
smoothedVal = smoothedVal + ((val - smoothedVal)/samples); //25
val = smoothedVal0.6779+32.755; // 26
dB = val
0.5228 + 35.271; // 27
Serial.println(dB); // 28

if(analogRead(sensorPin)<=0){ // 29
lcd.setCursor(0,0); // 30
lcd.print(" DESIBEL METER"); // 31
lcd.setCursor(0,1); // 32
lcd.print("press red button");} // 33
else{ // 34

lcd.setCursor(1,0); // 35
lcd.print("DESIBEL METER"); // 36
lcd.setCursor(0,1); // 37
lcd.print(dB+2); // 38
lcd.setCursor(5,1); // 39
lcd.print("dB"); // 40
lcd.setCursor(8,1); // 41
lcd.print("W-Tech");} // 42

delay(250); // 43

if (val>=45){ digitalWrite(6,1);} // 44
else {digitalWrite(6,0);} // 45
if (val>=55) {digitalWrite(7,1);} // 46
else {digitalWrite(7,0);} // 47
if (val>=60) {digitalWrite(8,1);} // 48
else {digitalWrite(8,0);} // 49
if (val>=70) {digitalWrite(9,1);} // 50
else {digitalWrite(9,0);} // 51

}

i use linearity to convert my ADC......
help me for changes to 20log10....26 and 27 is my conversion of my ADC

meh_dadi3.ino (2.39 KB)

Welcome to the Forum. Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags which make the code looklike thiswhen posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.

If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button.

i don't know what to do

(i.e. 0 would then equal approximately 20-30 dB).

Ok, that's weird. I would have thought that a reading of 0 comes to negative infinity db.

To make your calculation, we need two points on your scale - assuming that voltage corresponds linearly to SPL. And we can't use point 0 (no sound at all) because decibels are logarithmic. We'll do everything using floating point.

As always, I suffix everything with the unit of measure.

// When the analog in is 100, then the reading should be 40db
const double V0 = 100;
const double V0_dB = 40;

// When the analog in is 1020, then the reading should be 80db
const double V1 = 1020;
const double V1_dB = 80;

// pre-calculate the scaling constants
// convert units to bels rather than decibels
const double inV0_Bel = log10(V0);
const double inV1_Bel = log10(V1);
const double outV0_Bel = V0_dB / 10;
const double outV1_Bel = V1_dB / 10;
const double scalingConstant = (outV1_Bel-outV0_Bel) / (inV1_Bel-inV0_Bel);

float analog2db(int V) {
  double inV_Bel = log10(V);
  
  // scale to correct range
  double outV_Bel = (inV_Bel-inV0_Bel) * scalingConstant + outV0_Bel;
  
  return outV_Bel * 10; // deci-bels
}

I still don't get it...can you create the program from begining until the end?i really need this...i still dont get it how to change the analog voltage to decibel....

louisbourdon:
So, is there any formula that works to convert the voltage in dB SPL? I have tried many different ways, but I always get false results. There has to be something out there - or if could someone direct me to resources?

Again, I want to convert the voltage in db SPL (sound pressure level), with a minimum value of around 30dB, and a maximum at around 90dB.
Thanks!

And you are aware that 60 dB represents a dynamic range of one to one million?
You shoud not even try doing that in software.

You need analog hardware upfront with a logarithmic amplifier.

louisbourdon:
After some time I returned to finish this project. So far, still, no answer to make it work as closely as possible to as a dB meter.

I'm reading this article (http://www.inmotion.pt/store/phidgets-sound-sensor) saying that there is a formula that can be used to get the dB conversion (for 1kHz sound for example).

SPL at 1kHz tone (dB) = 16.801 x ln(sensorValue/1023) + 9.872

I tried the formula but I got nothing. I don't know what the ln stands for :roll_eyes:

Maybe someone could help?

If you want to to "make it work as closely as possible to as a dB meter", you have got a LOT to do!

You will need extreme low noise amplifiers, an (A) curve or a (C) curve filter, decoupling amplifiers again and finally a logarithmic demodulating amplifier. Not to mention a reliable microphone that has at least 60dB dynamic...
Good luck!

The phidget sound sensor does not appear to match these requirements.
Halas, since I am still seeking for a shield that does exactly that.

help me please

recnoise.ino (3.74 KB)

Hello Guys

adc value convert in decible dB = (adc + 83.2073) / 11.003;