Ok so @PaulS,
Let's say if i were to remove the else since it will make it complicated.. i changed it to else if and the condition is almost the same except for detecting the state of the switch which is HIGH, but after changing, i tried to run and it is almost the same with my previous code..
i tried to off the switch, it works by stopping the buzzer but once i on the switch, it continued to sound the buzzer (It started and ended the alarm perfectly, did not exceed nor ring before the alarm)
But i just want the alarm to stop once i OFF the switch (Which i dont want it to sound anymore)
void alarm1() //E.g. This is the first alarm for the medicine
{
state = digitalRead(sensor);
if( Hor == 20 && (Min == 11 || Min == 12) && state == 0) //Comparing the current time with the Alarm time
{
Buzzer();
lcd.clear();
lcd.print("1st Alarm ON");
lcd.setCursor(0,1);
lcd.print("Morning Medicine");
}
else if ( Hor == 20 && (Min == 11 || Min == 12) && state == 1)
{
noTone(buz);
}
delay(200);
}