Help needed to merge two void loops

#include <Adafruit_Fingerprint.h>
#include <SPI.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include<LiquidCrystal_I2C.h>
SoftwareSerial SIM800(10,11);

#define gps Serial3
#define mySerial Serial1
#define I2C_ADDR 0x27         
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); //LCD declaring

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
static const uint32_t GPSBaud = 9600;

int relayPin = 8;

//String str="";
char str[70];
String gpsString="";

char *test="$GPGGA";

String latitude="No Range      ";
String longitude="No Range     ";

int temp=0,i;
boolean gps_status=0;

void setup() 
{
  
 pinMode(relayPin, OUTPUT);
 digitalWrite(relayPin, HIGH);
 SIM800.begin(9600);
 Serial.begin(9600);
 while (!SIM800); 
 delay(100);

 lcd.begin(16,2);
 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
 lcd.setBacklight(HIGH);
 lcd.setCursor(0, 0);
 lcd.print("Smart Safe Sahan");
 lcd.setCursor(0, 1);
 lcd.print("Chandimal");
 delay(5000);
 lcd.clear();


 // set the data rate for the sensor serial port
  Serial1.begin(9600);
  finger.begin(57600);              //Sensor baude rate
  lcd.begin (16,2);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  finger.getTemplateCount();        //Counts the number of templates stored in the sensor flash memory
  lcd.setCursor(0,0);
  lcd.print("Scan ready");
  lcd.clear();  
  
 Serial3.begin(9600);
  gps.begin(GPSBaud);
  lcd.print("Ammo Tracking");
  lcd.setCursor(0,1);
  lcd.print("    System      ");
  delay(2000);

  
  SIM800_init();
  lcd.clear();
  SIM800.println("AT+CNMI=2,2,0,0,0");

  lcd.print("GPS Initializing");
  lcd.setCursor(0,1);
  lcd.print("  No GPS Range  ");
  get_gps();
  delay(2000);
  lcd.clear();
  lcd.print("GPS Range Found");
  lcd.setCursor(0,1);
  lcd.print("GPS is Ready");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  temp=0;
}

void loop()
{ 
  serialEvent();
  if(temp)
  {
    get_gps();
    tracking();
  }
}

void serialEvent()
{
  while(SIM800.available())
  {
    if (SIM800.find("RING"))
    {
      temp=1;
      break;
      lcd.print("SMS received");
    }
    else
    temp=0;
  }
}

void gpsEvent()
{
  gpsString="";
  while(1)
  {
   while (gps.available()>0)            //checking serial data from GPS
   {
    char inChar = (char)gps.read();
     gpsString+= inChar;                    //store data from GPS into gpsString
     i++;
     if (i < 7)                      
     {
      if(gpsString[i-1] != test[i-1])         //checking for $GPGGA sentence
      {
        i=0;
        gpsString="";
      }
     }
    if(inChar=='\r')
    {
     if(i>65)
     {
       gps_status=1;
       break;
     }
     else
     {
       i=0;
     }
    }
  }
   if(gps_status)
    break;
  }
}

void SIM800_init()
{
  lcd.clear();
  lcd.print("Finding Module..");
  boolean at_flag=1;
  while(at_flag)
  {
    SIM800.println("AT");
    while(SIM800.available()>0)
    {
      if(SIM800.find("OK"))
      at_flag=0;
    }
    
    delay(1000);
  }

  lcd.clear();
  lcd.print("Module Connected..");
  delay(1000);
  lcd.clear();
  lcd.print("Disabling ECHO");
  boolean echo_flag=1;
  while(echo_flag)
  {
    SIM800.println("ATE1");
    SIM800.println("AT+CGATT=1");
    SIM800.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\" ");
    SIM800.println("AT+SAPBR=3,1,\"APN\",\"RCMNET\" ");
    SIM800.println("AT+SAPBR=1,1");
    
    while(SIM800.available()>0)
    {
      if(SIM800.find("OK"))
      echo_flag=0;
    }
    delay(1000);
  }

  lcd.clear();
  lcd.print("Echo OFF");
  delay(1000);
  lcd.clear();
  lcd.print("Finding Network..");
  boolean net_flag=1;
  while(net_flag)
  { SIM800.println("ATE0");
    SIM800.println("AT+CPIN?");

    while(SIM800.available()>0)
    {
      if(SIM800.find("+CPIN: READY"))
      net_flag=0;
    }
    delay(4000);
  }
  lcd.clear();
  lcd.print("Network Found..");
  delay(1000);
  lcd.clear();
}

