Sound meter detects noise from its own circuit?

Hi everyone :smiley: !
This is my first post so it would be nice if you tell me my mistakes (i don't know if project guidance is the correct place).

I'm currently working on a sound meter for a school project, i have it mounted and more or less working. I'm using an Arduino MEGA 2560 and Sparkfun sound detector (SparkFun Sound Detector - SEN-12642 - SparkFun Electronics), which i calibrated with a sound meter app cause i don't have an SPL meter.
It calculates the decibels and displays them on a seven segment and four digits display, it also has an rtc (real time clock) DS3231 and a microSD module to save the decibel readings with the time.


Finally, i've added three LEDs like a traffic light:

  • Red: more than 120dB which is the danger zone, when the ears start to ache.
  • Yellow: between 65 and 120 dB.
  • Green: between 30 and 65 dB.

This was displayed in an LCD.

Here is the actual circuit (i'm also working on the schematics because now they are a mess):

The problem is that, at the beginning i had connected only the Sparkfun sensor and to control it the Arduino, when the room was in silence it detected around 45 dB. Whereas, when i added the rtc, LCD, etc. it detected around 53 dB with the room in silence. I've done some research and found that this might be because the noise the circuit itself makes (i think its called white noise), or the way you power the project (in my case a powerbank and if i connect it to a phone charger it detects 57-60 dB in silence!) or maybe because i use a lot of long wires (i saw in a video were someone made an radiocontroller with Arduino and said that short wires are better due to the interferences).

I would like to know if you think it's because the circuit noise and if it is how to solve it or how to solve my problem, please :slight_smile:.
(I hope i've given enough information, i've also posted the code).

Thanks for the replies. :wink:

#include <SD.h>
#include <SPI.h>
#include <DS3231.h>            // Modulo de reloj
#include <Wire.h>              // LCD
#include <LiquidCrystal_I2C.h> // LCD
#include <SevSeg.h>            // Display de segmentos

SevSeg sevseg; 
LiquidCrystal_I2C lcd(0x27,20,4);
DS3231  rtc(SDA, SCL);         // Reloj (rtc = real time clock)
File myFile;
int pinCS = 53;                // SD

const int soundPin = 0;        // Pin envelope del sensor de sonido (Anal贸gico)

//Variables del sonido
int sound;                     // Amplitud
float decibelsCalculated;
float dB;                      // Decibelios tras la operaci贸n (float --> decimal)

//Millis
unsigned long time;
unsigned long t = 0;
int dt = 1000;                 // Diferencia de tiempo

/* Los caracteres personalizados de mi logo (m谩ximo 8)
Este LCD tiene 20 caracteres por 4 l铆neas y cada caracter se compone de pixeles de 5x8
1 --> enciende el pixel     0 --> lo apaga
*/
byte logo_1[8] = {
  B00000,
  B00000,
  B00001,
  B00010,
  B00100,
  B00100,
  B01000,
  B01000
};
byte logo_2[8] = {
  B00000,
  B11111,
  B00000,
  B00000,
  B00000,
  B11111,
  B10101,
  B01110
};
byte logo_3[8] = {
  B00000,
  B00000,
  B10000,
  B01000,
  B00100,
  B00100,
  B00010,
  B00000
};
byte logo_4[8] = {
  B01000,
  B01000,
  B00100,
  B00100,
  B00010,
  B00001,
  B00000,
  B00000
};
byte logo_5[8] = {
  B00100,
  B00100,
  B00111,
  B00000,
  B00000,
  B00000,
  B11111,
  B00000
};
byte logo_6[8] = {
  B11110,
  B00010,
  B00100,
  B00100,
  B01000,
  B10000,
  B00000,
  B00000
};

// Leds (sem谩foro)
int Led_rojo = 22;
int Led_amarillo = 24;
int Led_verde = 26;
  
void setup()
{
Serial.begin(9600);     
lcd.backlight();
lcd.begin();
lcd.clear();
pinMode(pinCS, OUTPUT);       // SD  
rtc.begin();  
Wire.begin();

// Crear los caracteres del logo
lcd.createChar (0, logo_1);    
lcd.createChar (1, logo_2);    
lcd.createChar (2, logo_3); 
lcd.createChar (3, logo_4);    
lcd.createChar (4, logo_5);     
lcd.createChar (5, logo_6);     

// Display de segmentos
byte numDigits = 4;
byte digitPins[] = {10, 11, 12, 13};
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
bool resistorsOnSegments = true;
byte hardwareConfig = COMMON_CATHODE;
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
// sevseg.setBrightness(90);

//LOGO
lcd.setCursor(9,1); 
lcd.print(char(0));  
lcd.print(char(1));       
lcd.print(char(2));  
lcd.setCursor(9,2);  
lcd.print(char(3));
lcd.print(char(4)); 
lcd.print(char(5)); 
delay(3000);
lcd.clear();

// Leds
pinMode (Led_rojo, OUTPUT);
pinMode (Led_amarillo, OUTPUT);
pinMode (Led_verde, OUTPUT);
digitalWrite (Led_rojo, LOW);
digitalWrite (Led_amarillo, LOW); 
digitalWrite (Led_verde, LOW);  

// Iniciamos la MicroSD
if (SD.begin())
        {
        // Si funciona
        Serial.println("SD card is ready to use");
        lcd.print("SD card:");
        lcd.setCursor(0,1); 
        lcd.print("Ready to use.");
        delay(5000);
        // Create/Open file 
        myFile = SD.open("sound.txt", FILE_WRITE);   
        } else {
        // Si no funciona
        Serial.println("SD card initialization failed");
        lcd.print("SD card:");
        lcd.setCursor(0,1);
        lcd.print("Initialization failed.");
        delay(5000);
        return;
        }

// Abrimos el archivo
if (myFile) {
        // Si se cre贸/abri贸 correctamente
        Serial.println("File created/opened");
        lcd.clear();
        lcd.print("File created/opened");
        myFile.println(" ");
        myFile.print(rtc.getDateStr());
        myFile.print(" - ");
        myFile.println(rtc.getDOWStr());
        myFile.close(); // close the file
        delay(5000);
        } else {       
        // Si no se abri贸 correctamente
        Serial.println("Error opening file");
        lcd.clear();
        lcd.print("Error opening file");
        delay(5000);
        }

     lcd.clear();                                   // Limpiamos el LCD
     lcd.print("SONOMETRO");
     lcd.setCursor(0,1);
     lcd.print("Rojo: >120 dB Nocivo");
     lcd.setCursor(0,2);
     lcd.print("Amarillo: >65 dB");
     lcd.setCursor(0,3);
     lcd.print("Verde: >30 dB");
}

void loop()
{
 time = millis();
 if(time - t > dt) {
     t = time;
     sound = analogRead(soundPin);                 // Lee los datos y valores del pin Envelope del sensor de sonido
  
     decibelsCalculated = 20 * log10(sound/1);     // Calcula los dB
     dB = decibelsCalculated + 30.15;

     Serial.println(dB);                            // Imprimimos en el puerto serial los dB


      
  // Open file 
      myFile = SD.open("sound.txt", FILE_WRITE);
      
      if (myFile) {
        //Si se abri贸 correctamente el archivo
        myFile.print(rtc.getTimeStr());           // Escribimos la hora
        myFile.print(",");                      
        myFile.println(dB);                       // Escribimos los dB calculados en el txt
        myFile.close();                           //Cerramos el archivo
      }  
}
  sevseg.setNumber(dB,2);                         // Escribimos los dB en el display de segmentos
  sevseg.refreshDisplay();

// Leds
if (dB > 120) {                                   // Led ROJO --> A partir de 120 dB
    digitalWrite (Led_rojo,HIGH);                 
    } else {
    digitalWrite (Led_rojo,LOW); 
    }
if (dB > 65 && dB < 120) {                        // Led AMARILLO --> Entre 65 y 120 dB
      digitalWrite (Led_amarillo,HIGH);
    } else {
    digitalWrite (Led_amarillo,LOW);   
    }
if (dB > 30 && dB < 65) {                        // Led VERDE --> Entre 30 y 65 dB     
    digitalWrite (Led_verde,HIGH);
    } else {
    digitalWrite (Led_verde,LOW); 
    }

}

Try running on battery power only.
Chargers are made for a purpose (charging) not great for power supply and are inherently noisy.

I have a four battery holder on my way, as soon as it arrives i'll try what you say and post the results. Thanks for the reply!

The Sparkfun Sound Detector does not have proper filtering on VCC, if you look at the schematic the mic resistor connects right to it so I would expect lots of power supply noise to be a problem.
This is a no-no, especially because you are driving LED displays so your main 5V is a bit noisy from switching LED's on and off and the MCU etc.
For a sensitive mic preamplifier you need electrically quiet power. This is not to be confused with hiss or noise from random electrons moving around.

I would power the sound detector VCC through an RC filter, something like 47-220ohms and 100uF capacitor, from the Arduino.
This would filter out most of the noise coming into the board from the Arduino's power. You will need it with battery or USB or wall wart power.

Another problem can be an ungrounded (two-prong) wall wart adds a lot of electrical noise which the mic preamp will be pick up and give fake high readings.

Which of the three possible board output pins are you using?

Paul

Paul_KD7HB:
Which of the three possible board output pins are you using?

Paul

If you are referring to the Sparkfun sensor, i'm using the Envelope output.

prairiemystic:
The Sparkfun Sound Detector does not have proper filtering on VCC, if you look at the schematic the mic resistor connects right to it so I would expect lots of power supply noise to be a problem.
This is a no-no, especially because you are driving LED displays so your main 5V is a bit noisy from switching LED's on and off and the MCU etc.
For a sensitive mic preamplifier you need electrically quiet power. This is not to be confused with hiss or noise from random electrons moving around.

I would power the sound detector VCC through an RC filter, something like 47-220ohms and 100uF capacitor, from the Arduino.
This would filter out most of the noise coming into the board from the Arduino's power. You will need it with battery or USB or wall wart power.

Another problem can be an ungrounded (two-prong) wall wart adds a lot of electrical noise which the mic preamp will be pick up and give fake high readings.

I've never heard of RC filtering i'm a noob in electronics but after some research on the Internet i've understand what you have suggested. The capacitor with the closest value i have is 220uF but i'll buy one of 100uF in a shop near my house and see if it works.
Thanks for both replies. ;D

The capacitor with the closest value i have is 220uF but i'll buy one of 100uF in a shop near my house and see if it works.

220渭F is fine, the exact value does not matter.

Too many new folk come here expecting all the answers and don't want to do any work themselves. You are clearly making an effort to experiment and learn, well done. ++Karma;

PerryBebbington:
220渭F is fine, the exact value does not matter.

Too many new folk come here expecting all the answers and don't want to do any work themselves. You are clearly making an effort to experiment and learn, well done. ++Karma;

Thanks! When i started making this project i only knew how to light some LEDs or control a servo i've learned a lot during the procces, it's exciting seeing it work and thinking there are a lot more things to do and learn :smiley: .
I'll try to use the 220uF capacitor, should the connections be like this?:


I've also tried powering it up with the battery holder, it now detects 50-51 dB, which is at least less than 53-54.

I'll try to use the 220uF capacitor, should the connections be like this?

I suggest it would probably work better if you put the capacitor directly on the sound detector. If you can't do that then at least connect the 0V to the capacitor directly to the sound detector. You need to make the wiring between the capacitor and the sound detector as short as possible. If you have to do it via breadboard then probably take 0V to the breadboard with the capacitor then from there to the sound sensor. You will probably find that just routing the wires differently changes the amount of background noise picked up, so feel free to experiment.

I'll buy one of 100uF

I meant to say earlier, never buy 1 of something as cheap as a capacitor, buy 5 or 10 or even more. Things like capacitors are handy to have, buy more than you need and build up a stock.

The noise MAY be real... Most SPL meters use [u]A-Weighting[/u]. If your homemade meter is unweighted the readings won't match if nature of the sound/noise changes from whatever is used for calibration. You could also have "different" averaging, or maybe your meter picks-up the peaks or something. (The "envelope" output from the sound sensor is probably a peak reading.) Acoustic background noise is often dominated by low frequencies and this is filtered-out by A-weighting.

And in general, it's difficult to get consistent-repeatable results, especially at higher frequencies. Awhile ago, I was doing some high-frequency experiments with my SPL meter on a microphone stand and just moving around behind the SPL meter would change the readings (because of the way sounds reflect around the room and around objects in the room).

But, noise is always a challenge with audio. Especially when amplifying low-level microphone signals.

You can get electromagnetic interference from the environment. If you've ever touched the input to ah audio amplifier and heard a hum or buzz, that's your body acting as an antenna, picking-up power-line hum from the AC wires in your house and all-around you. Stage & studio microphones are shielded and they use shielded cables. And they use a low-impedance balanced connection to minimize noise pickup. (You probably won't find a balanced connection in an SPL meter but it will be shielded.)

All active electronics generate some noise. Good microphone preamps use low-noise op-amps or low-noise FETs/transistors. This sounds like hiss (white noise).

As mentioned above, you can get noise from the power supply. Some preamps use dual voltage regulators (i.e. a 15V regulator feeding a 12V regulator) and/or some use RC filtering in the power supply. (With low current circuits like preamps you can get-away with RC filtering. It doesn't work with power amplifiers because you get too much voltage-drop across the resistor.) "Improper grounding" (a ground loop) can allow noise to get-in through the power supply. Linear power supplies can "leak" low frequency power-line hum. Switching power supplies can generate high-frequency noise. High frequency noise from a running microprocessor can also get-into the power supply and then into the preamp.

PerryBebbington:
I suggest it would probably work better if you put the capacitor directly on the sound detector. If you can't do that then at least connect the 0V to the capacitor directly to the sound detector. You need to make the wiring between the capacitor and the sound detector as short as possible. If you have to do it via breadboard then probably take 0V to the breadboard with the capacitor then from there to the sound sensor. You will probably find that just routing the wires differently changes the amount of background noise picked up, so feel free to experiment.

Ok i'll to wiring between the capacitor and the sound detector as short as possible, experiment and see what happens. Also, with 0V are you referring to volts?

PerryBebbington:
I meant to say earlier, never buy 1 of something as cheap as a capacitor, buy 5 or 10 or even more. Things like capacitors are handy to have, buy more than you need and build up a stock.

That's a good philosophy ;D

DVDdoug:
The noise MAY be real... Most SPL meters use [u]A-Weighting[/u]. If your homemade meter is unweighted the readings won't match if nature of the sound/noise changes from whatever is used for calibration. You could also have "different" averaging, or maybe your meter picks-up the peaks or something. (The "envelope" output from the sound sensor is probably a peak reading.) Acoustic background noise is often dominated by low frequencies and this is filtered-out by A-weighting.

Thanks for the reply! How do i know if my sensor is weighted or how do i weight it? I never thought the hardest part of the sound meter would be the white noise.

DVDdoug:
The noise MAY be real...(The "envelope" output from the sound sensor is probably a peak reading.)

I didn't know that, thanks!

Thanks for the reply! How do i know if my sensor is weighted

It's not. For most applications you want flat frequency response for good audio quality and accuracy. A-weighting reduces the low & high frequencies and it would sound something-like a telephone or like turning-down the bass and treble controls on your stereo.

That's what your ear does naturally and it's what we are used to so it doesn't sound like filtering. You want that in an SPL meter to "simulate" the ear/brain, but you don't want that in a regular or audio circuit because the effect will be applied twice (once by the amplifier and again by your ear) and that does not sound natural.

or how do i weight it

It's not easy! It's not easy to build a good SPL meter!

You could build your own sensor with analog filtering or you could build an analog filter (with op-amps). Or, possibly do it with digitally with [u]DSP[/u] DSP filtering or [u]FFT[/u]. You'd need to use the actual analog output. You can't use the envelope follower output from your sensor because it's a varying DC voltage with no frequency information.

If you are going to do DSP with the Arduino, you'd have to "compromise" on the high-frequency end of the spectrum because the Arduino can only sample accurately up to about 15kHz, and that limits the audio to about 7.5kHz (Nyquist theory). Also, the Arduino is a little slow for real-time digital audio processing. From what I understand, the FFT library captures a short bit of audio (maybe several milliseconds), then stops capturing (maybe several more milliseconds) while it runs the FFT analysis.

I suspect that inexpensive SPL meters use some simple analog filtering to approximate the A-weighting. But I could be wrong... Electronics are cheap, and software is "free". (Although DSP chips are not cheap, so it's probably done with analog filters.)

Couple of different videos on charger noise.

Also, with 0V are you referring to volts?
Yes 0 volts.

As you are asking and new to this, and this causes confusion.

In any circuit you define one pole of the power supply as 0V, every voltage you measure is then referenced to that, unless otherwise specified. Often, but not always, 0V is the negative connection of the power supply. In telecoms, 0V is the positive connection, so equipment runs on, for example, -50V. In audio circuits a dual supply of +15V and -15V is used, so 0V is in the middle, not the most negative pole of the power supply. As 0V is whatever you define it as, 0V by definition cannot be noisy, however, I leave others to explain the caveats to that statement.

In your case 0V is the negative pole of the power supply.

The terms 0V and ground are used as if they mean the same thing; they are not the same thing but 0V is often connected to ground, meaning they become the same thing. Ground is what it says it is, it is a connection to that muddy stuff you find under your feet when you go outside. More to the point, it is a connection to the environment. A battery powered device in a plastic box has a 0V but no ground. A mains powered device will often have a ground connection for safety, and its 0V will be connected to it.

A common mistake for people new to electronics is to have 2 desperate circuits they want to connect together, they connect the signals but forget to connect 0V, then wonder why it doesn't work. If you read these forums you will find this comes up over and over and over and ..... Circuits are called that because they provide a circuit for the electrons to circulate around. No connection for 0V and they don't have a complete circuit.

bluejets:
Couple of different videos on charger noise.

USB Charger Radio Interference - YouTube

A CURE FOR AM RADIO STATIC IN VEHICLES - YouTube

Thanks! I never thought it would also affect the car's radio.

PerryBebbington:
In any circuit you define one pole of the power supply as 0V, every voltage you measure is then referenced to that, unless otherwise specified. Often, but not always, 0V is the negative connection of the power supply. In telecoms, 0V is the positive connection, so equipment runs on, for example, -50V. In audio circuits a dual supply of +15V and -15V is used, so 0V is in the middle, not the most negative pole of the power supply. As 0V is whatever you define it as, 0V by definition cannot be noisy, however, I leave others to explain the caveats to that statement.

In your case 0V is the negative pole of the power supply.

The terms 0V and ground are used as if they mean the same thing; they are not the same thing but 0V is often connected to ground, meaning they become the same thing. Ground is what it says it is, it is a connection to that muddy stuff you find under your feet when you go outside. More to the point, it is a connection to the environment. A battery powered device in a plastic box has a 0V but no ground. A mains powered device will often have a ground connection for safety, and its 0V will be connected to it.

Ok, now i understand it, thank you :D.

DVDdoug:
You want that in an SPL meter to "simulate" the ear/brain, but you don't want that in a regular or audio circuit because the effect will be applied twice (once by the amplifier and again by your ear) and that does not sound natural.

Ok, i get it.

DVDdoug:
It's not easy! It's not easy to build a good SPL meter!

You could build your own sensor with analog filtering or you could build an analog filter (with op-amps). Or, possibly do it with digitally with [u]DSP[/u] DSP filtering or [u]FFT[/u]. You'd need to use the actual analog output. You can't use the envelope follower output from your sensor because it's a varying DC voltage with no frequency information.

I suspect that inexpensive SPL meters use some simple analog filtering to approximate the A-weighting. But I could be wrong... Electronics are cheap, and software is "free". (Although DSP chips are not cheap, so it's probably done with analog filters.)

I'll search more info of what you suggest on the Internet and see if i can solve the problem. Thanks ;D!