#include <LiquidCrystal.h>
// Set up the LCD screen
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Set up the buzzer
int buzzerPin = 9;
// Set up the push button switch
int switchPin = 7;
// Variable to store the previous state of the push button switch
int prevSwitchState = HIGH;
void setup() {
// Set up the LCD screen
lcd.begin(16, 2);
// Set up the buzzer
pinMode(buzzerPin, OUTPUT);
// Set up the push button switch
pinMode(switchPin, INPUT);
}
void loop() {
// Check the push button switch
int switchState = digitalRead(switchPin);
if (switchState == LOW && prevSwitchState == HIGH) {
// Push button switch is touched
digitalWrite(buzzerPin, HIGH);
lcd.clear();
lcd.print("The touch sensor");
lcd.setCursor(0, 1);
lcd.print("has been disconnected");
} else {
// Push button switch is not touched
digitalWrite(buzzerPin, LOW);
lcd.clear();
lcd.print("Touch sensor is OK");
}
prevSwitchState = switchState;
delay(100);
}