What's new

Help Library Noise Alarm using Arduino

garachi30

Addict
Ma'am/Sir, baka po pwede magpatulong kung ano po kaya ang code sa arduino, ito po ung project, Kapag po nakadetect ng 75 and up decibel yung sensor, iilaw po ung 4 led lights and magdidisplay sa LCD ng SILENCE na word?


Thank you in advance po
 
Sure, I can help you with that. Here's the code that you can use for your project:

Code:
C++
#include <LiquidCrystal.h> // include the LCD library

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // set the LCD pins

const int led1 = 6; // set the LED pins
const int led2 = 7;
const int led3 = 8;
const int led4 = 9;

const int noiseSensor = A0; // set the noise sensor pin

void setup() {
  pinMode(led1, OUTPUT); // set the LED pins as output
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);

  lcd.begin(16, 2); // set the LCD size

  lcd.setCursor(0, 0); // set the cursor position
  lcd.print("Noise Alarm"); // display the title on the LCD
}

void loop() {
  int noiseLevel = analogRead(noiseSensor); // read the noise sensor value

  if (noiseLevel >= 75) { // check if the noise level is 75 or higher
    digitalWrite(led1, HIGH); // turn on the LEDs
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);

    lcd.setCursor(0, 1); // set the cursor position
    lcd.print("SILENCE"); // display the message on the LCD
  } else { // if the noise level is lower than 75
    digitalWrite(led1, LOW); // turn off the LEDs
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);

    lcd.setCursor(0, 1); // set the cursor position
    lcd.print("        "); // clear the message on the LCD
  }
}

I hope this helps. Let me know if you have any questions or if you need further assistance.
 
Sure, I can help you with that. Here's the code that you can use for your project:

Code:
C++
#include <LiquidCrystal.h> // include the LCD library

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // set the LCD pins

const int led1 = 6; // set the LED pins
const int led2 = 7;
const int led3 = 8;
const int led4 = 9;

const int noiseSensor = A0; // set the noise sensor pin

void setup() {
  pinMode(led1, OUTPUT); // set the LED pins as output
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);

  lcd.begin(16, 2); // set the LCD size

  lcd.setCursor(0, 0); // set the cursor position
  lcd.print("Noise Alarm"); // display the title on the LCD
}

void loop() {
  int noiseLevel = analogRead(noiseSensor); // read the noise sensor value

  if (noiseLevel >= 75) { // check if the noise level is 75 or higher
    digitalWrite(led1, HIGH); // turn on the LEDs
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);

    lcd.setCursor(0, 1); // set the cursor position
    lcd.print("SILENCE"); // display the message on the LCD
  } else { // if the noise level is lower than 75
    digitalWrite(led1, LOW); // turn off the LEDs
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);

    lcd.setCursor(0, 1); // set the cursor position
    lcd.print("        "); // clear the message on the LCD
  }
}

I hope this helps. Let me know if you have any questions or if you need further assistance.
paano po kung kailangan po maooff ung alarm ng specific time like 7:00am to 7:10am, 12:00pm to 12:10pm and 3:00pm to 3:10pm
 
paano po kung kailangan po maooff ung alarm ng specific time like 7:00am to 7:10am, 12:00pm to 12:10pm and 3:00pm to 3:10pm
To turn off the alarm during specific times, you can use the Time library in Arduino to define a time range during which the alarm should be turned off. Here's an updated code that includes this functionality:

Code:
C++
#include <LiquidCrystal.h> // include the LCD library
#include <TimeLib.h> // include the Time library

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // set the LCD pins

const int led1 = 6; // set the LED pins
const int led2 = 7;
const int led3 = 8;
const int led4 = 9;

const int noiseSensor = A0; // set the noise sensor pin

void setup() {
  pinMode(led1, OUTPUT); // set the LED pins as output
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);

  lcd.begin(16, 2); // set the LCD size

  lcd.setCursor(0, 0); // set the cursor position
  lcd.print("Noise Alarm"); // display the title on the LCD

  setSyncProvider(RTC.get); // set the time synchronization
  if (timeStatus() != timeSet) { // check if the time has been set
    lcd.setCursor(0, 1); // set the cursor position
    lcd.print("RTC not synced"); // display an error message on the LCD
  }
}

void loop() {
  int noiseLevel = analogRead(noiseSensor); // read the noise sensor value

  if (noiseLevel >= 75 && isAlarmEnabled()) { // check if the noise level is 75 or higher and the alarm is enabled
    digitalWrite(led1, HIGH); // turn on the LEDs
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);

    lcd.setCursor(0, 1); // set the cursor position
    lcd.print("SILENCE"); // display the message on the LCD
  } else { // if the noise level is lower than 75 or the alarm is disabled
    digitalWrite(led1, LOW); // turn off the LEDs
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);

    lcd.setCursor(0, 1); // set the cursor position
    lcd.print("        "); // clear the message on the LCD
  }
}

bool isAlarmEnabled() { // check if the alarm is enabled based on the current time
  time_t now = now(); // get the current time
  int hour = hour(now); // get the current hour
  int minute = minute(now); // get the current minute

  if ((hour == 7 && minute >= 0 && minute <= 10) || (hour == 12 && minute >= 0 && minute <= 10) || (hour == 15 && minute >= 0 && minute <= 10)) {
    // if the current time is within one of the specified ranges, return false to disable the alarm
    return false;
  } else {
    // if the current time is outside of the specified ranges, return true to enable the alarm
    return true;
  }
}

In this updated code, the isAlarmEnabled() function is used to check if the current time is within one of the specified time ranges during which the alarm should be turned off. If the current time is within one of these ranges, the function returns false to disable the alarm. If the current time is outside of the specified ranges, the function returns true to enable the alarm.

I hope this helps. Let me know if you have any questions or if you need further assistance.
 
try mo gumamit ng analog sound sensor tapos magsounds ka ng 75 db then kunin mo yung makukuhang input ng sensor yun yung gawan mo ng condition. di lang sya ganun kaaccurate since magiiba yung yung lakas ng sounds depende sa layo ng source pati ng sensor.
 
Back
Top