#include <LiquidCrystal.h>
const int tiltSensorPin = 2;
const int lcdRs = 12, lcdE = 11, lcdD4 = 5, lcdD5 = 4, lcdD6 = 3, lcdD7 = 2;
const int buzzerPin = 8;
const int relayPin = 9;
LiquidCrystal lcd(lcdRs, lcdE, lcdD4, lcdD5, lcdD6, lcdD7);
void setup() {
lcd.begin(16, 2);
pinMode(tiltSensorPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(relayPin, OUTPUT);
}
void loop() {
int tiltState = digitalRead(tiltSensorPin);
if (tiltState == LOW) {
lcd.setCursor(0, 0);
lcd.print("Tilt Detected!");
tone(buzzerPin, 1000); // alarm sound
digitalWrite(relayPin, LOW); // shutdown
delay(1000);
shutdownArduino();
} else {
lcd.setCursor(0, 0);
lcd.print("Normal");
noTone(buzzerPin); // stop alarm
digitalWrite(relayPin, HIGH); // normal operation
}
}
void shutdownArduino() {
// Shutdown Arduino code here
// e.g., system("shutdown /s /t 1");
}