2

When I separate fingerprint code and LCD code it works fine. sensor read 6 templates which I already stored 6 fingers ID. When I combine the code it read 0 templates.

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include<LiquidCrystal.h>

int Contrast=100;
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

// pin #7 is IN from sensor (GREEN wire)
// pin #6 is OUT from arduino  (WHITE wire)
SoftwareSerial mySerial(6,7);

uint8_t id;
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

#define S1 14 //Button candidate A
#define S2 15 // Button candidate B
#define S3 16 // Button candidate c
#define S4 17 // Button candidate D
#define S5 18 // Button Result
#define S6 2 // Button Add unregistered voter
#define S7 4 // Button to cast vote
int can1=0;
int can2=0;
int can3=0;
int can4=0;

void setup()
{
  pinMode(S1, INPUT);
  pinMode(S2,INPUT);
  pinMode(S3,INPUT);
  pinMode(S4,INPUT);
  pinMode(S5,INPUT);
  pinMode(S6,INPUT);
  pinMode(S7,INPUT);

  digitalWrite(S1, HIGH);
  digitalWrite(S2, HIGH);
  digitalWrite(S3, HIGH);
  digitalWrite(S4, HIGH);
  digitalWrite(S5, HIGH);
  digitalWrite(S6, HIGH);
  digitalWrite(S7, HIGH);

  analogWrite(6,Contrast);
  lcd.begin(16, 2);
  lcd.print("  Polling Day  ");
  lcd.setCursor(0,1);
  lcd.print("      UPM      ");
  delay(4000);
  
  Serial.begin(57600);
    lcd.clear();
    lcd.print("Finding Module");
    lcd.setCursor(0,1);
    delay(1000);
    if (finger.verifyPassword()) 
    {
      //Serial.println("Found fingerprint sensor!");
      lcd.clear();
      lcd.print("Found Module ");
      delay(1000);
    } 
    else 
    {
    //Serial.println("Did not find fingerprint sensor :(");
    lcd.clear();
    lcd.print("module not Found");
    lcd.setCursor(0,1);
    lcd.print("Check Connections");
    while (1);
    }

    finger.getTemplateCount();
    lcd.clear();
    lcd.print("contains");
    lcd.setCursor(0,1);
    lcd.print(finger.templateCount);
    delay (4000);
}

uint8_t readnumber(void) {
  uint8_t num = 0;
  
  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}


void loop(){
  lcd.clear();
  lcd.setCursor(1,0);
  lcd.print("Place Your");
  lcd.setCursor(0,1);
  lcd.print("Finger");
  delay(4000);
  getFingerprintIDez();
  delay(50);
  
    if(digitalRead(S5)==0) // To view the result for admin only
    {
      int total=can1+can2+can3+can4;
    if(total)
    {
      if((can1 > can2 && can1 > can3 && can1 > can4))
    {
      lcd.clear();
      lcd.print("Can A is Winner");
      delay(3000);
      lcd.clear();
    }
    else if((can2 > can1 && can2 > can3 && can2 > can4))
    {
      lcd.clear();
      lcd.print("Can B is Winner");
      delay(3000);
      lcd.clear();
    }
    else if((can3 > can1 && can3 > can2 && can3 > can4))
    {
      lcd.clear();
      lcd.print("Can C is Winner");
      delay(3000);
      lcd.clear();
    }
    else if(can4 > can1 && can4 > can2 && can4 > can3)
    {
        lcd.setCursor(0,0);
        lcd.clear();
        lcd.print("Can D is Winner");
        delay(3000);
        lcd.clear();
    }
 
    else if(can4 > can1 && can4 > can2 && can4 > can3)
    {
        lcd.setCursor(0,0);
        lcd.clear();
        lcd.print("Can D is Winner");
        delay(3000);
        lcd.clear();
    }
 
    else
    {
        lcd.clear();
        lcd.print(" Tie Up Or ");
        lcd.setCursor(0,1);
        lcd.print(" No Result ");
        delay(3000);
        lcd.clear();
    }
 
    }
    else
    {
        lcd.clear();
        lcd.print("No Voting....");
        delay(3000);
        lcd.clear();
    }
        can1=0;can2=0;can3=0;can4=0,total=0;
        lcd.clear();
    }

    if(digitalRead(S7)==0){ //To cast avote for user
        voterpage();
    }

    if(digitalRead(S6)==0){
      Serial.println("Ready to enroll a fingerprint!");
      Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
      lcd.clear();
      lcd.print("ENTER ID:");
      delay(2000);
      id = readnumber();
      if (id == 0) {// ID #0 not allowed, try again!
      return;
      }
      Serial.print("Enrolling ID #");
      lcd.print(id);
  
      while (!  getFingerprintEnroll() );
      }
  }

    void voterpage(){
      lcd.clear();
      lcd.setCursor(1,0);
      lcd.print("A");
      lcd.setCursor(5,0);
      lcd.print("B");
      lcd.setCursor(9,0);
      lcd.print("C");
      lcd.setCursor(13,0);
      lcd.print("D");

      if(digitalRead(S1)==0){
      can1++;
      votereceived();
      }
        while(digitalRead(S1)==0);
      if(digitalRead(S2)==0){
      can2++;
      votereceived();
      }
        while(digitalRead(S2)==0);
      if(digitalRead(S3)==0){
      can3++;
      votereceived();
      }
        while(digitalRead(S3)==0);
      if(digitalRead(S4)==0){
      can4++;
      votereceived();
      }
        while(digitalRead(S4)==0);
}

void votereceived(){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Vote Received");
      lcd.setCursor(2,1);
      lcd.print("Thank You :)");
      delay(2000);  
}

uint8_t getFingerprintEnroll() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  lcd.clear(); 
  lcd.print("ID "); 
  lcd.print(id);
  delay(2000);
  p = -1;
  lcd.clear(); lcd.print("Place same finger again"); delay(2000);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
  

Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
}
  
uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
    // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence); 
    lcd.clear();
    lcd.setCursor(3,0);
    lcd.print("ID");
    lcd.setCursor(1,1);
    lcd.print(finger.fingerID);
    delay(4000); 
    return finger.fingerID;
    if(finger.fingerID==26 ;finger.confidence>100){
      lcd.clear();
      lcd.setCursor(3,0);
      lcd.print("1");
      lcd.setCursor(1,1);
      lcd.print("Result");
      lcd.setCursor(11,0);
      lcd.print("2");
      lcd.setCursor(8,1);
      lcd.print("Register");
      delay(4000); 
  }

}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;
  
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  return finger.fingerID; 
}

enter image description here

enter image description here

11
  • 2
    dupe your sketch, start removing code, re-test until there's nothing left to take away (then post that) or the problem goes away (in which case you don't need us anymore). – dandavis Nov 17 '20 at 3:47
  • 1
    Can you please share the schematic also and also which fingerprint sensor you are using. – Maaz Sk Nov 17 '20 at 6:54
  • 2
    What part "doesn't work"? That is an incredibly vague description. What shows on the LCD display? What appears in the serial monitor? – Nick Gammon Nov 17 '20 at 6:56
  • 1
    @NickGammon Hi I already add the pic of lcd dislpay and serial monitor. Serial reads 6 templates but if I add lcd code it showed 0 templates. Hope you can help thank you :) – SASHA SYAZANA Nov 17 '20 at 9:13
  • 2
    Need to check will get back soon – Maaz Sk Nov 17 '20 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.