0

My project was to open the door from inside and outside the room using fingerprint sensors, currently I used separate arduino on 2 different fingerprint sensor. Please help, my arduino detected only 1 fingerprint sensor when I try to connect them both on 1 arduino. ps: I connected the fingerprint sensor to digital pins (2,3) and (10,11) of the arduino mega. Thank you in advance...

//Here is my code

//for Relay

int in1 = 8; //pin for opening door 

int in2 = 9; //pin for buzzer

 #include (<)Adafruit_Fingerprint.h> 

//it (<) i use only to post the code 

//Arduino Mega

SoftwareSerial mySerial1(2, 3); //for fingeprint sensor outside

SoftwareSerial mySerial2(10, 11);//for fingeprint sensor inside

Adafruit_Fingerprint finger1 = Adafruit_Fingerprint(&mySerial1);

Adafruit_Fingerprint finger2 = Adafruit_Fingerprint(&mySerial2);

void setup()  
{

Serial.begin(115200);

pinMode(in1, OUTPUT);

 pinMode(in2, OUTPUT);

 digitalWrite(in1, HIGH);

 digitalWrite(in2, HIGH);

  while (!Serial); 

delay(100);

  finger1.begin(57600);

finger2.begin(57600);

  if (finger1.verifyPassword() and finger2.verifyPassword()) { //To verify if 2 

fingerprint sensor is working

 Serial.println("Found fingerprint sensors!");

} else {

 Serial.println("Did not find any fingerprint sensor!");

while (1) { delay(1); }

 }

  finger1.getTemplateCount(); //To show the numbers of enrolled fingerprint in sensor

 finger2.getTemplateCount(); 

  Serial.print("Fingerprint Sensor1 contains "); 

Serial.print(finger1.templateCount); Serial.println(" templates");

 Serial.print("Fingerprint Sensor2 contains "); 

Serial.print(finger2.templateCount); Serial.println(" templates");

Serial.println("Waiting for valid finger...");

}

void loop()                    
{

 //for fingeprint sensor outside the door
  getFingerprintID1();
  delay(50);           

//for fingeprint sensor inside the door
  getFingerprintID2();
  delay(50);   
}

uint8_t getFingerprintID1() {

uint8_t p = finger1.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;

 }


// OK success!

  p = finger1.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 = finger1.fingerFastSearch();

if (p == FINGERPRINT_OK) {

 Serial.println("Found a print match!");

digitalWrite(in1, LOW);  //Door will open for 5 seconds 

 delay(5000);

 digitalWrite(in1, HIGH);

 delay(1000);

 Serial.print(finger1.fingerID); 

 } else if (p == FINGERPRINT_PACKETRECIEVEERR) {

  //Serial.println("Communication error");

  return p;

} else if (p == FINGERPRINT_NOTFOUND) {

 Serial.println("Did not find a match");

 digitalWrite(in2,LOW); //if the fingerprint did not recognize buzzer will be ON

delay(1000);

 digitalWrite(in2,HIGH);

return p;

 } else {

//Serial.println("Unknown error");

 return p;

 }   

return finger1.fingerID;

}

uint8_t getFingerprintID2() {

uint8_t p = finger2.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;

 }

  // OK success!
  p = finger2.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 = finger2.fingerFastSearch();

if (p == FINGERPRINT_OK) {

 Serial.println("Found a print match!");

digitalWrite(in1, LOW); 

 delay(3000);

digitalWrite(in1, HIGH);

 delay(1000);

 Serial.print(finger2.fingerID); 

} else if (p == FINGERPRINT_PACKETRECIEVEERR) {

 //Serial.println("Communication error");

  return p;

  } else if (p == FINGERPRINT_NOTFOUND) {

 Serial.println("Did not find a match");

 digitalWrite(in2,LOW);

 delay(1000);

 digitalWrite(in2,HIGH);

 return p;

 } else {

 //Serial.println("Unknown error");

  return p;

 }   

 return finger2.fingerID;

}
4
  • Don't ask your question again. You can edit your first question. Also please format the code correctly by selecting it in the question editor and clicking the {} button or pressing Control+K.
    – chrisl
    Nov 26, 2019 at 9:41
  • Why are you using software serial, when the Mega has 4 hardware serial interfaces?
    – chrisl
    Nov 26, 2019 at 9:43
  • sorry sir, I am a beginner thanks for the concerns
    – Time Gold
    Nov 26, 2019 at 9:44
  • @chrisl im using adafruit library thats why i use 2 software serials, how can I use hardware serial properly? please help
    – Time Gold
    Nov 26, 2019 at 9:48

1 Answer 1

0

I guess your problem is, that you are using SoftwareSerial. Doing Serial in software means, that you can only listen at one interface at a time, thus only one of the fingerprint sensors work at a time.

But you are using the Arduino Mega, which has 4 hardware Serial interfaces. They are named Serial and SerialX (with X being 1,2 or 3). You can give a reference to these Serial interfaces to the Adafruit library just like you are doing it with the SoftwareSerial interfaces. You are doing:

Adafruit_Fingerprint finger1 = Adafruit_Fingerprint(&mySerial1);

Instead you could do:

Adafruit_Fingerprint finger1 = Adafruit_Fingerprint(&Serial1);

That will give a reference of the second hardware serial interface (first whould be Serial) to the Adafruit library, which will then use it to communicate with the sensor. Hardware and Software Serial implement the same interface, they just work differently under the hood, so you can easily exchange them at this level.

3
  • For Hardware Serial you cannot define your own pins. You have to use the pins corresponding to the used interface. For Serial1 this is pin 19 (RX) and pin 18 (TX)
    – chrisl
    Nov 26, 2019 at 10:10
  • Thank you!!! now I know how to use hardware serial on arduino mega :)))
    – Time Gold
    Nov 26, 2019 at 10:11
  • I use this link as reference thank you
    – Time Gold
    Nov 26, 2019 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.