Hi everyone
!
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
.
(I hope i've given enough information, i've also posted the code).
Thanks for the replies. ![]()
#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);
}
}



