A basic demo of fingerprint based voting machine on Arduino with KeyPad and LCD.
Last active
April 4, 2017 20:47
-
-
Save parthpower/90678da6633e249c65bde27e3d7ba41e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*The circuit: | |
* LCD RS pin to digital pin 13 | |
* LCD Enable pin to digital pin 12 | |
* LCD D4 pin to digital pin 5 | |
* LCD D5 pin to digital pin 4 | |
* LCD D6 pin to digital pin 3 | |
* LCD D7 pin to digital pin 2 | |
* LCD R/W pin to ground | |
* LCD VSS pin to ground | |
* LCD VCC pin to 5V | |
*KeyPad: | |
*Rows | |
* 1:A0 | |
* 2:A1 | |
* 3:A2 | |
*Cols: | |
* 1:A3 | |
* 2:A4 | |
* 3:A5 | |
* 4:6 | |
*r305: | |
*tx:10 | |
*rx:11 | |
*/ | |
#include <SoftwareSerial.h> | |
#include <Keypad.h> | |
#include <LiquidCrystal.h> | |
SoftwareSerial r305serial(10,11); | |
char recBuffer[256]; | |
boolean res =false; | |
unsigned long int votes[3]={0,0,0}; | |
unsigned char vfyPwd_c[16] = { 0xef, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,0x07, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b }; | |
unsigned char genImg_c[12] = { 0xEF, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00,0x03, 0x01, 0x00, 0x05 }; | |
unsigned char img2tz_c[13] = { 239, 1, 255, 255, 255, 255, 1, 0, 4, 2, 1, 0, 8 }; | |
unsigned char img2tz2_c[13] = { 239, 1, 255, 255, 255, 255, 1, 0, 4, 2, 2, 0, 9 }; | |
unsigned char regModel_c[12] = { 239, 1, 255, 255, 255, 255, 1, 0, 3, 5, 0, 9 }; | |
unsigned char searchT_c[17] = { 239, 1, 255, 255, 255, 255, 1, 0, 8, 4, 1, 0, 0, 0,200, 0, 200 + 1 + 8 + 4 + 1 }; | |
LiquidCrystal lcd(13,12,5,4,3,2); | |
///////////////////////////// | |
//////////////////////////// | |
const char password[] = {'1','2','3'}; | |
const byte rows =3; | |
const byte cols =4; | |
char keys[rows][cols]={ | |
{'7','8','9','/'}, | |
{'4','5','6','*'}, | |
{'1','2','3','-'} | |
}; | |
byte rowPins[rows] = {14,15,16}; | |
byte colPins[cols] = {17,18,19,6}; | |
Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,rows,cols); | |
boolean setVote(){ | |
lcd.clear(); | |
lcd.print("Candidate:123?"); | |
char a = keypad.waitForKey(); | |
switch(a){ | |
case '1': | |
case '2': | |
case '3': | |
votes[a-'0'] += 1; | |
lcd.print("VoteSucess"); | |
return true; | |
break; | |
default: | |
lcd.print("InvalidID"); | |
delay(1000); | |
return false; | |
break; | |
} | |
} | |
boolean showVote(){ | |
lcd.clear(); | |
lcd.print("Candidate:123?"); | |
char a = keypad.waitForKey(); | |
switch(a){ | |
case '1': | |
case '2': | |
case '3': | |
lcd.print(votes[a-'0']); | |
delay(5000); | |
return true; | |
break; | |
default: | |
lcd.print("InvalidID"); | |
delay(1000); | |
return false; | |
break; | |
} | |
} | |
unsigned char vfyPwd(){ | |
Serial.println("vfyPwd start"); | |
r305serial.write(vfyPwd_c,16); | |
delay(100); | |
byte b= r305serial.readBytes(recBuffer,12); | |
if(b != 12) | |
Serial.println(b); | |
return recBuffer[9]; | |
} | |
unsigned char genImg(){ | |
Serial.println("genImg start"); | |
r305serial.write(genImg_c,12); | |
r305serial.readBytes(recBuffer,12); | |
return recBuffer[9]; | |
} | |
unsigned char img2tz(){ | |
Serial.println("img2tz start"); | |
r305serial.write(img2tz_c,13); | |
r305serial.readBytes(recBuffer,12); | |
return recBuffer[9]; | |
} | |
unsigned char img2tz2(){ | |
Serial.println("img2tz2 start"); | |
r305serial.write(img2tz2_c,13); | |
r305serial.readBytes(recBuffer,12); | |
return recBuffer[9]; | |
} | |
unsigned char regModel(){ | |
Serial.println("regModel start"); | |
r305serial.write(regModel_c,12); | |
r305serial.readBytes(recBuffer,12); | |
return recBuffer[9]; | |
} | |
unsigned char storeT(byte ID){ | |
if(ID>199){ | |
return 1; | |
}else{ | |
byte storeT_c[] = { 239, 1, 255, 255, 255, 255, 1, 0, 6, 6, 1,0, ID, 0, 14 + ID }; | |
Serial.println("storeT start"); | |
r305serial.write(storeT_c,13); | |
r305serial.readBytes(recBuffer,12); | |
return recBuffer[9]; | |
} | |
} | |
char searchT(){ | |
Serial.println("searchT start"); | |
r305serial.write(searchT_c,17); | |
r305serial.readBytes(recBuffer,16); | |
return recBuffer[9]; | |
} | |
boolean tmpProc(){ | |
Serial.println("RegModelStart"); | |
lcd.print("Put Finger"); | |
while(genImg() != 0x00){ | |
delay(1000); | |
} | |
if(img2tz()!=0x00){ | |
Serial.println("Can't generate"); | |
lcd.print("Chr1Fail"); | |
delay(1000); | |
return false; | |
} | |
delay(2000); | |
//////////////////////////////////////////// | |
lcd.clear(); | |
lcd.print("Put Again"); | |
while(genImg() != 0x00){ | |
delay(1000); | |
} | |
///////////// | |
if(img2tz2()!=0x00){ | |
Serial.println("Can't generate"); | |
lcd.print("Chr2Fail"); | |
delay(1000); | |
return false; | |
} | |
//////////////////////////////////////////// | |
if(regModel() != 0x00){ | |
Serial.println("regModelFailed"); | |
lcd.print("RegModelFailed"); | |
delay(1000); | |
return false; | |
} | |
Serial.println("RegModelSucess"); | |
lcd.print("RegModelSucess"); | |
delay(1000); | |
return true; | |
} | |
boolean storeProc(byte ID){ | |
lcd.clear(); | |
if(!tmpProc()){ | |
Serial.println("Can't Generate Tmp"); | |
lcd.print("TemplateFail"); | |
delay(1000); | |
return false; | |
} | |
if(storeT(ID) != 0x00){ | |
Serial.println("StorageFAiled"); | |
return false; | |
} | |
Serial.println("Store Sucess"); | |
return true; | |
} | |
boolean searchProc(){ | |
lcd.clear(); | |
if(!tmpProc()){ | |
Serial.println("Can't Generate Tmp"); | |
lcd.print("TemplateFail"); | |
delay(1000); | |
return false; | |
} | |
char s= searchT(); | |
if(s != 0x00){ | |
Serial.println("SearchFailed"); | |
lcd.print("SearchFail"); | |
delay(1000); | |
if(s == 0x09){ | |
Serial.println("NoMatch"); | |
lcd.print("NoMatch"); | |
} | |
return false; | |
} | |
Serial.println("SearchSucess"); | |
lcd.print("MatchFound!"); | |
delay(1000); | |
return true; | |
} | |
boolean keyPasswordCheck(){ | |
boolean ret=true; | |
int i=0; | |
char a; | |
for(i=0;i<3;i++){ | |
a = keypad.waitForKey(); | |
lcd.print('*'); | |
if(a != password[i]){ | |
ret=false; | |
} | |
} | |
return ret; | |
} | |
void setup(){ | |
Serial.begin(57600); | |
while(!Serial); | |
//R305///////////// | |
r305serial.begin(57600); | |
r305serial.setTimeout(3000); | |
Serial.println("GoGoGooo"); | |
if(vfyPwd()==0){ | |
Serial.println("VerifiedPWD"); | |
Serial.write((uint8_t*)recBuffer,12); | |
}else{ | |
Serial.println("NO PWD VERIFIED"); | |
} | |
////////////////////////////////// | |
//LCD///////////////////////////// | |
////////////////////////////////// | |
lcd.begin(16,2); | |
lcd.print("Working"); | |
///////////////////////////////// | |
//////////////////////////////// | |
} | |
void loop(){ | |
while(true){ | |
lcd.print("PasswordPlz:"); | |
lcd.setCursor(0,1); | |
lcd.blink(); | |
if(keyPasswordCheck()){ | |
lcd.print("CorrectPwd"); | |
Serial.println("CorrectPwd"); | |
break; | |
}else{ | |
lcd.print("IncorrectPwd"); | |
delay(5000); | |
} | |
} | |
delay(1000); | |
boolean Opflag=true; | |
while(Opflag){ | |
lcd.print("SelectOp:123456"); | |
char selection = keypad.waitForKey(); | |
switch(selection){ | |
case '1': | |
case '2': | |
case '3': | |
case '4': | |
res = storeProc(selection-'0'); | |
break; | |
case '5': | |
res=searchProc(); | |
if(res){ | |
setVote(); | |
} | |
break; | |
case '6': | |
showVote(); | |
break; | |
default: | |
lcd.print("WrongOp"); | |
lcd.clear(); | |
} | |
delay(1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment