Alarm Mute over a certain time.

Hi everyone.

Have some issues with a alarm system I’m trying to set up for a friend.

The alarm points works but I have trouble muting a buzzer for a period on individual alarm without block a buzzer for a new alarm in the meantime.

The buzzer also stops for some reason when reading the other alarms, guess it’s because the cod is very crude.

if you feel for it pleas com white comments and suggestions.

// Linus

float temp;
float mute;
const int buzzer = 7;
const int buttonPin = 2;
const int mutePin =  50;
unsigned long startTime;
int oldState;

void setup() {
  Serial.begin(9600);
  pinMode(30,OUTPUT);         // LED Intermediat Shaft Bearing 1.           100.001 
  pinMode(31,OUTPUT);         // LED Intermediat Shaft Bearing 2.           100.002
  pinMode(32,OUTPUT);         // LED Shaft Bearing.                         100.003
  pinMode(33,OUTPUT);         // LED Stern Tube Oil Temp.                   200.001
  pinMode(34,OUTPUT);         // LED Gear Box Oil Temp.                     400.001
  pinMode(35,OUTPUT);         // LED Hydraulic Pump Bowthruster Oil Temp.   500.001
  pinMode(36,OUTPUT);         // LED ME1 Exhaust Temp.                      601.001
  pinMode(37,OUTPUT);         // LED ME2 Exhaust Temp.                      602.001
  pinMode(mutePin, OUTPUT);      
  pinMode(buttonPin, INPUT); 
  pinMode(buzzer, OUTPUT);    // Pin 7.
  

  }

void loop() 
{
  {
  int sensorState = digitalRead(buttonPin);
  if (sensorState == LOW) //inverted
  {
    if (oldState == HIGH)
    {     
      Serial.println("Button Pushed");
      digitalWrite(mutePin, HIGH);   // turns the motor on
      startTime = millis();
    } 
  }
  oldState = sensorState;
  if (digitalRead(mutePin == HIGH))
  {
    if (millis() - startTime >= 10000UL)
    {
      Serial.println("Timer Expired");
      digitalWrite(mutePin, LOW);
    }
  }
}
 


    // Intermediat Shaft Bearing 1.   100.001
  temp = analogRead(A0);
  temp = temp * 0.48828125;
  Serial.print(" Temperature ISB1: ");
  Serial.print(temp);
  Serial.print("*C ");
  Serial.println();
  delay(500);
  

      if(temp >= 19)digitalWrite(30, HIGH);
      
          if(temp <= 19)digitalWrite (30, LOW);

      if((temp >= 19)and(mutePin == LOW))tone(buzzer,2000); 
      
          if(mutePin == HIGH)noTone(buzzer);

      if(temp >= 19)Serial.print("TEMP ALARM INTERMEDIAT SHAFT BEARING 1 100.001 ");
       

    

      // Intermediat Shaft Bearing 2.   100.002
  temp = analogRead(A1);
  temp = temp * 0.48828125;
  Serial.print(" Temperature ISB2: ");
  Serial.print(temp);
  Serial.print("*C ");
  Serial.println();
  delay(500);

        if(temp >= 26) digitalWrite(31, HIGH);
      
          if(temp <= 26)digitalWrite (31, LOW);

      if(temp >= 26)tone(buzzer,2000);

          if(temp <= 26)noTone(buzzer);

      if(temp >= 26)Serial.print("TEMP ALARM INTERMEDIAT SHAFT BEARING 2 100.002 ");


        // Shaft Bearing.   100.003
  temp = analogRead(A2);
  temp = temp * 0.48828125;
  Serial.print(" Temperature SB: ");
  Serial.print(temp);
  Serial.print("*C ");
  Serial.println();
  delay(500);

        if(temp >= 26) digitalWrite(32, HIGH);
      
          if(temp <= 26)digitalWrite (32, LOW);

      if(temp >= 26)tone(buzzer,2000);

          if(temp <= 26)noTone(buzzer);

      if(temp >= 26)Serial.print("TEMP ALARM SHAFT BEARING 100.003 ");



         // Stern Tube Oil Temp.   300.001
  temp = analogRead(A3);
  temp = temp * 0.48828125;
  Serial.print(" Temperature Stern Tube: ");
  Serial.print(temp);
  Serial.print("*C ");
  Serial.println();
  delay(500);

        if(temp >= 26) digitalWrite(33, HIGH);
      
          if(temp <= 26)digitalWrite (33, LOW);

      if(temp >= 26)tone(buzzer,2000);

          if(temp <= 26)noTone(buzzer);

      if(temp >= 26)Serial.print("TEMP ALARM STERN TUBE 300.001 ");


          // Gear Box Oil Temp.   400.001
  temp = analogRead(A4);
  temp = temp * 0.48828125;
  Serial.print(" Temperature Gear Box: ");
  Serial.print(temp);
  Serial.print("*C ");
  Serial.println();
  delay(500);

        if(temp >= 26) digitalWrite(34, HIGH);
      
          if(temp <= 26)digitalWrite (34, LOW);

      if(temp >= 26)tone(buzzer,2000);

          if(temp <= 26)noTone(buzzer);

      if(temp >= 26)Serial.print("TEMP ALARM GEAR BOX 400.001 ");


           // Hydraulic Pump Bowthruster Oil Temp.   500.001
  temp = analogRead(A5);
  temp = temp * 0.48828125;
  Serial.print(" Temperature Hydraulic Pump BOW: ");
  Serial.print(temp);
  Serial.print("*C ");
  Serial.println();
  delay(500);

        if(temp >= 26) digitalWrite(35, HIGH);
      
          if(temp <= 26)digitalWrite (35, LOW);

      if(temp >= 26)tone(buzzer,2000);

          if(temp <= 26)noTone(buzzer);

      if(temp >= 26)Serial.print("TEMP ALARM HYDRAULIC PUMP BOW 500.001 ");


             // ME1 Exhaust Temp.   601.001
  temp = analogRead(A6);
  temp = temp * 0.48828125;
  Serial.print(" Temperature Hdraulic Pump BOW: ");
  Serial.print(temp);
  Serial.print("*C ");
  Serial.println();
  delay(500);

        if(temp >= 26) digitalWrite(36, HIGH);
      
          if(temp <= 26)digitalWrite (36, LOW);

      if(temp >= 26)tone(buzzer,2000);

          if(temp <= 26)noTone(buzzer);

      if(temp >= 26)Serial.print("TEMP ALARM ME1 EXHAUST HIGH 601.001 ");


            // ME2 Exhaust Temp.   602.001
  temp = analogRead(A7);
  temp = temp * 0.48828125;
  Serial.print(" Temperature Hdraulic Pump BOW: ");
  Serial.print(temp);
  Serial.print("*C ");
  Serial.println();
  delay(500);

        if(temp >= 26) digitalWrite(37, HIGH);
      
          if(temp <= 26)digitalWrite (37, LOW);

      if(temp >= 26)tone(buzzer,2000);

          if(temp <= 26)noTone(buzzer);

      if(temp >= 26)Serial.print("TEMP ALARM ME2 EXHAUST HIGH 602.001 ");

}

