/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: Sound Monitor - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2024-10-23 11:26:31 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* I want the lcd to display the sound level when the */ /* sound sensor detects a sound and the led should */ /* glow if it crosses a certain limit and the buzzer */ /* should beep */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include #include //https://github.com/marcoschwartz/LiquidCrystal_I2C /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF I2C PINS *****/ const uint8_t display_LCD1602I2C_I2C_PIN_SDA_A4 = A4; const uint8_t display_LCD1602I2C_I2C_PIN_SCL_A5 = A5; const uint8_t display_LCD1602I2C_I2C_SLAVE_ADDRESS = 39; /****** DEFINITION OF PIN NUMBERS *****/ // Define the pin numbers for the sound sensor, LED, and buzzer const uint8_t SOUND_SENSOR_PIN = A0; // Analog pin for sound sensor const uint8_t LED_PIN = 9; // Digital pin for LED const uint8_t BUZZER_PIN = 10; // Digital pin for Buzzer /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ // Initialize the LiquidCrystal_I2C object with the I2C address and dimensions of the LCD LiquidCrystal_I2C lcd(display_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // 16 columns and 2 rows void setup(void) { // Initialize the LCD lcd.init(); // Initialize the LCD lcd.backlight(); // Turn on the backlight // Initialize the LED and Buzzer pins pinMode(LED_PIN, OUTPUT); // Set LED pin as output pinMode(BUZZER_PIN, OUTPUT); // Set Buzzer pin as output // Display initial message on the LCD lcd.setCursor(0, 0); // Set cursor to first row, first column lcd.print("Sound Level:"); // Print message on the first row } void loop(void) { // Read the sound level from the sound sensor int soundLevel = analogRead(SOUND_SENSOR_PIN); // Read the sound level // Display the sound level on the LCD lcd.setCursor(0, 1); // Set cursor to second row, first column lcd.print(" "); // Clear previous sound level lcd.setCursor(0, 1); // Reset cursor to the beginning of the second row lcd.print(soundLevel); // Print the sound level // Check if the sound level exceeds a certain limit (e.g., 300) if (soundLevel > 300) { digitalWrite(LED_PIN, HIGH); // Turn on the LED digitalWrite(BUZZER_PIN, HIGH); // Turn on the Buzzer delay(100); // Buzzer on for 100 milliseconds digitalWrite(BUZZER_PIN, LOW); // Turn off the Buzzer } else { digitalWrite(LED_PIN, LOW); // Turn off the LED } delay(500); // Delay for half a second before the next reading } /* END CODE */