car immobilizer with RFID and vibration sensor

hi friend all,
i still new i arduino but i really like to learn and make project with arduino.
now i try make project immobilizer security for my motorcycle using RFID reader + vibration sensor + arduino nano.
i try write code but not 100% work like what i want.

my plan like this:
1.when i scan RFID system arm (relay on )for 10sec
2.if i put key and ignition sw on with in 10sec motor can start, if over 10sec system enter alarm mode(vibration sensor active),in this mode engine can't start.
3.when engine start (run) and when i turn off engine, system reset ( follow step 1 to start engine)
4.if i scan RFID and leave it for 10sec system will be under alarm mode and relay siren will be ON when vibration sensor sense vibration.
5.to out from alarm mode or off siren when alarm trigger , i just need scan RFID.

for so far step 1 and step 2 my coding pass, but when i add coding for viration sensor it fail..
i also can out or stop siren when alarm trigger by scan RFID.

hope any one can help me..TQ

here my coding: (for full coding refer attachment i take from internet for RFID reader and try to combine with coding vibration sensor, here just " IF" function i use..only this function i know so for hahaha.)

void setup() {                
 Serial.begin(9600);                       // RFID reader SOUT pin connected to Serial RX pin at 2400bps 
// start the SPI library:
SPI.begin();
pinMode(7, OUTPUT); // output vibration sensor relay for alarm
pinMode(8, INPUT); //input for vibration sensor
pinMode(4,INPUT); // input from ignition sw

pinMode(5,OUTPUT); //output relay omilizer loop
pinMode(6,OUTPUT); //output  buzzer
pinMode(chipSelectPin,OUTPUT);             // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin 
digitalWrite(chipSelectPin, LOW);          // Activate the RFID reader
pinMode(NRSTPD,OUTPUT);               // Set digital pin 10 , Not Reset and Power-down
digitalWrite(NRSTPD, HIGH);
MFRC522_Init();  
}

void loop()
{
 uchar i,tmp;
uchar status;
      uchar str[MAX_LEN];
      uchar RC_size;
      uchar blockAddr; //Selection operation block addresses 0 to 63
      String mynum = "";


//Detecting card, return card type
status = MFRC522_Request(PICC_REQIDL, str); 
if (status == MI_OK)
{
                      //Serial.println("Card detected");
//Serial.print(str[0],BIN);
                      //Serial.print(" , ");
//Serial.print(str[1],BIN);
                      //Serial.println(" ");
}

//防冲撞,返回卡的序列号 4字节
status = MFRC522_Anticoll(str);
memcpy(serNum, str, 5);
if (status == MI_OK)
{

                      //Serial.println("The card's number is  : ");
Serial.print(serNum[0]);
                      //Serial.print(" , ");
//Serial.print(serNum[1],BIN);
                      //Serial.print(" , ");
//Serial.print(serNum[2],BIN);
                      //Serial.print(" , ");
//Serial.print(serNum[3],BIN);
                      //Serial.print(" , ");
//Serial.print(serNum[4],BIN);
                      Serial.println(" ");
                      
                      // Should really check all pairs, but for now we'll just use the first
                   
                      if(serNum[0] == 65) {
                        Serial.println("system arm");
                        digitalWrite(6, HIGH); // buzzer on
                        delay(100);
                        digitalWrite(6, LOW);
                        digitalWrite(5, HIGH); // relay on
                        delay(10000);
                        digitalWrite(5, LOW);
                        
                      } 
                       else      {               
                        Serial.println("Incorrect");
                        digitalWrite(6, HIGH);
                        delay(1000);
                        digitalWrite(6, LOW);
                        delay(500);
                        digitalWrite(6, HIGH);
                        delay(1000);
                        digitalWrite(6, LOW);
                      }
                      //delay(5000);
}
              //Serial.println(" ");
MFRC522_Halt(); //Command card into hibernation  


 
long measurement =TP_init(); // vibration sensor start here..
delay(50);
Serial.print("measurment = ");
Serial.println(measurement);
if (digitalRead (4) == LOW && measurement > 100){
  
  digitalWrite(7, HIGH);
  delay(10000);
   
  digitalWrite(7, LOW);}
 
 
else{
  digitalWrite(7, LOW); 
}
}

long TP_init(){
delay(500);
long measurement=pulseIn (8, HIGH);  //wait for the pin to get HIGH and returns measurement
return measurement;   
}

RFID_for_DUKE_200_TEST_3Cwith_vibr_sensor.ino (21.6 KB)

Welcome to the Forum. Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags ("</>") when posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.

If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button.

thanks aarg for infor..
i still new in this forum... :slight_smile: :slight_smile:
i already modify my coding as you instruction..i still find what function i need to use for make it work like this:
1.scan RFID to active (arm ) alarm system (at this time arduino with input from vibration sensor)
2.scan one more time RFID to de activate (disarm) alarm system.
3.if alarm trigger (siren ON ) need scan RFID to stop siren and de activate alarm system.

the problem if when alarm trigger i already set delay timer 3 minutes (i not set yet in my code ), during delay timer run i can't scan RFID to stop this system because need wait until timer end ( wait loop complete ).. :sob:

the problem if when alarm trigger i already set delay timer 3 minutes (i not set yet in my code ), during delay timer run i can't scan RFID to stop this system because need wait until timer end ( wait loop complete ).

The blink without delay example deserves some attention, then. It shows how to record when something happens (the alarm is triggered) and how to make something happen a suitable amount of time later ("shut up, damn it") without blocking other actions.