#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Initialize the LCD with the I2C address and dimensions
const int potPin = 27; // Analog pin connected to the potentiometer
const int vibrationThreshold = 2000; // Adjust this threshold as needed
bool vibrationDetected = false; // Track the vibration status
void setup() {
Serial.begin(115200);
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
// Set up the potentiometer pin
pinMode(potPin, INPUT);
}
void loop() {
int potValue = analogRead(potPin); // Read the value from the potentiometer
// Display the potentiometer value on the serial monitor
Serial.print("Vibration: ");
Serial.println(potValue);
// Check if the potentiometer value exceeds the vibration threshold
bool newVibrationStatus = (potValue >= vibrationThreshold);
// Update the LCD only when the vibration status changes
if (newVibrationStatus != vibrationDetected) {
vibrationDetected = newVibrationStatus;
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0);
if (vibrationDetected) {
lcd.print("Vibration: Detected");
} else {
lcd.print("Vibration: None "); // Adding spaces to clear the line fully
}
}
delay(500); // Adjust delay as needed for your application
}