Mini alarm system

Hi, I am new to Arduino and I have completed one of my first projects and I designed a mini alarm system currently with one magnetic sensor. I have made it to arm and disarm by RFID tags. But when I have tested it the problem is because it can not be disarmed during the exit or entry delay, so if you please can tell me how to moderate my code to be able to disarm it even during the entry and exit delay.

Thanks for your answers;)

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

String read_rfid;
String ok_rfid_1="849d74a7"; //RFID TAG for arming the system
String ok_rfid_2="e7fd54c5"; //RFID TAG for disarming the system

// Alarmni sistem za detekcijo gibanja
int counter=0; //Counts the number of occured alarms
int pirsensor=2; //PIR sensor pin (currently not in use)
int buzzer=6; //Buzzer pin
int buttonState=0; //For door/window magnetic contact
int alarmstatus = 0; //Sets the alarm into disarm (1=armed; 0=disarmed)
void beep(unsigned char delayms){
analogWrite(6, 70); // Almost any value can be used except 0 and 255
// experiment to get the best tone
delay(delayms); // wait for a delayms ms
analogWrite(6, 0); // 0 turns it off
// wait for a delayms ms
}

void beep1(){ //For the first part of entry delay
analogWrite(6, 70);
}

void disarming(){ //Disarming confirmation beep
beep(90);
delay(50);
beep(50);
delay(50);
beep(50);
delay(50);
beep(50);
delay(50);
beep(50);

if(counter>=1){
Serial.println("System is DISARMED, ALARM MEMORY!!!"); //If the counter is positive that means that an alarm or more occured during the alarm was armed
counter=0;}
else{
Serial.println("System is DISRMED, no alarm memory");}
};
void arming(){ //This function runs when we scan the right RFID tag for arming
Serial.println("Arming AWAY exit delay in progress");
beep(80);
delay(200);
beep(100);
delay(10);
beep(100);
delay(10);
beep(100);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(350);
delay(900);
beep(100);
delay(10);
beep(100);
delay(10);
beep(100);
delay(700);
beep(100);
delay(10);
beep(100);
delay(10);
beep(100);
delay(700);
beep(100);
delay(10);
beep(100);
delay(10);
beep(100);
delay(700);
beep(100);
delay(10);
beep(100);
delay(10);
beep(100);
delay(700);
beep(100);
delay(10);
beep(100);
delay(10);
beep(100);
delay(400);
beep(200);
Serial.println("Armed AWAY all secure");
}

void entrydelayandsounding(){ //Entry delay function, occurs when the sensor is trigerred
Serial.println("Sensor: ENTRY DOOR");
Serial.println("Entry delay is active");
beep1();
delay(13000);

beep(100);
delay(10);
beep(100);
delay(10);
beep(100);
delay(700);
beep(100);
delay(10);
beep(100);
delay(10);
beep(100);
delay(700);
beep(100);
delay(10);
beep(100);
delay(10);
beep(100);
delay(700);
beep(100);
delay(10);
beep(100);
delay(10);
beep(100);
delay(700);
beep(100);
delay(10);
beep(100);
delay(10);
beep(100);
delay(400);
beep(200);
Serial.println("System is in alarm"); //Here the relay turns on for the siren
counter=counter+1;
pinMode(8, OUTPUT);
digitalWrite(8,LOW);
delay(8000);
digitalWrite(8,HIGH);
Serial.println("Armed AWAY all secure");

}

void setup(){
Serial.begin(9600);
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card

Serial.println("DISARMED, ready to arm"); //At the powering up this text shows up and short beep sounds
beep(30);

}
void dump_byte_array(byte buffer, byte bufferSize) {
read_rfid="";
for (byte i = 0; i < bufferSize; i++) {
read_rfid=read_rfid + String(buffer
, HEX);*

  • }*
    }

void loop() {

  • buttonState = digitalRead(pirsensor);*

  • if (buttonState == LOW && alarmstatus== 1){*

  • entrydelayandsounding();*

  • }*

  • if (buttonState == LOW && alarmstatus==0){*

  • Serial.println("Not ready to arm: ENTRY DOOR");*

  • delay(3000);*

  • Serial.println("DISARMED, ready to arm");}*

  • // Look for new cards*

  • if ( ! mfrc522.PICC_IsNewCardPresent())*

  • return;*

  • // Select one of the cards*

  • if ( ! mfrc522.PICC_ReadCardSerial())*

  • return;*

  • dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);*

  • Serial.println(read_rfid);*

  • if (read_rfid==ok_rfid_1) {*

  • //ok, open the door.*

  • arming();*

  • alarmstatus=1;*

  • }*

  • if(read_rfid==ok_rfid_2) {*

  • alarmstatus=0;*

  • disarming();*

  • digitalWrite(8,HIGH);*

  • }*
    simplealarmDELAY10s-zrfidom-exit3test.ino (5.3 KB)

so if you please can tell me how to moderate my code to be able to disarm it even during the entry and exit delay.

Sure. DO NOT USE DELAY().

See the blink without delay example for some clues.

But how do I specify the exit and entry delay with Blink no delay function?

But how do I specify the exit and entry delay with Blink no delay function?

If you were the gatekeeper, with nothing but a pencil, paper, and watch, how would YOU perform the task?

You want some beeping to happen, some number of times, some interval apart, when some event occurs.

So, when the event occurs, you set a flag indicating that entry beeping should happen.

Periodically (read that as on every pass through loop()), you check to see if entry beeping should be happening, and, if so, if it is time to start the annoying noise for the nth time or if it is time to stop the infernal racket, based on whether noise is being made, or not.

If it is time to shut the damned noise maker off, do it, and increment the number of times you've annoyed everyone with the racket.

If it is time to make more freaking noise, start the noise maker and make note of the fact that noise is being made.