Yes that is part of my project. But I can't figure it out. I got it in a simple version like this:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int sensorPin = 2;
const int speakerPin = 9;
const int pitchPin = 0;
const int resetPin = 7;
int ledPin = 13;
void setup()
{
pinMode(sensorPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop()
{
if (digitalRead(sensorPin) == HIGH)
{
digitalWrite(ledPin, HIGH);
int frequentie = analogRead(pitchPin);
int frequency = map(frequentie, 0, 1023, 100,5000);
int duration = 250;
tone(speakerPin, frequency, duration);
delay(100);
lcd.init();
lcd.backlight();
lcd.print("ALARM");
}
else
{
digitalWrite(ledPin, LOW);
lcd.init();
lcd.backlight();
lcd.print("Online");
}
}
But now I need it to stay HIGH when I have pressed the button. Then stay HIGH till I press the button again. But I have seen several tutorials on the button switch with debounce but I can't get it to work with my system.