void get_gps()
{
   gps_status=0;
   int x=0;
   while(gps_status==0)
   {
    gpsEvent();
    int str_lenth=i;
    latitude="";
    longitude="";
    int comma=0;
    while(x<str_lenth)
    {
      if(gpsString[x]==',')
      comma++;
      if(comma==2)        //extract latitude from string
      latitude+=gpsString[x+1];     
      else if(comma==4)        //extract longitude from string
      longitude+=gpsString[x+1];
      x++;
    }
    int l1=latitude.length();
    latitude[l1-1]=' ';
    l1=longitude.length();
    longitude[l1-1]=' ';
    lcd.clear();
    lcd.print("Lat:");
    lcd.print(latitude);
    lcd.setCursor(0,1);
    lcd.print("Long:");
    lcd.print(longitude);
    i=0;x=0;
    str_lenth=0;
    delay(2000);
   }
}

void init_sms()
{
  SIM800.println("AT+CMGF=1");
  delay(1000);
  SIM800.println("AT+CMGS=\"+94779994223\"");   // use your 10 digit cell no. here
  delay(1000);
  
}

void send_data(String message)
{
  SIM800.println(message);
  delay(200);
}

void send_sms()
{
  SIM800.write(26);
}

void lcd_status()
{
  lcd.clear();
  lcd.print("Message Sent");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  return;
}

void tracking()
{
    init_sms();
    send_data("Locker Tracking Alert:");
    send_data("Your Locker's Current Location:");
    SIM800.print("Latitude:");
    send_data(latitude);
    SIM800.print("Longitude:");
    send_data(longitude);
    send_data("Please take some action soon..\nThankyou");
    send_sms();
    delay(2000);
    lcd_status();
}

WIth the below one, this is for the fingerprint reader, should be placed inside the void loop(). :pleading_face:

void fn() 
{
 getFingerprintIDez();            
}

int getFingerprintIDez() {
 uint8_t p = finger.getImage();
 if (p != FINGERPRINT_OK)  {
   lcd.setCursor(0, 0);
   lcd.print(" Scanner ready");
   
   return -1;
 }

 p = finger.image2Tz();
 if (p != FINGERPRINT_OK)  {
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("  Messy Image");
   lcd.setCursor(0, 1);
   lcd.print("  Try Again");
   delay(3000);
   lcd.clear();
   return -1;
 }

 p = finger.fingerFastSearch();
 if (p != FINGERPRINT_OK)  {
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("Not a valid Finger");
   delay(3000);
   lcd.clear();
   return -1;
 }

 // found a match!
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("  Door Unlocked");
 lcd.setCursor(0, 1);
 lcd.print("    Welcome");
 digitalWrite(relayPin, LOW);
 delay(3000);
 digitalWrite(relayPin, HIGH);
 lcd.clear();
 return finger.fingerID;
  
  }

Can anyone help? :smiley:

What's the specification of the merged code?

Please remember to use tags when posting code

1 Like

The 2nd part is just another function, fn().
Add it to the bottom of the file of the first part, and call it as needed.

Then add the parts after the function definition to the bottom of your current loop(), and debug from there.

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

1 Like

This one is for a fingerprint safe locker with GPS, the first part of the code works fine.

But the void fn() part, (for the fingerprint) is not working.

When void fn() is placed just below the void loop() it works fine, but then the gsm stops working..

It should look something like this when combined.
Without your libraries I can't compile it, and without your hardware I can't run it.

#include <Adafruit_Fingerprint.h>
#include <SPI.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include<LiquidCrystal_I2C.h>
SoftwareSerial SIM800(10, 11);

#define gps Serial3
#define mySerial Serial1
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); //LCD declaring

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
static const uint32_t GPSBaud = 9600;

int relayPin = 8;

//String str="";
char str[70];
String gpsString = "";

char *test = "$GPGGA";

String latitude = "No Range      ";
String longitude = "No Range     ";

int temp = 0, i;
boolean gps_status = 0;

