FINGER PRINT BASED STUDENTS MONITORING SYSTEM IN REAL TIME ENVIRONMENT

Photo of author

By Jackson Taylor

Home » Electronics Topics » Arduino » FINGER PRINT BASED STUDENTS MONITORING SYSTEM IN REAL TIME ENVIRONMENT

As an Amazon Associate we earn from qualifying purchases.

CIRCUIT

Circuit diagram of Arduino fingerprint attendance system with R305 module, DS1307 RTC and LCD

PROGRAM

//module-r305
//it has 3 steps to read & check finger print
//step 1-collect finger image
//step 2-To generate character filefrom image
//step 3- search finger library for for previously stored finger print
//connect SDA--> A4, SCL-->A5
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <Wire.h>
const int DS1307 = 0x68; // Address of DS1307 see data sheets
byte second = 0;
byte minute = 0;
byte hour = 0;
byte weekday = 0;
byte monthday = 0;
byte month = 0;
byte year = 0;
SoftwareSerial mySerial(10, 11); // RX, TX
LiquidCrystal lcd(3, 4, 5, 6, 7, 8);//LCD RS-3,En-4,D4-5,D5- 6,D6-7,D7-8
char a,e;
int x=0,user1=0,user2=0,fingerswitch=9,progressswitch=12,f,p,sd,f2=0,f3=0;
void setup()
{
  lcdstart();
   Wire.begin();
  setTime();
   mySerial.begin(57600);
mySerial.println("hai");
  Serial.begin(57600);
  delay(500);
  switchinit();
readTime();
sd =monthday;//start date
f2=0;f3=0;
}
 void loop()
{
switchcheck();
 }
