The idea for this sensor reading is to read the noise level in a room and detect whether it would be damaging to someone’s hearing. For the average human ear, a sustained noise level over 70dB or a burst of sound over 120dB can cause harm to the human ear. In order to counteract this, I used a speaker sensor connected to an Arduino to read the noise level in a room and decide whether either of these conditions have been met. If they have then an LED would turn on. So far I have gotten the speaker to read data but I haven’t been able to translate this data into decibels at the moment. The sensor I am currently using measures the noise level in its output by varying the signal to a degree relative to the amount of noise being detected. So if there is a high noise level, the sensor gives data that looks like the following:
If there is a low noise output, the data looks more uniform like a straight line.
I attempted to write a script that would look at the change in this data and use a filter to smooth the delta calculation but this didn’t work very well when I tried it out. My next idea would be to take a moving average of the data over time and then take the max and min of that range as the magnitude of the noise level. With this magnitude, it could then be converted into decibels through tuning of an equation.
//Define Accelerometer Variables for pins #define MICROPHONE A0 double speakerLevel = 0; double prevSpeakerLevel = 0; double delta = 0; double prevDelta = 0; double alpha = 0.8; void setup() { //Setup pins as inputs pinMode(MICROPHONE, INPUT); Serial.begin(9600); } void loop() { speakerLevel = analogRead(MICROPHONE); delta = abs(speakerLevel - prevSpeakerLevel); speakerLevel = alpha*speakerLevel + (1-alpha)*prevSpeakerLevel; delta = alpha*delta + (1-alpha)*prevDelta; prevDelta = delta; Serial.println(speakerLevel); // Serial.println(delta); }