Enrolling your fingerprint

The first thing that we have to do is enroll at least one fingerprint so that it can be later recognized by the sensor. We will do that in this section. Here is most of the code for this section:

// Libraries
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

// Fingerprint enroll function
uint8_t getFingerprintEnroll(uint8_t id);

// Software Serial instance
SoftwareSerial mySerial(2, 3);

// Fingerprint sensor instance
Adafruit_Fingerprint finger = Adafruit_Fingerprint(andmySerial);

void setup() 
{
  // Start serial
  Serial.begin(9600);
  Serial.println("fingertest");

  // Set the data rate for the sensor serial port
  finger.begin(57600);

  // Verify that sensor is present
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
}

void loop()
{
  // Wait for fingerprint ID
  Serial.println("Type in the ID # you want to save this finger as...");
  uint8_t id = 0;
  while (true) {
    while (! Serial.available());
    char c = Serial.read();
    if (! isdigit(c)) break;
    id *= 10;
    id += c - '0';
  }
  Serial.print("Enrolling ID #");
  Serial.println(id);
 
  while (!  getFingerprintEnroll(id) );
}

You will note that I didn't include all the details of fingerprint sensor functions as they are too long to be displayed here. You can, of course, find the whole code in the GitHub repository of this book.

Now, let's see the details of the code. It starts by including the required libraries:

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

Then, we declare the function that we will use in order to enroll our fingerprint:

uint8_t getFingerprintEnroll(uint8_t id);

After that, we create the software serial instance that we will use to communicate with the server:

SoftwareSerial mySerial(2, 3);

We will also create the fingerprint sensor instance:

Adafruit_Fingerprint finger = Adafruit_Fingerprint(andmySerial);

Now, in the setup() function of the sketch, we will initialize serial communications:

Serial.begin(9600);
Serial.println("fingertest");

Then, we will initialize the communication with the sensor:

finger.begin(57600);

We will also check whether the sensor is present:

if (finger.verifyPassword()) {
  Serial.println("Found fingerprint sensor!");
} else {
  Serial.println("Did not find fingerprint sensor :(");
  while (1);
}

In the loop() function of the code, we will first wait for an input from the user, which is the ID of the fingerprint that we want to store. Then, we go through the process of storing the fingerprint. This is all done by the following code snippet:

// Wait for fingerprint ID
Serial.println("Type in the ID # you want to save this finger as...");
  uint8_t id = 0;
  while (true) {
    while (! Serial.available());
    char c = Serial.read();
    if (! isdigit(c)) break;
    id *= 10;
    id += c - '0';
  }
  Serial.print("Enrolling ID #");
  Serial.println(id);
 
  while (!  getFingerprintEnroll(id) );

It's now the time to test the enrollment process. First, get the complete code, for example, from the GitHub repository of the book, which is available at https://github.com/marcoschwartz/arduino-secret-agents.

Then, copy the code in the Arduino IDE. After that, upload the code to the Arduino board and open the serial monitor with a speed of 9600 baud. The following screenshot is what you should see:

Enrolling your fingerprint

On being prompted, enter the ID of the fingerprint that you want to store and press enter. The sketch will now ask you to put your finger on the sensor. Do so and, after a while, you should see that the image was taken and you can now remove your finger:

Enrolling your fingerprint

Then, as asked by the sketch, put your finger on the sensor once more. The sketch will then confirm that the fingerprint has been stored:

Enrolling your fingerprint

If you can see this message, it means that your fingerprint is now stored in the sensor and you can move to the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.221.144