void setup()
{

  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
  SIM800.begin(9600);
  Serial.begin(9600);
  while (!SIM800);
  delay(100);

  lcd.begin(16, 2);
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.setCursor(0, 0);
  lcd.print("Smart Safe Sahan");
  lcd.setCursor(0, 1);
  lcd.print("Chandimal");
  delay(5000);
  lcd.clear();


  // set the data rate for the sensor serial port
  Serial1.begin(9600);
  finger.begin(57600);              //Sensor baude rate
  lcd.begin (16, 2);
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  finger.getTemplateCount();        //Counts the number of templates stored in the sensor flash memory
  lcd.setCursor(0, 0);
  lcd.print("Scan ready");
  lcd.clear();

  Serial3.begin(9600);
  gps.begin(GPSBaud);
  lcd.print("Ammo Tracking");
  lcd.setCursor(0, 1);
  lcd.print("    System      ");
  delay(2000);


  SIM800_init();
  lcd.clear();
  SIM800.println("AT+CNMI=2,2,0,0,0");

  lcd.print("GPS Initializing");
  lcd.setCursor(0, 1);
  lcd.print("  No GPS Range  ");
  get_gps();
  delay(2000);
  lcd.clear();
  lcd.print("GPS Range Found");
  lcd.setCursor(0, 1);
  lcd.print("GPS is Ready");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  temp = 0;
}

void loop()
{
  serialEvent();
  if (temp)
  {
    get_gps();
    tracking();
  }
  int getFingerprintIDez() {
    uint8_t p = finger.getImage();
    if (p != FINGERPRINT_OK)  {
      lcd.setCursor(0, 0);
      lcd.print(" Scanner ready");

      return -1;
    }

    p = finger.image2Tz();
    if (p != FINGERPRINT_OK)  {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("  Messy Image");
      lcd.setCursor(0, 1);
      lcd.print("  Try Again");
      delay(3000);
      lcd.clear();
      return -1;
    }

    p = finger.fingerFastSearch();
    if (p != FINGERPRINT_OK)  {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Not a valid Finger");
      delay(3000);
      lcd.clear();
      return -1;
    }

    // found a match!
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("  Door Unlocked");
    lcd.setCursor(0, 1);
    lcd.print("    Welcome");
    digitalWrite(relayPin, LOW);
    delay(3000);
    digitalWrite(relayPin, HIGH);
    lcd.clear();
    return finger.fingerID;

  }
}

void serialEvent()
{
  while (SIM800.available())
  {
    if (SIM800.find("RING"))
    {
      temp = 1;
      break;
      lcd.print("SMS received");
    }
    else
      temp = 0;
  }
}

void gpsEvent()
{
  gpsString = "";
  while (1)
  {
    while (gps.available() > 0)          //checking serial data from GPS
    {
      char inChar = (char)gps.read();
      gpsString += inChar;                   //store data from GPS into gpsString
      i++;
      if (i < 7)
      {
        if (gpsString[i - 1] != test[i - 1])    //checking for $GPGGA sentence
        {
          i = 0;
          gpsString = "";
        }
      }
      if (inChar == '\r')
      {
        if (i > 65)
        {
          gps_status = 1;
          break;
        }
        else
        {
          i = 0;
        }
      }
    }
    if (gps_status)
      break;
  }
}

void SIM800_init()
{
  lcd.clear();
  lcd.print("Finding Module..");
  boolean at_flag = 1;
  while (at_flag)
  {
    SIM800.println("AT");
    while (SIM800.available() > 0)
    {
      if (SIM800.find("OK"))
        at_flag = 0;
    }

    delay(1000);
  }

  lcd.clear();
  lcd.print("Module Connected..");
  delay(1000);
  lcd.clear();
  lcd.print("Disabling ECHO");
  boolean echo_flag = 1;
  while (echo_flag)
  {
    SIM800.println("ATE1");
    SIM800.println("AT+CGATT=1");
    SIM800.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\" ");
    SIM800.println("AT+SAPBR=3,1,\"APN\",\"RCMNET\" ");
    SIM800.println("AT+SAPBR=1,1");

    while (SIM800.available() > 0)
    {
      if (SIM800.find("OK"))
        echo_flag = 0;
    }
    delay(1000);
  }

  lcd.clear();
  lcd.print("Echo OFF");
  delay(1000);
  lcd.clear();
  lcd.print("Finding Network..");
  boolean net_flag = 1;
  while (net_flag)
  { SIM800.println("ATE0");
    SIM800.println("AT+CPIN?");

    while (SIM800.available() > 0)
    {
      if (SIM800.find("+CPIN: READY"))
        net_flag = 0;
    }
    delay(4000);
  }
  lcd.clear();
  lcd.print("Network Found..");
  delay(1000);
  lcd.clear();
}

