#include <LiquidCrystal.h> // include the LiquidCrystal library
const int micPin1 = A0; // define the pin for the first microphone
const int buzzerPin = 9; // define the pin for the buzzer
const int ledPin = 6; // define the pin for the LED
const int contrast = 50; // define the LCD contrast
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the LCD display
void setup() {
pinMode(buzzerPin, OUTPUT); // set the buzzer pin as output
pinMode(ledPin, OUTPUT); // set the LED pin as output
lcd.begin(16, 2); // initialize the LCD display
analogWrite(6,contrast); // set the LCD contrast
Serial.begin(9600); // initialize the serial monitor
}
void loop() {
// read the values from the microphones
int micValue1 = analogRead(micPin1);
// calculate the sound levels in dB for each microphone
float voltage1 = micValue1 * 5.0 / 1024.0; // convert the first microphone value to voltage (5V reference)
float voltage2 = micValue1 * 5.0 / 1024.0; // convert the second microphone value to voltage (5V reference)
float voltage3 = micValue1 * 5.0 / 1024.0; // convert the third microphone value to voltage (5V reference)
float dB1 = 20 * log10(voltage1/0.0063); // calculate the sound level in dB for the first microphone
float dB2 = 20 * log10(voltage2/0.0063); // calculate the sound level in dB for the second microphone
float dB3 = 20 * log10(voltage3/0.0063); // calculate the sound level in dB for the third microphone
// calculate the average sound level in dB for all microphones
float averageDB = (dB1 + dB2 + dB3) / 3;
// display the sound level on the LCD display and the serial monitor
lcd.setCursor(0, 0); // set the cursor to the first row of the LCD display
lcd.print("Sound Level: "); // print the text "Sound Level: " on the LCD display
lcd.setCursor(0, 1); // set the cursor to the second row of the LCD display
lcd.print(averageDB); // print the average sound level on the LCD display
Serial.print("Sound Level: "); // print the text "Sound Level: " on the serial monitor
Serial.println(averageDB); // print the average sound level on the serial monitor
// control the LED and the buzzer based on the sound level
if (averageDB > 50) { // if the sound level is higher than 70 dB
digitalWrite(ledPin, HIGH); // turn the LED on
tone(buzzerPin, 1000, 500); // turn the buzzer on
} else { // if the sound level is lower than 70 dB
digitalWrite;
}
}