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;
}