In this project we want to have a secure lock that opens with a registered Fingerprint image. We will have a buzzer and LED lights interacting with it. We will have two different code, one for registering a fingerprint and second for opening the Safe lock.
LED lights (x2) - Red and Green
Resistors (x2) - 220 Ohm
If you don't have any of those materials, you can buy the kit in our shop :
Our goal for this circuit is to have our fingerprint sensor sense for an image and open the lock, in this case, the servo. We also want two LED lights and a buzzer interacting with it. In the image below, we don't have the fingerprint sensor. It will be further explained later. First, we are going to set up our breadboard. We have the ground and 5V pins from the Arduino going to the negative and positive respectively. This way we can connect any ground and positive pins to the breadboard. Next, our servo. We want our servo to be our lock. The red and brown wires automatically to the positive and negative in the breadboard. The orange wire is our output pin. It's how we communicate with the Arduino. We are going to connect it to pin 9. The buzzer is pretty straightforward, we want to have the buzzer because we want to hear a sound when the lock opens. We connect its negative to the negative on the breadboard and it's positive to pin number 8 on the Arduino. The positive has a little plus sign at the top of the buzzer. Lastly, our LED lights. For the LEDs, we have their positive being connected to each of their 220-ohm resistors. Then they are being connected to pin 4 for the red one and pin 5 for the green one. And their negative pins are connected to the negative pin on the breadboard.
The Fingerprint module is a sensor that takes is an image, converts it, and sets it to an ID. First, you need to enroll your fingerprint then you can check if it matches. Most fingerprint modules have four pins we need to connect. The RX and TX pins are input pins where the fingerprint captures a finger's image. The RX(white wire) is connected to pin 2, and the TX(Green wire) is connected to pin 3. And the black and red wires go to the negative and positive respectively on the breadboard. Some of the fingerprint sensors have six wires. For those, you can leave the other two not connected.
We are going to have two different programs that we are going to run. But first, we need to add the Adafruit Fingerprint. To do that we have to go to the scroll-down menu at the top to sketch. Then we will find include library, then we're going to choose the first option, manage libraries. The library manager will pop up, and we're going to search up "Adafruit Fingerprint" and "Adafruit Fingerprint Sensor Library" should be as an option and we're going to install that. And that should have whatever we need for the fingerprint sensor
The first one is to enroll a fingerprint. If we want to add another fingerprint to open our lock, we should run this one. And to start us off we are going to run this one.
First, we included the fingerprint library. We are creating a new object called mySerial and declaring our sensor pins to 2 and 3. The parameters for mySerial are supposed to be the pins we connected to the Arduino. Next, we are creating the biggest object in the whole code called "finger". This is what we will be calling all the time. And we have the parameters set to mySerial. Then we are creating another variable called id. The reference uint8_t just means it's a variable with 8 bits.
Next, we have our setup. We're going to start with setting our serial monitor as it's going to be one of the most important things. The next thing is the if statement. This if statement makes sure if the fingerprint sensor is connected to Arduino. If it finds the sensor it will keep going, if not it will do nothing forever. Finally, we have a bunch of lines calling the library and matching them with our object finger. These are just important values to capture a finger's image.
We also have another function that will help us input an ID from the user and save it so that we can set it so a fingerprint image. We're asking for the user input using "Serial.parseInt()". And then we're setting it to our variable num.
Now we are going to our loop. This is what happens when the Arduino is on. We're serial printing that we're ready to take a fingerprint. We are also calling the "readnumber" function that is going to help us get an ID number for our fingerprint that we're about to set it to. Then we're calling the biggest function in this code. We are calling "getFingerprintEnroll()". We are saying repeat until we get a fingerprint image. Let's go over what the function does.
The function is located right below the main loop. So we start by serial printing that we are enrolling a fingerprint with the id we got for the main loop. And then we have a while loop that says, while p isn't equal to "FINGERPRINT _OK" keep repeating. This basically means we are going to repeat the code inside it until we have a valid fingerprint image. Inside it we are first setting it to "finger.getImage()". And then we have a bunch of switch statements. We are seeing if our variable p, which is our fingerprint image, is equal to any of the cases. For example, the first is "FINGERPRINT_OK". This is a variable that's in the library. We are checking if our fingerprint image is correctly taken or not. All the next cases are just possibilities if something goes wrong. Maybe if there are communication or image errors. It then goes to the next set of cases.
The next set of cases has something to do with the image being converted to a reasonable value for us to match with. First, we're setting our variable p to the "finger.image2Tz(1)" which is our fingerprint image to be converted. If it's a success we're going to move on to the next step until one of the problems happens. And the parameter means that this is the first time we're scanning for an image.
Now we're done with the first image scan. We're going to as our users to remove their fingers. Now we're going to do the same thing to make sure it's accurate. We're are going to capture the image and convert it again. That's why the cases are being repeated. In this case, when we're scanning the image, we set our variable p to finger.image2Tz(2). The parameter is 2 because this is our second trial. When we finish scanning the image and converting it, we have our last if-else statements. This is for storing our image as a model. We're al