void get_gps()
{
  gps_status = 0;
  int x = 0;
  while (gps_status == 0)
  {
    gpsEvent();
    int str_lenth = i;
    latitude = "";
    longitude = "";
    int comma = 0;
    while (x < str_lenth)
    {
      if (gpsString[x] == ',')
        comma++;
      if (comma == 2)     //extract latitude from string
        latitude += gpsString[x + 1];
      else if (comma == 4)     //extract longitude from string
        longitude += gpsString[x + 1];
      x++;
    }
    int l1 = latitude.length();
    latitude[l1 - 1] = ' ';
    l1 = longitude.length();
    longitude[l1 - 1] = ' ';
    lcd.clear();
    lcd.print("Lat:");
    lcd.print(latitude);
    lcd.setCursor(0, 1);
    lcd.print("Long:");
    lcd.print(longitude);
    i = 0; x = 0;
    str_lenth = 0;
    delay(2000);
  }
}

void init_sms()
{
  SIM800.println("AT+CMGF=1");
  delay(1000);
  SIM800.println("AT+CMGS=\"+94779994223\"");   // use your 10 digit cell no. here
  delay(1000);

}

void send_data(String message)
{
  SIM800.println(message);
  delay(200);
}

void send_sms()
{
  SIM800.write(26);
}

void lcd_status()
{
  lcd.clear();
  lcd.print("Message Sent");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  return;
}

void tracking()
{
  init_sms();
  send_data("Locker Tracking Alert:");
  send_data("Your Locker's Current Location:");
  SIM800.print("Latitude:");
  send_data(latitude);
  SIM800.print("Longitude:");
  send_data(longitude);
  send_data("Please take some action soon..\nThankyou");
  send_sms();
  delay(2000);
  lcd_status();
}

void fn()
{
  getFingerprintIDez();
}
1 Like

That's right - you can't define a function inside another function.

Please don't post pictures,post code and error messages.

Why are you calling serialEvent?

1 Like

@shaggyzynther did you forget the code tags and did you see that handy button labelled "Copy error messages" that you could have used ?

1 Like

You can call the fn() function from loop():

#include <Adafruit_Fingerprint.h>
#include <SPI.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include<LiquidCrystal_I2C.h>
SoftwareSerial SIM800(10, 11);

#define gps Serial3
#define mySerial Serial1
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

// LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); //LCD declaring
LiquidCrystal_I2C lcd(I2C_ADDR, 16, 2); //LCD 

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
static const uint32_t GPSBaud = 9600;

int relayPin = 8;

//String str="";
char str[70];
String gpsString = "";

char *test = "$GPGGA";

String latitude = "No Range      ";
String longitude = "No Range     ";

int temp = 0, i;
boolean gps_status = 0;

void setup()
{

  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
  SIM800.begin(9600);
  Serial.begin(9600);
  while (!SIM800);
  delay(100);

  lcd.begin(16, 2);
  //lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.setCursor(0, 0);
  lcd.print("Smart Safe Sahan");
  lcd.setCursor(0, 1);
  lcd.print("Chandimal");
  delay(5000);
  lcd.clear();


  // set the data rate for the sensor serial port
  Serial1.begin(9600);
  finger.begin(57600);              //Sensor baude rate
  lcd.begin (16, 2);
  //lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  finger.getTemplateCount();        //Counts the number of templates stored in the sensor flash memory
  lcd.setCursor(0, 0);
  lcd.print("Scan ready");
  lcd.clear();

  Serial3.begin(9600);
  gps.begin(GPSBaud);
  lcd.print("Ammo Tracking");
  lcd.setCursor(0, 1);
  lcd.print("    System      ");
  delay(2000);


  SIM800_init();
  lcd.clear();
  SIM800.println("AT+CNMI=2,2,0,0,0");

  lcd.print("GPS Initializing");
  lcd.setCursor(0, 1);
  lcd.print("  No GPS Range  ");
  get_gps();
  delay(2000);
  lcd.clear();
  lcd.print("GPS Range Found");
  lcd.setCursor(0, 1);
  lcd.print("GPS is Ready");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  temp = 0;
}

void loop()
{
  serialEvent();
  if (temp)
  {
    get_gps();
    fn();
    tracking();
  }
}

void serialEvent()
{
  while (SIM800.available())
  {
    if (SIM800.find("RING"))
    {
      temp = 1;
      break;
      lcd.print("SMS received");
    }
    else
      temp = 0;
  }
}

