I am trying to implement a security terminal using a fingerprint sensor and an Arduino Mega 2560. It acquires the user's fingerprint and sends an OTP to the user's mobile number which when input into a keypad grants access to the user. I am using an Arduino Mega 2560, R307 fingerprint sensor, a GSM SIM800A modem and an LCD display. The problem is when I uploaded the code, the fingerprint sensor stopped responding. I think it is a coding mistake because I tested the sensor individually, and it worked. Can you guys point out the mistakes in the code?
Thanks
You have a Mega2560 which has 4 (in words: four) hardware serial interfaces and you use two SoftwareSerial instances? You know that SoftwareSerial is a crippled piece of software that you may only use if you have absolutely no other chance, don't you?
Next problem:
finger.begin(57600);
mySerial.begin(9600);
You initialize the baud rate twice for the same instance of SoftwareSerial. Guess which one will be used?
A baud rate of 57600 with SoftwareSerial will work only in the very seldom case of an extremely timing tolerant device connected to it.
BTW: Changing the Adafruit Fingerprint library to accept HardwareSerial objects instead of SoftwareSerial is simply a running a replace over the complete library. I would strongly recommend doing that.
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
SoftwareSerial mySerial(10, 11);
Can you post a picture of the mySerial that is connected? There is NOTHING useful in that name. It's like getting a dog and calling it myDog.
SoftwareSerial mySerial2(12, 13);
Can you post a picture of the mySerial2 that is connected?
Did you read the documentation for SoftwareSerial? How many instances can listen at the same time?
mySerial2.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial2.println("AT+CMGS=\"+919886924719\"\r"); // Replace x with mobile number
delay(1000);
mySerial2.println(randNumber);// The SMS text you want to send
delay(100);
mySerial2.println((char)26);// ASCII code of CTRL+Z
delay(1000);
This is like posting on the forum and never reading the replies. I don't know why I'm bothering to type one up. You won't read it.
The hardware MAY be telling you something, if only you'd listen.
It doesn't do much good to send data to the (uselessly named) mySerial2 instance since you have not called mySerial2.begin().