MrDEB
Well-Known Member
here is the db meter code that looks promising. connected leds and after my wife wakes up I can turn on some movie or music to see how well it really works.
Code:
const int MIC = 0; //the microphone amplifier output is connected to pin A0
int adc;
int dB, PdB; //the variable that will hold the value read from the microphone each time
int greenLed=2;
int yellowLed=3;
int redLed=4;
void setup() {
Serial.begin(9600); //sets the baud rate at 9600 so we can check the values the microphone is obtaining on the Serial Monitor
pinMode(3, OUTPUT);
pinMode(4,OUTPUT);
pinMode(2,OUTPUT);
}
void loop(){
PdB = dB; //Store the previous of dB here
adc= analogRead(MIC); //Read the ADC value from amplifer
//Serial.println (adc);//Print ADC for initial calculation
dB = (adc+83.2073) / 11.003; //Convert ADC value to dB using Regression values
if (PdB!=dB)
Serial.println (dB);
if (dB>60)
{
digitalWrite(4, HIGH); // turn the REDLED on (HIGH is the voltage level)
delay(2000); // wait for a second
digitalWrite(4, LOW);
}
if (dB>40)
{
digitalWrite(3,HIGH);
delay(2000);
digitalWrite(3,LOW);
}
if (dB>20)
{
digitalWrite(2,HIGH);
delay(2000);
digitalWrite(2,LOW);
}
}