guess it's because the cod is very crude.

Maybe you need a grouper or a halibut or a salmon, instead. 8)

      digitalWrite(mutePin, HIGH);   // turns the motor on

What? What do you REALLY have connected to that pin?

  if (digitalRead(mutePin == HIGH))

Reading from the true pin or the false pin is rarely the right thing to do.

YOU control the state of the mutePin. Why do you think you need to read its state, even if you were doing it correctly?

          if(mutePin == HIGH)noTone(buzzer);

50 is never going to equal 1...

 if((temp >= 19)and(mutePin == LOW))

The syntax for ‘and’ between 2 test conditions is &&:

 if(temp >= 19 && mutePin == LOW)

You have several times the same kind of ifs, such as:

      if(temp >= 26) digitalWrite(32, HIGH);
      if(temp <= 26)digitalWrite (32, LOW);
      if(temp >= 26)tone(buzzer,2000);
      if(temp <= 26)noTone(buzzer);
      if(temp >= 26)Serial.print("TEMP ALARM SHAFT BEARING 100.003 ");

You can simplify this by using if - else:

      if(temp >= 26) digitalWrite(32, HIGH);
      if(temp <= 26) {
        digitalWrite (32, LOW);
        noTone(buzzer);
      } else {
        tone(buzzer,2000);
        Serial.print("TEMP ALARM SHAFT BEARING 100.003 ");
      }

The syntax for 'and' between 2 test conditions is &&:

One can overload operators. The Arduino understands that and means && and that or means ||.

Personally, I still expect to see && and || in if statements.

I didn't know that, thanks for the info...

(BTW the cod thing is fun !!)

LOL.

I see the fish rely made your day :slight_smile:

Anyway, thanks for all the input, I will try to make some changes based on your suggestions.

PaulS

lesept

Thank you both.