void switchcheck(void)
{
  do
  {
       readTime() ;
    f=digitalRead(fingerswitch);p= digitalRead(progressswitch);
  }   while(f&&p);
  readTime() ;
 if(sd != monthday)
 {f2=0;f3=0;mySerial.println(sd); sd =monthday ;}
  if(!f && ( (!f2) ||(!f3))){finger();delay(500);}
  else if(!f){lcd.clear(); displayattendence ();delay(500);}
  else if (!p){lcd.clear();progress();delay(500);}
}
void finger (void)
{
collectfingerimage();
generatecharacterfilefromimage();
   searchfingerlibrary(); 
if(x==1 && f2==0){f2=1; user1++; x=0;   lcd.clear();}
else if(x==2 && f3==0) {f3=1;user2++; x=0;   lcd.clear();}
else{ } 
displayattendence ();
}
byte bcdToDec(byte val) 
{
  int msbdec=val/16*10; //gets decimel msb of BCD value(4 bits)
  int lsbdec = val%16;//gets decimel lsb of BCD value(4 bits)
  int total=msbdec+lsbdec;
  return (total);
   
}
 void readTime() 
{
  Wire.beginTransmission(DS1307);
  Wire.write(byte(0));
  Wire.endTransmission();
  Wire.requestFrom(DS1307, 7);
  second = bcdToDec(Wire.read());
  minute = bcdToDec(Wire.read());
  hour = bcdToDec(Wire.read());
  weekday = bcdToDec(Wire.read());
  monthday = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year = bcdToDec(Wire.read());
  lcd.setCursor(0, 3);
   lcd.print(monthday);
   lcd.write('-'); 
   lcd.print(month );
   lcd.write('-'); 
   lcd.print(year);
   lcd.write('-');
   lcd.write('-');
   lcd.print(hour);
  lcd.write(':');
  lcd.print(minute);
   lcd.write(':');
  lcd.print(second);
}
 void setTime() {
   // The following codes transmits the data to the RTC
  Wire.beginTransmission(DS1307);
  Wire.write(byte(0)); //starts sending data writing 
  Wire.write(0x12);//second
  Wire.write(0x10); //minute
  Wire.write(0x15); //hour
  Wire.write(0x5); //weekday
  Wire.write(0x16);//monthday
  Wire.write(0x4);//month
  Wire.write(0x15);//year
  Wire.write(byte(0));
  Wire.endTransmission();
  // Ends transmission of data
    Serial.println("OK");
}
 void displayattendence (void)
{
lcd.setCursor(0, 0);lcd.print("student1-"); lcd.print(user1);
lcd.setCursor(0, 1);lcd.print("student2-"); lcd.print(user2);  
}
 void progress(void)
{
  lcd.clear();
lcd.setCursor(0, 0);lcd.print("student1-");lcd.print("marks= 78%");
lcd.setCursor(0, 1);lcd.print("student2-");lcd.print("marks= 88%");
}
 void switchinit(void)
{
  pinMode(fingerswitch,INPUT_PULLUP); 
  pinMode(progressswitch,INPUT_PULLUP); 
}
 void searchfingerlibrary(void)
{
Serial.write(0XEF);//header --1st byte of header (total 2 bytes)
Serial.write(0X01);//header --2nd byte of header (total 2 bytes)
Serial.write(0XFF);//address--1st byte of address (total 4 bytes)
Serial.write(0XFF);//address--2
Serial.write(0XFF);//address--3
Serial.write(0XFF);//address--4
Serial.write(0X01);//Package identifier--01=Commands ,07=Acknowledgement (total 1 byte)
Serial.write(0);// --1st byte of Package length   (total 2 byte)
Serial.write(8);// --2nd byte of Package length   (total 2 byte)
Serial.write(4);////instruction code to search finger library (total 1 byte)
Serial.write(1);//buffer id number where the image is stored (total 1 byte)
Serial.write(0);//Start Page of searching(searching start address)(total 2 bytes)
Serial.write(0);//(total 2 bytes)
Serial.write(0);//searching numbers(total 2 bytes)
Serial.write(10);//searching numbers(total 2 bytes)
Serial.write(0);//check sum(total 2 bytes)
Serial.write(24);//check sum(total 2 bytes)
 while(!(Serial.available()>0)); 
while(a != 7){   //wait until receiving Acknowledgement ..ie 0x7
a=Serial.read(); 
  mySerial.write(a);
}
 do {   //wait until receiving package length ..ie 0x7
a=Serial.read(); 
  mySerial.write(a);
}while(a != 7);   
 if(Serial.available()>0){ //reads the confirmation code
a=Serial.read(); 
  mySerial.write(a);
}
  if(a==0) mySerial.println("ok     ");// Confirmation code=00H: found the matching finer; 
  else if(a==1) mySerial.println("error 1  ");//Confirmation code=01H: error when receiving package; 
  else if(a==9) mySerial.println("no match ");//Confirmation code=09H: No matching in the library (both the PageID and   
                               // matching score are 0); 
else { mySerial.println("error 0   ");}
  if(a==0)
  {
if(Serial.available()>0){e=Serial.read();} // avoides   the 1st byte of matching templates location
 if(Serial.available()>0){ // reads   the 2nd byte of matching templates location
a=Serial.read(); }
mySerial.println("one");x=1;}
  else if(a==5){ mySerial.println("two");x=2;}
  else mySerial.println("error");   
mySerial.write(a);
   
}
if(Serial.available()>0){a=Serial.read(); mySerial.write(a); }// avoides MatchScore   (total 2 bytes)
if(Serial.available()>0){a=Serial.read(); mySerial.write(a); }// avoides MatchScore   (total 2 bytes)
if(Serial.available()>0){a=Serial.read(); mySerial.write(a); }//avoides checksum
if(Serial.available()>0){a=Serial.read(); mySerial.write(a); }//avoides checksum
delay(100);
}
 void generatecharacterfilefromimage(void)
{
  do{   
  // delay(500);
   
   Serial.write(0XEF);//header --1st byte of header (total 2 bytes)
   Serial.write(0X01);//header --2nd byte of header (total 2 bytes)
   Serial.write(0XFF);//address--1st byte of address (total 4 bytes)
   Serial.write(0XFF);//address--2
   Serial.write(0XFF);//address--3
   Serial.write(0XFF);//address--4
   Serial.write(0X01);//Package identifier--01=Commands ,07=Acknowledgement (total 1 byte)
   Serial.write(0X00);// --1st byte of Package length   (total 2 byte)
   Serial.write(0X04);//Package length
   Serial.write(0X02);//instruction code to generate character file from image
   Serial.write(0X01);//BufferID 1   (total 1 byte)(to generate character file fromthe original finger image in ImageBuffer and   
               //store the file in CharBuffer1 or CharBuffer2.
               //BufferID of CharBuffer1 and CharBuffer2 are 1h and 2h respectively
   Serial.write(0X00);//check sum(total 2 bytes)
   Serial.write(0X08);//check sum(total 2 bytes)
while(!(Serial.available()>0));//waiting for reply
while(a != 3){ //wait until receiving package length ..ie 0x3
a=Serial.read(); 
  mySerial.write(a);
};
if(Serial.available()>0){ //reads the confirmation code
a=Serial.read(); 
  mySerial.write(a);
}
if(a==0) mySerial.println("ok     ");//Confirmation code=00H: generate character file complete; 
  else if(a==1) mySerial.println("error 1  ");//Confirmation code=01H: error when receiving package; 
  else if(a==6) mySerial.println("er 2");//Confirmation code=06H: fail to generate character file due to the over-disorderly  
               //fingerprint image;   
else if(a==7) mySerial.println("error 3  ");//Confirmation code=07H: fail to generate character file due to lackness of character  
               //point or over-smallness of fingerprint image; 
 else if(a==0x15) mySerial.println("error 4  ");//Confirmation code=15H: fail to generate the image
               // for the lackness of valid primary image; 
else { mySerial.println("error 5 ");}
e=Serial.read(); //avoides checksum
e=Serial.read(); //avoides checksum
  }while(a!=0); //waits until the generation character file is completed;   
delay(1000);
}
 void collectfingerimage(void)   //page number 12 in manual of r305
{
   do{ 
   
   Serial.write(0XEF);//header --1st byte of header (total 2 bytes)
   Serial.write(0X01);//header --2nd byte of header (total 2 bytes)
   Serial.write(0XFF);//address--1st byte of address (total 4 bytes)
   Serial.write(0XFF);//address--2
   Serial.write(0XFF);//address--3
   Serial.write(0XFF);//address--4
   Serial.write(0X01);//Package identifier--01=Commands ,07=Acknowledgement (total 1 byte)
   Serial.write(0X00);// --1st byte of Package length   (total 2 byte)
   Serial.write(0X03);//Package length
   Serial.write(0X01);//instruction code to collect image
   Serial.write(0X00);//check sum(total 2 bytes)
   Serial.write(0X05);//check sum(total 2 bytes)
 while(!(Serial.available()>0));//waiting for reply
 while(a != 3){ //wait until receiving package length ..ie 0x3
   a=Serial.read(); 
   mySerial.write(a);
 }
 while(Serial.available()>0){
   // process collected image data if needed
 }
}
 void lcdstart(void)
{
  // initialization code for LCD if required
}

Things to Know Before You Build This Project

The sketch above works as a demonstration, but a few details in it will affect how your build behaves. Check these before you upload it.

  • Enroll fingerprints first. The code only searches the module’s stored library. It does not enroll new fingers. Store each student’s fingerprint in the R305 module beforehand, using a separate enrollment sketch or the manufacturer’s tool, so the search step has something to match.
  • Set the clock once, then remove the call. The setTime() function writes a fixed date and time to the DS1307 every time the board starts. After the first upload, edit the values to the current time, upload once, then remove the call. Otherwise the clock resets on every power-up.
  • Attendance is kept in RAM only. The counters user1 and user2 are ordinary variables, so they reset when power is lost. To keep records, write them to EEPROM or an SD card.
  • Only two students are handled. The match result is mapped to two fixed users, and the marks shown on the progress screen are typed into the code. To support a class, read the matched template ID from the module’s reply and use it to index an array of students.
  • Serial port sharing. The fingerprint module uses the hardware serial pins, and the SoftwareSerial port on pins 10 and 11 is used for debug output. Disconnect the module’s wires from pins 0 and 1 while uploading, then reconnect them.
  • Match the baud rate. The sketch opens the module’s port at 57600. If your module has been configured differently, change this value.
See also
Analysis of Statistical Texture Features for Automatic Lung Cancer Detection in PET/CT Images

Each student can mark attendance only once per day. The code uses the date from the RTC to clear the flags when the day changes. If attendance is not clearing, check that the RTC is running and that its battery is fitted.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works