CIRCUIT
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);
//return ((val/16*10) + (val%16));
}
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);
//lcd.write(0xd);
/* Serial.print(monthday);
Serial.write(‘-‘);
Serial.print(month );
Serial.write(‘-‘);
Serial.print(year);
Serial.write(‘-‘);
Serial.write(‘-‘);
Serial.print(hour);
Serial.write(‘:’);
Serial.print(minute);
Serial.write(‘:’);
Serial.print(second);
Serial.write(0xd);
*/
}
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)
//delay(500);
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: finger collection successs;
else if(a==1) mySerial.println(“error 4 “); //Confirmation code=01H: error when receiving packag
else if(a==2) mySerial.println(“no finger”);//Confirmation code=02H: can’t detect finger;
else if(a==3) mySerial.println(“error 2 “);//Confirmation code=03H: fail to collect finger;
else { mySerial.println(“error 0 “);}
e=Serial.read(); //avoides checksum
e=Serial.read();//avoides checksum
}while(a!=0);//waits until to get any finger
}
void lcdstart(void)
{
lcd.begin(20, 4);// set up the LCD’s number of columns and rows:
lcd.setCursor(1, 1);
//lcd.print(“WELCOME”);// Print a message to the LCD.
//delay(500);
// lcd.clear();
}