Go Down

Topic: Our School Project - Security System using RFID + Biometric Fingerprint Scanner (Read 5314 times) previous topic - next topic

clargin

Hello there everyone! I'm actually new here and I'm hoping I could get some help from experts out there. So, here's our school project details:

Components:
1 - Arduino ATMEGA2560 Board
1 - Biometric Fingerprint Scanner - FPS (to be connected to Serial1 of Arduino ATMEGA2560)
2 - Passive RFID readers (to be connected to  Serial2 and Serial3 of Arduino ATMEGA2560)
x - Switches

There would be three modes of operation:
1. Adding of New Users
2. Deleting of Currently Enrolled Users
3. Reading the State of Currently Enrolled Users, whether they have previously logged in or logged out of the system

Our problem:

ADDING OF NEW USERS
1st readRFID() - gets the RFID card data
2nd getEmptyID() - gets an available location within the biometric fingerprint scanner where biometric data would be saved
3rd enroll_data() - scans the fingerprint and saves it on the location taken from the getEmptyID() function

When I try to put the getEmptyID() and enroll_data() function in the loop structure, there is actually no output.
However, if only one function is present in the loop structure, we can see an output from the Serial Monitor, which is either printing an available location or asking the user to enroll his/her fingerprint data.

**Code attached. I removed some parts of the code.


GaryP

There is something wrong with your rar. You should attack your code like others do it, using #-button, and paste your  code in it.

Cheers,
kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

clargin

Sorry. I didn't notice that. I tried pasting it here but it extends the maximum length of characters per post so I attached it.


clargin

Code: [Select]
#include <LiquidCrystal.h> //Import library for LCD
#include <EEPROM.h> //Import library for EEPROM
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Initialize pins to be used for LCD

