Noob here, need help with some homework

Hello, I'm trying to wrap my head around some work from school and I'm getting very lost. My base on Arduino isn't that good but we do know some very, very basic stuff.
Anyways, so basically I'm supposed to make an alarm that can do the following:

  • If the sensor detects something, Alarm 1 triggers

  • If Alarm 1 is turned off or broken, something else has to happen to notify the user

So what I did is set up 2 alarms and an LED. If during the 30 seconds that Alarm 1 activates it breaks, Alarm 2 triggers and the LED starts flash.

Where I'm getting confused is how to code the 30 second period where Alarm 1 is active so that, if it breaks, Alarm 2 can activate. I've been stuck here for an hour and due to the ambiguity of the assignment I'm not really sure how to solve it. Here's the code I have so far, just in case:

int led=13; // auxiliary LED
int pir=2;
int alarma1=12; // main alarm
int alarma2=7; // auxiliary alarm
  
void setup () {
  pinMode (pir, INPUT); 
  pinMode (led, OUTPUT);
  pinMode (alarma1, OUTPUT);
  pinMode (alarma2, OUTPUT);
  
}
    
void loop () 
{
  int estado= digitalRead(pir); // reads sensor's value
  
  if (estado == HIGH)
  {
    digitalWrite(alarma1, HIGH);// if sensor has 1, turns on main alarm
    delay (30000); 
    digitalWrite(alarma1, LOW);
  }
  
  else
  {
    digitalWrite(alarma1, LOW);
  }
}

If Alarm 1 is turned off or broken, something else has to happen to notify the user

How will you detect the alarm being turned off or broken ?

As to timing the 30 second period you cannot use delay() because it stops anything else happening. Use millis() for the timing instead

See Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE

UKHeliBob:
How will you detect the alarm being turned off or broken ?

This is where it kinda gets muddy since the assignment is so vague, but I took it as "if during the 30 second period the alarm 1 is active it suddenly goes off, that's where the alarm 2 comes in".

"if during the 30 second period the alarm 1 is active it suddenly goes off, that's where the alarm 2 comes in".

That is no better. It may mean "If the sensor ceases to detect the input that caused alarm 1 to sound in a period of 30 seconds after it was triggered then sound alarm 2" This implies that the sensor will normally stay active for at least 30 seconds. What type of sensor is it and what triggers it ?

What is the exact wording of your assignment ?

I think it's more of a "if, during the 30 seconds the alarm is triggered, it ceases to function, then sound alarm 2". The sensor is a PIR sensor, and as such is triggered by movement.
As for the assignment, there's not really something too exact since, due to online classes, it was fully described on an audio message where the teacher fumbles a lot of his wording. Initially, it was "an alarm system on a house" and then later added the "auxiliary system in case someone trying to enter the house breaks one of the alarm speakers". So basically, online classes are messy and we we're kinda left to our own devices, so I'm trying to make the most of it.

Also, just in case, we're not using actual Arduino, we're using Tinkercad for simulation purposes so we don't have to take the assignment too literally, it's more of a conceptual thing.

Here is some code you can start with.

As mentioned you need to decide how alarm two is to be incorporated.

const byte pir          = 2;
const byte alarma2      = 7;  // auxiliary alarm
const byte alarma1      = 11; // main alarm
const byte led          = 12; // auxiliary LED
const byte heartbeatLED = 13; // heartbeat LED

byte lastEstado;

bool timingEnableFlag = false;

unsigned long currentMillis;
unsigned long switchMillis;
unsigned long timingMillis;
unsigned long heartbeatMillis;

//***********************************************************************************
void setup ()
{
  pinMode (pir, INPUT);
  
  pinMode (led, OUTPUT);
  pinMode (alarma1, OUTPUT);
  pinMode (alarma2, OUTPUT);
  pinMode (heartbeatLED, OUTPUT);

} //END of setup()

//***********************************************************************************
void loop ()
{
  currentMillis = millis();
  
  //******************************
  //toggle the heartbeat LED every 500ms, shows if the code is blocking
  if (currentMillis - heartbeatMillis >= 500)
  {
    //restart the TIMER
    heartbeatMillis = currentMillis;

    //toggle LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //******************************
  checkSwitches();

  //******************************
  if (timingEnableFlag == true && currentMillis - timingMillis >= 3000ul) //change to 30000ul later
  {
    //disable timing
    timingEnableFlag = false;

    //turn off the alarm
    digitalWrite(alarma1, LOW);
  }

} //END of loop()

//***********************************************************************************
void checkSwitches()
{
  if (currentMillis - switchMillis < 50)
  {
    //not time to check the switches
    return;
  }

  //restart the TIMER
  switchMillis = currentMillis;


  //******************************                            p i r
  byte estado = digitalRead(pir);

  //was there a change in state ?
  if ( lastEstado != estado)
  {
    //update to the new state
    lastEstado = estado;

    //alarm detected ?
    if (estado == HIGH)
    {
      //turn on the alarm
      digitalWrite(alarma1, HIGH);

      //enable the TIMER
      timingEnableFlag = true;

      //start the TIMER
      timingMillis = currentMillis;
    }

    else
    {
      //alarm is over
      digitalWrite(alarma1, LOW);

      //disable the TIMER
      timingEnableFlag = false;
    }
  }

} //END of checkSwitches()


//***********************************************************************************

if, during the 30 seconds the alarm is triggered, it ceases to function

We are not getting anywhere

How will you know that the alarm or sensor has failed ? What are you going to test or measure ? What constitutes failure ?

I think that you should ask for a written specification of the assignment

And what exactly is the "alarm"? A klaxon, a siren, a horn, a flashing light, an email, etc.? The detection of failure really depends on what it is.

Paul