Arduino Code For Earthquake Alert System
Arduino Code
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Define the LCD pins
const int buttonPin = 7; // Push button pin
const int buzzerPin = 6; // Buzzer pin
const int ledPin = 8; // LED pin
bool earthquakeAlert = false; // Flag to indicate if an earthquake alert is active
void setup() {
lcd.begin(16, 2); // Initialize the LCD
pinMode(buttonPin, INPUT_PULLUP); // Set the button pin as an input with internal pull-up resistor
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
lcd.print(" Earthquake Alert System"); // Initial text
lcd.setCursor(0, 1);
lcd.print("");
// Scroll the text
for (int position = 0; position < 16; position++) {
lcd.scrollDisplayLeft();
delay(200);
}
delay(500); // Delay after scrolling
lcd.clear();
}
void loop() {
if (!earthquakeAlert) {
lcd.setCursor(0, 0);
lcd.print(" Made By Sufian ");
}
if (digitalRead(buttonPin) == LOW) { // Check if the button is pressed
earthquakeAlert = true;
lcd.setCursor(0, 0);
lcd.print(" Earthquake!!!!!");
lcd.setCursor(0, 1);
lcd.print(" Stay Alert ");
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(5000); // Stay in this state for 10 seconds
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
digitalWrite(ledPin, LOW); // Turn off the LED
lcd.clear();
earthquakeAlert = false;
}
}
Comments
Post a Comment