Your code works perfectly.
If.
I remove the LCD.
I use an LED and digitalWrite(buzzerPin, HIGH) instead of tone.
Try
noTone();
instead of
digitalWrite(buzzerPin, LOW);
to turn off you buzzer.
Below is what I did, I tried very hard not to tinker with the structure and flow of your logic, so it's the buzzer (probable) or the LCD (less so) that's hagging you up…
int buzzerPin = 9;
int buttonPin = 4;
float sinVal;
int toneVal;
boolean soundOn = false;
boolean alarmSet = false;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
pinMode(5, OUTPUT);
Serial.begin(9600);
}
void loop() {
checkButton();
alarmSound();
}
void alarmSound() {
for (int x = 0; x < 25; x++) { // fewer, just so
checkButton();
if (soundOn == true) {
sinVal = sin(x * PI / 180);
toneVal = 2000 + sinVal * 500;
// tone(buzzerPin, toneVal); no, blink an LED on the pin instead
digitalWrite(buzzerPin, HIGH);
delay(25);
digitalWrite(buzzerPin, LOW);
delay(25);
}
else {
digitalWrite(buzzerPin, LOW);
}
}
}
void checkButton() {
//pritisak gumba - mijenjaj stanje alarma
// ifovi radi bouncea
if (digitalRead(buttonPin) == LOW) {
delay(10);
if (digitalRead(buttonPin) == LOW) {
checkSound();
while (digitalRead(buttonPin) == LOW) {
delay(10);
}
}
}
}
void checkSound() {
if (soundOn == true) {
soundOn = false;
Serial.println("Alarm ugašen! Danas će biti dobar dan.");
}
else if (soundOn == false) {
soundOn = true;
Serial.println("Ide gas!");
}
}
Nice to learn a bit of Croatian in the process!
HTH
a7