void gpsEvent()
{
  gpsString = "";
  while (1)
  {
    while (gps.available() > 0)          //checking serial data from GPS
    {
      char inChar = (char)gps.read();
      gpsString += inChar;                   //store data from GPS into gpsString
      i++;
      if (i < 7)
      {
        if (gpsString[i - 1] != test[i - 1])    //checking for $GPGGA sentence
        {
          i = 0;
          gpsString = "";
        }
      }
      if (inChar == '\r')
      {
        if (i > 65)
        {
          gps_status = 1;
          break;
        }
        else
        {
          i = 0;
        }
      }
    }
    if (gps_status)
      break;
  }
}

void SIM800_init()
{
  lcd.clear();
  lcd.print("Finding Module..");
  boolean at_flag = 1;
  while (at_flag)
  {
    SIM800.println("AT");
    while (SIM800.available() > 0)
    {
      if (SIM800.find("OK"))
        at_flag = 0;
    }

    delay(1000);
  }

  lcd.clear();
  lcd.print("Module Connected..");
  delay(1000);
  lcd.clear();
  lcd.print("Disabling ECHO");
  boolean echo_flag = 1;
  while (echo_flag)
  {
    SIM800.println("ATE1");
    SIM800.println("AT+CGATT=1");
    SIM800.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\" ");
    SIM800.println("AT+SAPBR=3,1,\"APN\",\"RCMNET\" ");
    SIM800.println("AT+SAPBR=1,1");

    while (SIM800.available() > 0)
    {
      if (SIM800.find("OK"))
        echo_flag = 0;
    }
    delay(1000);
  }

  lcd.clear();
  lcd.print("Echo OFF");
  delay(1000);
  lcd.clear();
  lcd.print("Finding Network..");
  boolean net_flag = 1;
  while (net_flag)
  {
    SIM800.println("ATE0");
    SIM800.println("AT+CPIN?");

    while (SIM800.available() > 0)
    {
      if (SIM800.find("+CPIN: READY"))
        net_flag = 0;
    }
    delay(4000);
  }
  lcd.clear();
  lcd.print("Network Found..");
  delay(1000);
  lcd.clear();
}

void get_gps()
{
  gps_status = 0;
  int x = 0;
  while (gps_status == 0)
  {
    gpsEvent();
    int str_lenth = i;
    latitude = "";
    longitude = "";
    int comma = 0;
    while (x < str_lenth)
    {
      if (gpsString[x] == ',')
        comma++;
      if (comma == 2)     //extract latitude from string
        latitude += gpsString[x + 1];
      else if (comma == 4)     //extract longitude from string
        longitude += gpsString[x + 1];
      x++;
    }
    int l1 = latitude.length();
    latitude[l1 - 1] = ' ';
    l1 = longitude.length();
    longitude[l1 - 1] = ' ';
    lcd.clear();
    lcd.print("Lat:");
    lcd.print(latitude);
    lcd.setCursor(0, 1);
    lcd.print("Long:");
    lcd.print(longitude);
    i = 0; x = 0;
    str_lenth = 0;
    delay(2000);
  }
}

void init_sms()
{
  SIM800.println("AT+CMGF=1");
  delay(1000);
  SIM800.println("AT+CMGS=\"+94779994223\"");   // use your 10 digit cell no. here
  delay(1000);

}

void send_data(String message)
{
  SIM800.println(message);
  delay(200);
}

void send_sms()
{
  SIM800.write(26);
}

void lcd_status()
{
  lcd.clear();
  lcd.print("Message Sent");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  return;
}

void tracking()
{
  init_sms();
  send_data("Locker Tracking Alert:");
  send_data("Your Locker's Current Location:");
  SIM800.print("Latitude:");
  send_data(latitude);
  SIM800.print("Longitude:");
  send_data(longitude);
  send_data("Please take some action soon..\nThankyou");
  send_sms();
  delay(2000);
  lcd_status();
}

void fn()
{
  getFingerprintIDez();
}

int getFingerprintIDez()
{
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)
  {
    lcd.setCursor(0, 0);
    lcd.print(" Scanner ready");

    return -1;
  }

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("  Messy Image");
    lcd.setCursor(0, 1);
    lcd.print("  Try Again");
    delay(3000);
    lcd.clear();
    return -1;
  }

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Not a valid Finger");
    delay(3000);
    lcd.clear();
    return -1;
  }

  // found a match!
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("  Door Unlocked");
  lcd.setCursor(0, 1);
  lcd.print("    Welcome");
  digitalWrite(relayPin, LOW);
  delay(3000);
  digitalWrite(relayPin, HIGH);
  lcd.clear();
  return finger.fingerID;

}
1 Like

Just got it fixed ,Thanks guys! For all the replies :heart: