Arduino Wireless alarm problems

Hi all,
I am need help with code that i have been working on for a while and cant seem to solve
I have built a reciever and transmitter using nrf24 module to act as a alarm for a garage door that is situated in a apartment block the garage is about 50 meters away from the apartment and when the door opens the buzzer in the apartment goes off emediatly.
What i cant seem to solve is to only let the buzzer sound for 5 seconds and then turn off. It must not sound again only 5 seconds and then stop even with the door open.

IF ANYONE CAN HELP WITH THIS PLEASE BE SO KIND:))

here are the codes i have been using:
RECIEVER>>>>>>>>>>>>>>

#include <SPI.h>
#include “RF24.h” // This is the RF24 library that may need to be installed through the Manage Libraries feature in the IDE.

RF24 radio(7, 8);//Create a commuications object for talking to the NRF24L01
const uint64_t send_pipe=0xB01DFACECEL;//These are just arbitrary 64bit numbers to use as pipe identifiers
const uint64_t recv_pipe=0xDEADBEEFF1L;//They must be the same on both ends of the communciations

//As in the transmit code these are the possible alarm codes.
#define CODE_NONE 0
#define CODE_ALARM_TRIGGER 1//CODE_MOTOR_START 1
#define CODE_ALARM_OFF 2//CODE_MOTOR_STOP 2
#define CODE_ALARM_HAS_TRIPED 3

const byte BUZZER_LED=3;

//This is obviously the pin which tells the servo what to do
unsigned long CODE_ALARM_TRIGGERmillis;
unsigned long buzzer_ledonat;
unsigned long turn_on_delay = 200;
unsigned long turn_off_delay = 5000;
bool buzzerledready = false;
bool buzzerledstate = false;

void setup()
{
Serial.begin(9600);//Set up comm with the IDE serial monitor
Serial.println(“Ready for commands”);
radio.begin();//Start up the radio object
radio.setRetries(15,15);//This will improve reliability of the module if it encounters interference
radio.setPALevel(RF24_PA_LOW);//This sets the power low. This will reduce the range. RF24_PA_MAX would increase the range
radio.openWritingPipe(send_pipe);//Thses are the reverse of the transmit code.
radio.openReadingPipe(1,recv_pipe);
radio.startListening();//Give the module a kick
pinMode(BUZZER_LED, OUTPUT);
digitalWrite(BUZZER_LED, LOW);
}

void loop()
{
unsigned long alarm_active_code=CODE_NONE;
unsigned long currentmillis = millis();
unsigned long CODE_ALARM_TRIGGERmilles();

if( radio.available())//Keep checking on each loop to see if any data has come in
{
while(radio.available())//Loop while there is incoming data. The packets are one unsigned long in total so it shoudl only loop once
{
radio.read(&alarm_active_code, sizeof(unsigned long));//Stuff the incoming packet into the motor_code variable
}
radio.stopListening();//We have heard so now we will send an ack
radio.write(&alarm_active_code, sizeof(unsigned long));//Turn the motor code around and send it back
radio.startListening();//Go back to listening as this is what this mostly does

//set the motor_running varible depending upon the code received
if(alarm_active_code==CODE_ALARM_TRIGGER)
{
Serial.println(“ALARM TRIGGERED”);
CODE_ALARM_TRIGGERmillis = currentmillis;
buzzerledready = true;
alarm_active_code=true;
}
if (buzzerledready){
if ((unsigned long)(currentmillis - CODE_ALARM_TRIGGERmillies)>= turn_on_delay){
digitalWrite(BUZZER_LED, HIGH);
buzzerledstate = true;
buzzer_ledonat = currentmillis;
buzzerledready = false;
}
if(buzzerledstate){
if((unsigned long)(currentmillis - buzzer_ledonat) >= turn_off_delay){
digitalWrite(BUZZER_LED, LOW);
}
}
}
else if(alarm_active_code==CODE_ALARM_OFF)
{
Serial.println(“ALARM OFF”);
digitalWrite(BUZZER_LED, LOW);
alarm_active_code=false;

}

}

delay(10);
}

TRANSMITTER>>>>>>>>>>>>>>>>>>>>>>>.
#include <SPI.h>
#include “RF24.h”
RF24 radio(7, 8); // Establish a new RF24 object
const uint64_t send_pipe=0xB01DFACECEL;//This will be this device
const uint64_t recv_pipe=0xDEADBEEFF1L;//This will be the other device

#define RED_PIN 3

void setup()
{
Serial.begin(9600); // Set up communcations with the serial monitor in the arduino IDE
// Prepare the pins for input
pinMode(RED_PIN, INPUT);

Serial.println(“Start”);
radio.begin();// Basically turn on communications with the device
radio.setPALevel(RF24_PA_LOW);//RF24_PA_MAX is max power
radio.setRetries(15,15);//This will improve reliability
radio.openWritingPipe(recv_pipe);//Set up the two way communications with the named device
radio.openReadingPipe(1,send_pipe);

radio.startListening();// Start listening for data which gives the device a kick
}
//These are the four codes that we will work with, the final three being those that are transmitted
#define CODE_NONE 0
#define CODE_ALARM_TRIGGER 1//CODE_MOTOR_START 1
#define CODE_ALARM_OFF 2//CODE_MOTOR_STOP 2
unsigned long message_code=CODE_NONE;//This is where the code to be sent will reside

void loop()
{
//Check the status of the two buttons
int red_pin_status=digitalRead(RED_PIN);

if(red_pin_status==0)
{
message_code=CODE_ALARM_OFF;
}
else if(red_pin_status==1)//Send stop if red is pushed
{
message_code=CODE_ALARM_TRIGGER;
}

else// If nothing is pushed then, well, do nothing.
{
message_code=CODE_NONE;
}

if(message_code!=CODE_NONE)//If something is to be done then send the code
{
radio.stopListening();//We are sending not listening for now
if(!radio.write(&message_code, sizeof(unsigned long)))// Send the message_code and check to see if it comes back false
{
Serial.println(“Failed”);
}

radio.startListening();//Go back to listening and wait for the ack signal.

unsigned long started_waiting_at=micros();//This notes the time
boolean timeout=false;//Assume for the moment that there is no timeout

while(!radio.available())//Keep looping while no ack has come in
{
if(micros()-started_waiting_at>200000)//If the loop has been going for more than 1/5th of a second then give up
{
timeout=true; //Note that it has failed
break;
}
}
if(timeout==true)//If the previous looped marked as failure then
{
Serial.println(“Timeout”);
}
else// If it didn’t fail to ack then read in and printout the results.
{
unsigned long in_data;
radio.read(&in_data, sizeof(unsigned long));
Serial.println("In Data: "+String(in_data));
}
delay(1000);
}

}

(deleted)

Not fully certain how your system works but it looks like you wait for a value of CODE_ALARM_OFF to turn the alarm off. From your description you want to turn the alarm off after 5 seconds even is the code is not received.

The code you posted shuts off the alarm inside the if statement that checks for available data from the radio, so it can never be shut off unless the transmitter sends something.

You need to pull the timeout code out of that if statement, the following should give you some ideas.

      if (buzzerledstate) {
        if ((unsigned long)(currentmillis - buzzer_ledonat) >= turn_off_delay) {
          digitalWrite(BUZZER_LED, LOW);
        }
      }
    }
  }

  // if alarm code is off or it is triggered and has been on long enough
  if (  alarm_active_code == CODE_ALARM_OFF  || ( (alarm_active_code == CODE_ALARM_TRIGGER) && ((currentmillis - buzzer_ledonat) >= turn_off_delay)) )
  {
    Serial.println("ALARM OFF");
    digitalWrite(BUZZER_LED, LOW);
    alarm_active_code = false;

  }