//VARIABLES FOR FINGERPRINT
int cks=0;
byte test [] = {0x55,0xAA,0x50,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte enroll [] = {0x55,0xAA,0x03,0x01,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte identify [] = {0x55,0xAA,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte clearalltemplate [] = {0x55,0xAA,0x06,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte cleartemplate [] = {0x55,0xAA,0x05,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte getemptytemp [] = {0x55,0xAA,0x07,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte cancelop[]=  {0x55,0xAA,0x30,0x01,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte standby[]=  {0x55,0xAA,0x17,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte temp_no=0x01;
byte r_data[24];
byte prev;

byte cmd[24];

//VARIABLES FOR RFID
int i = 0;
int curAdd=0;
byte val = 0;
byte code[6];
byte checksum = 0;
byte bytesread = 0;
byte tempbyte = 0;

byte mode = 1;

void setup(){
   Serial.begin(9600); //For Serial Monitor
   Serial1.begin(115200); //For Biometric Fingerprint Scanner
   Serial2.begin(9600); // For RFID Reader 1
   Serial3.begin(9600); //For RFID Reader 2
}
void loop(){
 sendGetEmptyID();
 sendEnroll();
}

void sendTest()
{
   for (int i = 0; i<7;i++)
   {
     cks = cks + test[i];
   }
   
   test[22] = cks&0xFF;
   test[23] = (cks - test[22])/256;
 
   for (int i = 0; i<24; i++)
   {
     Serial1.write(test[i]);
     //Serial.print(test[i]);
   }
   cks=0;
}

void sendEnroll()
{
  enroll[6]=temp_no;
  send_command:
  for (int i = 0; i<7; i++)
  {
    cks = cks + enroll[i];
  }

  enroll[22]=cks&0xFF;
  enroll[23]=(cks - enroll[22])/256;

  for (int i = 0; i<24; i++)
  {
    Serial1.write(enroll[i]);
  }
  cks=0;
}

void sendIdentify()
{
    for (int i = 0; i<7; i++)
    {
      cks = cks + identify[i];
    }

     identify[22]=cks&0xFF;
     identify[23]=(cks - identify[22])/256;
   
     for (int j = 0; j<24; j++)
     {
       Serial1.write(identify[j]);
     }
     cks=0;
     
}
void sendCancel()
{
 for (int i = 0; i<7;i++)
 {
   cks = cks + cancelop[i];
 }
 
 cancelop[22] = cks&0xFF;
 cancelop[23] = (cks - cancelop[22])/256;
 
 for (int i = 0; i<24; i++)
 {
   Serial1.write(cancelop[i]);
 }
 cks=0;
}

void sendClearAll()
{
 for (int i = 0; i<7;i++)
 {
   cks = cks + clearalltemplate[i];
 }
 
 clearalltemplate[22] = cks&0xFF;
 clearalltemplate[23] = (cks - clearalltemplate[22])/256;
 
 for (int i = 0; i<24; i++)
   {
     Serial1.write(clearalltemplate[i]);
   }
   cks=0;
}

void sendClearOne()
{
 for (int i = 0; i<7;i++)
 {
   cks = cks + cleartemplate[i];
 }
 
 cleartemplate[22] = cks&0xFF;
 cleartemplate[23] = (cks - cleartemplate[22])/256;
 
 for (int i = 0; i<24; i++)
   {
     Serial1.write(cleartemplate[i]);
   }
   cks=0;
}

void sendGetEmptyID()
{  
 for (int i = 0; i<7;i++)
 {
   cks = cks + getemptytemp[i];
 }
 
 getemptytemp[22] = cks&0xFF;
 getemptytemp[23] = (cks - getemptytemp[22])/256;
 
 for (int i = 0; i<24; i++)
 {
   Serial1.write(getemptytemp[i]);
 }
 cks=0;
}

void sendStandbyMode()
{
 for (int i = 0; i<7;i++)
 {
   cks = cks + standby[i];
 }
 
 standby[22] = cks&0xFF;
 standby[23] = (cks - standby[22])/256;
 
 for (int i = 0; i<24; i++)
 {
   Serial1.write(standby[i]);
 }
 cks=0;
}

void serialEvent1(){
 for(int ctr=0;ctr<24;ctr++)
 {
   r_data[ctr]=Serial1.read();
   Serial.print(r_data[ctr],HEX);
 }
 Serial.println("");
 processFPS();
}

void processFPS(){
 switch(r_data[2])
 {
   case 2:      //identify
    if(r_data[8]==0xF4)
    {
      for (int k = 0;k<24;k++)
      {
        r_data[k] = Serial1.read();
      }
     
      if(r_data[8]==0x12||r_data[8]==0xFF)
      {
        Serial.print("Fingerprint doesn't exist on database.");
       }
      else
      {
        Serial.print("Identify successful. Template number is ");
        Serial.println(r_data[8],HEX);
       }
    }
   break;
   case 3:      //enroll
   readAgain:
   if (r_data[6]==0x00)
   {
     if (r_data[8]==0xF1)
        {
          Serial.println("First pass:");
                  for(int i = 0; i<24; i++)
                     {
                      r_data[i] = Serial1.read();
                      //Serial.print(r_data[i]);
                     }
                     goto readAgain;
                   
        }      
      else if (r_data[8]==0xF2)
        {
          Serial.println("Second pass:");
          for(int i = 0; i<24; i++)
          {
            r_data[i] = Serial1.read();
            //Serial.print(r_data[i]);
           }
           goto readAgain;        
        }
        else if (r_data[8]==0xF3)
        {
          Serial.println("Third pass:");
          for(int i = 0; i<24; i++)
          {
            r_data[i] = Serial1.read();
            //Serial.print(r_data[i]);
          }
          goto readAgain;
        }
        else if (r_data[8]==0xF4)
        {
            Serial.println("Sweep successful! Please lift finger");
            for(int i = 0; i<24; i++)
            {
              r_data[i] = Serial1.read();
              //Serial.print(r_data[i]);
            }
            goto readAgain;
        }
   }
   else if(r_data[6]==0x01)
   {
     if(r_data[8]==0x23)
     {
           Serial.println("Time out. No fingerprint detected!");
           for(int i = 0; i<24; i++)
           {
             r_data[i] = Serial1.read();
             //  Serial.print(r_data[i]);
           }
           goto readAgain;
      }
     else if(r_data[8]==0x21)
     {
           Serial.println("Bad quality taken. Please try again");
           for(int i = 0; i<24; i++)
           {
             r_data[i] = Serial1.read();
             //Serial.print(r_data[i]);
           }
           goto readAgain;
      }
     else if(r_data[8]==0x60)
     {
       Serial.println("Template number is invalid");
     }
     else if(r_data[8]==0x14)
     {
       Serial.println("Data exists for template number");
     }
     else if(r_data[8]==0x30)
     {
       Serial.println("Generalizing template number fail");
       sendEnroll();
     }
     else if(r_data[8]==0x19)
     {
       Serial.println("Fingerprint has been enrolled already!");
     }
   }
   break;    
   case 5:      //clear template
   break;
   case 6:      //clear all template
   if(r_data[22]=0x0A&&r_data[23]==0x01) Serial.println("Clear all template successful");
   break;
   case 7:      //get empty ID
readID:  
   for (int k = 0;k<24;k++)
   {
     r_data[k] = Serial1.read();
   }
 
   if (r_data[6]==0x00)
   {
     if(r_data[8]==0x00||r_data[8]==0xFF||r_data[8]>0x60)
     {
       goto readID;
     }
     else
     {
       temp_no=r_data[8];
       Serial.print(temp_no,HEX);
     }
   }
   break;
   case 17:    //enter standby mode
   break;
   case 30:    //cancel current operation
   break;
   case 50:    //test connection
   if(r_data[22]=0x54&&r_data[23]==0x01) Serial.println("Connection to FPS successful");
   break;
 }
}



GaryP

The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

pinkoymontano

I tried the codes above, but i am having a problem here:

cks = cks + enroll;
cks = cks + identify;

cks is declared as int
enroll, identify as byte

I believe it will really not work, but they have built this code, so i think they've able to run it.

Please help

clargin

You might need to review your data types and arrays. It is very much clear in the code that the variable test is an array. Therefore, you have to indicate which element are you trying to access in the test array by placing an index i.e. test[0], test[1],.. and so on.

pinkoymontano

Yes, but I am just wondering why they post it if there is an error? I hoping they've able to run it in some ways, somehow..

clargin

Sorry. I did not notice that that was a part of our code. That was just an initial draft of our code before so we were trying to get some help but then we were able to figure it out on our own so we did not update this forum already. Hope the code below helps. :)

clargin

Code: [Select]

void sendEnroll()
{
  enroll[6]=temp_no;
  for (int i = 0; i<7; i++)
  {
    cks = cks + enroll[i];
  }
  enroll[22]=cks&0xFF;
  enroll[23]=(cks - enroll[22])/256;

  for (int i = 0; i<24; i++)
  {
    Serial1.write(enroll[i]);
  }
  cks=0;
}

clargin

So above would already be the proper way of sending a command to the biometric fingerprint scanner. Hope this helps.  :)

JimboZA

Post your code in code tags.... didn't you see half of it's in italics? Somewhere in there there's a square bracket i square bracket from an array and that turns italics on. So the square bracket i square bracket has actually gone missing.

Select your code and hit the # icon above the  :smiley-sweat:
Arduino ethernet server here.... http://jimboza.gotdns.com:8085/

No PMs for help please


Go Up