Skip to content

Instantly share code, notes, and snippets.

@zaidpirwani
Created October 26, 2017 17:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zaidpirwani/68e6bba0cc258fb33a934b223e95c4bf to your computer and use it in GitHub Desktop.
Save zaidpirwani/68e6bba0cc258fb33a934b223e95c4bf to your computer and use it in GitHub Desktop.
WaveShare Finger print Sensor Module ARDUINO Code
// Code was tested on Arduino MEGA or Leonardo, I THINK, dont actually remember.
// no warranties or guarantees
// use this as it is.
#include <EEPROM.h>
int address = 0;
byte userID;
int addBtn = 5;
int chkBtn = 6;
int outLed = 13;
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
digitalWrite(addBtn, HIGH);
digitalWrite(chkBtn, HIGH);
pinMode(addBtn, INPUT);
pinMode(chkBtn, INPUT);
Serial.begin(9600);
Serial.println("Starting now..!");
mySerial.begin(19200);
userID = EEPROM.read(address);
// delay(1000);
// byte chkCmd[] = {0xF5, 0x05, 0x00, 0x00, 0x00, 0x00, 0x05, 0xF5};
// for(int i=0; i<8; i++){
// mySerial.write(chkCmd[i]);
// }
// EEPROM.write(address, 0);
// userID = EEPROM.read(address);
// Serial.println("ALL DELETED..!");
pinMode(outLed, OUTPUT);
digitalWrite(outLed, LOW);
}
void loop() {
if(digitalRead(addBtn) == LOW){
delay(500);
if(digitalRead(addBtn) == LOW){
while(mySerial.available()>0)mySerial.read();
Serial.print("Inside ADD..!\n USER ID=");
userID++;
Serial.println(userID);
addFingerPrint();
EEPROM.write(address, userID);
while(digitalRead(addBtn) == LOW){};
delay(500);
Serial.println("ADDED");
}
}
if(digitalRead(chkBtn) == LOW){
delay(500);
if(digitalRead(chkBtn) == LOW){
while(mySerial.available()>0)mySerial.read();
Serial.println("Inside CHECK..!");
int chk = chkFingerPrint();
if(chk==1){
digitalWrite(outLed, HIGH);
delay(2000);
digitalWrite(outLed, LOW);
}
while(digitalRead(chkBtn) == LOW){};
delay(500);
}
}
}
void addFingerPrint(void){
byte reply[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
byte addCmd[] = {0xF5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF5};
byte checkSum = 0;
delay(1000);
for(int i=0; i<8; i++){
addCmd[i] = 0x00;
}
addCmd[0] = 0xF5;
addCmd[7] = 0xF5;
addCmd[3] = userID;
addCmd[4] = 1;
addCmd[1] = 0x01;
checkSum = 0;
for(int i=1; i<6; i++){
checkSum = checkSum^addCmd[i];
}
addCmd[6] = checkSum;
for(int i=0; i<8; i++){
mySerial.write(addCmd[i]);
Serial.print(addCmd[i]);
Serial.print(' ');
}
Serial.println();
delay(1000);
for(int i=0; i<8; i++){
addCmd[i] = 0x00;
}
addCmd[0] = 0xF5;
addCmd[7] = 0xF5;
addCmd[3] = userID;
addCmd[4] = 1;
addCmd[1] = 0x02;
checkSum = 0;
for(int i=1; i<6; i++){
checkSum = checkSum^addCmd[i];
}
addCmd[6] = checkSum;
for(int i=0; i<8; i++){
mySerial.write(addCmd[i]);
Serial.print(addCmd[i]);
Serial.print(' ');
}
Serial.println();
delay(1000);
for(int i=0; i<8; i++){
addCmd[i] = 0x00;
}
addCmd[0] = 0xF5;
addCmd[7] = 0xF5;
addCmd[3] = userID;
addCmd[4] = 1;
addCmd[1] = 0x03;
checkSum = 0;
for(int i=1; i<6; i++){
checkSum = checkSum^addCmd[i];
}
addCmd[6] = checkSum;
for(int i=0; i<8; i++){
mySerial.write(addCmd[i]);
Serial.print(addCmd[i]);
Serial.print(' ');
}
Serial.println();
byte temp=0;
while(mySerial.available()>0)
temp =mySerial.read();
}
int chkFingerPrint(void){
byte chkCmd[] = {0xF5, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xF5};
byte reply[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
for(int i=0; i<8; i++){
mySerial.write(chkCmd[i]);
Serial.print(chkCmd[i]);
Serial.print(' ');
}
Serial.println();
delay(1000);
while(mySerial.available()<8){};
int i=0;
while(mySerial.available()>0){
reply[i] = mySerial.read();
Serial.print(reply[i]);
Serial.print(' ');
i++;
}
Serial.println();
if(reply[0]==0xF5 && reply[4]==0x01 && reply[7]==0xF5){
while(mySerial.available()>0)mySerial.read();
return(1);
}
else{
while(mySerial.available()>0)mySerial.read();
return(0);
}
return(0);
}
@zaidpirwani
Copy link
Author

dont remember why I did the EEPROM thing in this code.

@zaidpirwani
Copy link
Author

for completeness of information, referring to THIS module:
UART Fingerprint Reader, onboard processor STM32F205, commercial fingerprinting algorithm, optical sensor

https://www.waveshare.com/uart-fingerprint-reader.htm

@kokothetkoko
Copy link

how to use enroll and matching fingerprint in arduino ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment