ESP32

ESP32 based Biometric Door Lock system using R307 Fingerprint Sensor & Blynk IoT

IoT based Fingerprint Door Lock System with ESP32

Today we are building an ESP32-based biometric door lock system using the R307 fingerprint sensor and Blynk IoT platform. In this tutorial, we’ll guide you through the entire process of setting up the hardware, programming the ESP32, and configuring the Blynk web dashboard. So, Let’s get started!


Overview: ESP32 based IoT Fingerprint Door Lock

First, let’s understand how this system works. The ESP32, along with the R307 fingerprint sensor, acts as the main controller for the door lock system. The system allows authorized users to unlock the door using their fingerprints. Once a fingerprint is scanned, the ESP32 verifies it with the stored fingerprints in its memory. If the fingerprint matches, the ESP32 triggers the solenoid door lock, granting access to the user.

A small 0.96-inch OLED Display displays information like Access Denied or Access Granted through graphics.

You can also monitor your door lock remotely from anywhere in the world using Blynk IoT mobile App as well as the blynk web dashboard.


Hardware Requirements

To build this ESP32 based Biometric Door Lock system using R307 Fingerprint Sensor. You’ll need the following hardware components:

S.NCOMPONENTS NAMEQUANTITYPURCHASE LINKS
1ESP32 Dev Kit V1 Board1 Amazon | AliExpress
2R307 Fingerprint Sensor1 Amazon | AliExpress
30.96 inch OLED Display1 Amazon | AliExpress
412V Solenoid Lock1 Amazon | AliExpress
5Single channel 5V Relay Module1 Amazon | AliExpress
6Breadboard1 Amazon | AliExpress
7Buzzer1 Amazon | AliExpress
8Jumper Cables20 Amazon | AliExpress

Hardware Connection

Now, let’s connect all the components. The connections are fairly straightforward and will be as follows:

Circuit Diagram of ESP32 based Biometric Door Lock system using Fingerprint R307 Sensor and Blynk IoT
  • VCC pin of the fingerprint sensor to the Vin pin on the ESP32
  • GND pin of the fingerprint sensor to the GND pin on the ESP32
  • TX pin of the fingerprint sensor to RX2 pin on the ESP32
  • RX pin of the fingerprint sensor to TX2 pin on the ESP32
  • Relay Pin to ESP32 pin D23
  • OLED SDA pin to ESP32 Pin D21
  • OLED SCL pin to ESP32 Pin D22
  • OLED VCC pin to ESP32 3.3V
  • OLED GND pin to ESP32 GND

Project PCB Gerber File & PCB Ordering Online

If you don’t want to assemble the circuit on a zero PCB and you want PCB for the project, then here is the PCB for you. The PCB Board for this project looks something like below.

Biometric Fingerprint Door Lock PCB

The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from PCBWay.com.

Download PCB Gerber File

Now you can visit the PCBWay official website by clicking here: PCBWay.com. So you will be directed to the PCBWay website.

You can now upload the Gerber File to the Website and place an order. The PCB quality is superb & high standard. That is why most people trust PCBWay for PCB & PCBA ServicesPCBWay is a leading manufacturer of high-quality PCBs and offers a wide range of services, including PCB fabrication, assembly, and components sourcing.

  • 3D PCB IoT Fingerprint Door Lock
  • Biometric Fingerprint Door Lock PCB
  • PCB of Fingerprint Door Lock with ESP32

Setting up Blynk Web Dashboard

Next, let’s configure the Blynk web dashboard for our system. Start by creating a new template in the Blynk app.

Create a template

On a web Dashboard, add a Terminal widget and customize its properties. Create a Datastream connected to Virtual Pin V0. Choose its data type as a string.

Create and Assign datastream to widgets

Once you’re done, add the device to the Blynk app using the template. Make sure to copy the Blynk authentication token for later use.

Add device from Template

Program Code

Now, let’s take a look at the program code. Open the Arduino IDE or your preferred IDE, and paste the program code provided below.

#include <Adafruit_Fingerprint.h>   //https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library
#include <HardwareSerial.h>
#include <Adafruit_GFX.h>           //https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h>       //https://github.com/adafruit/Adafruit_SSD1306
#include <SPI.h>
#include <Wire.h>

#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID "TMPL6alI-f6lt"
#define BLYNK_TEMPLATE_NAME "Fingerprint Door Lock"
#define BLYNK_AUTH_TOKEN "W1ZqMfrYEiUwaca_ERfx_2DkF3XuzifEi"

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "IoT Projects Ideas";
char pass[] = "@12345678";
char auth[] = BLYNK_AUTH_TOKEN;
SimpleTimer timer;

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

WidgetTerminal terminal(V0);

// Icon of Fingerprint
#define LOGO_HEIGHT   64
#define LOGO_WIDTH    128
static const unsigned char PROGMEM logo_bmp[] =
{
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x83, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x03, 0xff, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f, 0xff, 0xf8, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0xff, 0xff, 0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0xe1, 0xff, 0x00, 0xff, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0xc7, 0xf0, 0x00, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0x8f, 0xc0, 0x00, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x03, 0xff, 0xc1, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x0f, 0xff, 0xf0, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x3f, 0xff, 0xfc, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x00, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0xf8, 0x00, 0x1f, 0x8f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0xe3, 0xf0, 0x18, 0x0f, 0xc7, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xc7, 0xc1, 0xff, 0x83, 0xe3, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xc7, 0x87, 0xff, 0xe1, 0xf1, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x07, 0x8f, 0x1f, 0xff, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x07, 0x1e, 0x3f, 0x01, 0xf8, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x07, 0x1e, 0x7e, 0x00, 0x7c, 0x79, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x78, 0x00, 0x3e, 0x3d, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xf0, 0xff, 0x1f, 0x3d, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0xe1, 0xff, 0x8f, 0x1c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0xe3, 0xff, 0xc7, 0x1e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0xe3, 0xc7, 0xc3, 0xc7, 0x9e, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x07, 0xe3, 0x8f, 0x01, 0xe7, 0x9e, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0f, 0xc7, 0x8f, 0x00, 0xe3, 0x9e, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x8f, 0x9e, 0x18, 0xf3, 0x9e, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0e, 0x0f, 0x1e, 0x38, 0xf3, 0x9e, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x3c, 0x38, 0xf3, 0x9e, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3c, 0x78, 0xf7, 0x9c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x78, 0x78, 0xe7, 0x9c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0xf0, 0xf1, 0xe7, 0x9c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x03, 0xe1, 0xf1, 0xe1, 0xe7, 0x3c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0f, 0xc3, 0xe3, 0xe3, 0xc7, 0x3c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x87, 0xc3, 0xc3, 0xcf, 0x3c, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x87, 0x87, 0x8f, 0x3c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x0f, 0x0f, 0x8f, 0x38, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x1f, 0x1f, 0x0f, 0x3c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3e, 0x1e, 0x0f, 0x3d, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x7c, 0x3c, 0xcf, 0x3c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0xf8, 0x79, 0xcf, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0f, 0xc1, 0xf0, 0xf9, 0xcf, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0f, 0x07, 0xe1, 0xf1, 0xc7, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x0e, 0x0f, 0xc3, 0xe3, 0xc7, 0x87, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x07, 0xc3, 0xc7, 0x87, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x1f, 0x83, 0xc3, 0xc3, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3e, 0x01, 0xc3, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x7c, 0x01, 0xc1, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0xf8, 0x01, 0xe0, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x01, 0xc3, 0xf3, 0xf8, 0xf0, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe7, 0xfc, 0xf8, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xcf, 0xfe, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x1f, 0x1e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x3e, 0x0f, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x0f, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

//---------------------------------------------------------------
#define Fingerprint_valid_width 64
#define Fingerprint_valid_height 64
static const unsigned char PROGMEM Fingerprint_valid_bts[] = {
  0x00, 0x00, 0x03, 0xfe, 0x00, 0x00, 0x00, 0x00
  , 0x00, 0x00, 0x1f, 0xff, 0xe0, 0x00, 0x00, 0x00
  , 0x00, 0x00, 0x7f, 0xff, 0xf8, 0x00, 0x00, 0x00
  , 0x00, 0x00, 0xfc, 0x00, 0xfe, 0x00, 0x00, 0x00
  , 0x00, 0x03, 0xe0, 0x00, 0x1f, 0x00, 0x00, 0x00
  , 0x00, 0x07, 0xc0, 0x00, 0x07, 0x80, 0x00, 0x00
  , 0x00, 0x0f, 0x80, 0x00, 0x03, 0xe0, 0x00, 0x00
  , 0x00, 0x0e, 0x03, 0xff, 0x01, 0xe0, 0x00, 0x00
  , 0x00, 0x1c, 0x1f, 0xff, 0xe0, 0xf0, 0x00, 0x00
  , 0x00, 0x3c, 0x3f, 0xff, 0xf0, 0x78, 0x00, 0x00
  , 0x00, 0x78, 0x7c, 0x00, 0xf8, 0x3c, 0x00, 0x00
  , 0x00, 0x70, 0xf0, 0x00, 0x3c, 0x1c, 0x00, 0x00
  , 0x00, 0xe1, 0xe0, 0x00, 0x1e, 0x1c, 0x00, 0x00
  , 0x00, 0xe1, 0xc0, 0x00, 0x0f, 0x0e, 0x00, 0x00
  , 0x00, 0xc3, 0x81, 0xfc, 0x07, 0x0e, 0x00, 0x00
  , 0x00, 0x03, 0x83, 0xff, 0x07, 0x8e, 0x00, 0x00
  , 0x00, 0x07, 0x07, 0x8f, 0x83, 0x87, 0x00, 0x00
  , 0x00, 0x0f, 0x0f, 0x03, 0xc3, 0x87, 0x00, 0x00
  , 0x00, 0x1e, 0x0e, 0x01, 0xc3, 0x87, 0x00, 0x00
  , 0x00, 0x3c, 0x1c, 0x00, 0xe1, 0x87, 0x00, 0x00
  , 0x00, 0xf8, 0x1c, 0x30, 0xe1, 0x87, 0x00, 0x00
  , 0x07, 0xf0, 0x38, 0x70, 0xe1, 0x86, 0x00, 0x00
  , 0x07, 0xc0, 0x78, 0x70, 0xe3, 0x8e, 0x00, 0x00
  , 0x02, 0x00, 0xf0, 0xf0, 0xe3, 0x8e, 0x00, 0x00
  , 0x00, 0x01, 0xe0, 0xe0, 0xe3, 0x8e, 0x00, 0x00
  , 0x00, 0x03, 0xc1, 0xe1, 0xc3, 0x8e, 0x00, 0x00
  , 0x00, 0x0f, 0x83, 0xc3, 0xc3, 0x8e, 0x00, 0x00
  , 0x00, 0x7f, 0x07, 0x83, 0x83, 0x0e, 0x00, 0x00
  , 0x07, 0xfc, 0x0f, 0x07, 0x83, 0x0e, 0x00, 0x00
  , 0x07, 0xf0, 0x1e, 0x0f, 0x03, 0x0e, 0x00, 0x00
  , 0x07, 0x80, 0x7c, 0x1e, 0x03, 0x07, 0x00, 0x00
  , 0x00, 0x00, 0xf8, 0x3c, 0x03, 0x87, 0x80, 0x00
  , 0x00, 0x03, 0xf0, 0x78, 0x03, 0x83, 0xc0, 0x00
  , 0x00, 0x1f, 0xc0, 0xf0, 0x02, 0x00, 0x00, 0x00
  , 0x00, 0xff, 0x01, 0xe1, 0xc0, 0x0c, 0x00, 0x00
  , 0x07, 0xfc, 0x03, 0xc3, 0xe1, 0xff, 0xc0, 0x00
  , 0x07, 0xe0, 0x0f, 0x87, 0xc7, 0xff, 0xf0, 0x00
  , 0x07, 0x00, 0x3f, 0x0f, 0x0f, 0xff, 0xfc, 0x00
  , 0x00, 0x00, 0x7c, 0x3e, 0x3f, 0xff, 0xfe, 0x00
  , 0x00, 0x03, 0xf8, 0x7c, 0x3f, 0xff, 0xff, 0x00
  , 0x00, 0x1f, 0xe0, 0xf0, 0x7f, 0xff, 0xff, 0x80
  , 0x00, 0xff, 0x83, 0xe0, 0xff, 0xff, 0xff, 0x80
  , 0x01, 0xfc, 0x07, 0xc1, 0xff, 0xff, 0xe3, 0xc0
  , 0x01, 0xe0, 0x1f, 0x01, 0xff, 0xff, 0xc3, 0xc0
  , 0x00, 0x00, 0xfe, 0x01, 0xff, 0xff, 0x87, 0xe0
  , 0x00, 0x03, 0xf8, 0x13, 0xff, 0xff, 0x0f, 0xe0
  , 0x00, 0x1f, 0xe0, 0x73, 0xff, 0xfe, 0x1f, 0xe0
  , 0x00, 0x7f, 0x81, 0xf3, 0xff, 0xfc, 0x1f, 0xe0
  , 0x00, 0xfc, 0x03, 0xe3, 0xef, 0xf8, 0x3f, 0xe0
  , 0x00, 0x60, 0x0f, 0xc3, 0xc7, 0xf0, 0x7f, 0xe0
  , 0x00, 0x00, 0x3f, 0x03, 0xc3, 0xe0, 0xff, 0xe0
  , 0x00, 0x00, 0xfc, 0x03, 0xc1, 0xc1, 0xff, 0xe0
  , 0x00, 0x07, 0xf0, 0x13, 0xe0, 0x83, 0xff, 0xe0
  , 0x00, 0x0f, 0xc0, 0x7b, 0xf8, 0x07, 0xff, 0xe0
  , 0x00, 0x0f, 0x01, 0xf9, 0xfc, 0x0f, 0xff, 0xc0
  , 0x00, 0x00, 0x07, 0xf1, 0xfe, 0x1f, 0xff, 0xc0
  , 0x00, 0x00, 0x1f, 0xc0, 0xff, 0x3f, 0xff, 0x80
  , 0x00, 0x00, 0x7e, 0x00, 0xff, 0xff, 0xff, 0x80
  , 0x00, 0x00, 0xfc, 0x00, 0x7f, 0xff, 0xff, 0x00
  , 0x00, 0x00, 0xf0, 0x1f, 0x3f, 0xff, 0xfe, 0x00
  , 0x00, 0x00, 0x00, 0x7f, 0x1f, 0xff, 0xfc, 0x00
  , 0x00, 0x00, 0x01, 0xff, 0x8f, 0xff, 0xf8, 0x00
  , 0x00, 0x00, 0x03, 0xe0, 0xe3, 0xff, 0xe0, 0x00
  , 0x00, 0x00, 0x01, 0x80, 0x00, 0x7f, 0x00, 0x00
};
//---------------------------------------------------------------
#define Fingerprint_invalid_width 64
#define Fingerprint_invalid_height 64
static const unsigned char PROGMEM Fingerprint_invalid_bts[] = {
  0x00, 0x00, 0x03, 0xfe, 0x00, 0x00, 0x00, 0x00
  , 0x00, 0x00, 0x1f, 0xff, 0xe0, 0x00, 0x00, 0x00
  , 0x00, 0x00, 0x7f, 0xff, 0xf8, 0x00, 0x00, 0x00
  , 0x00, 0x00, 0xfc, 0x00, 0xfe, 0x00, 0x00, 0x00
  , 0x00, 0x03, 0xe0, 0x00, 0x1f, 0x00, 0x00, 0x00
  , 0x00, 0x07, 0xc0, 0x00, 0x07, 0x80, 0x00, 0x00
  , 0x00, 0x0f, 0x80, 0x00, 0x03, 0xe0, 0x00, 0x00
  , 0x00, 0x0e, 0x03, 0xff, 0x01, 0xe0, 0x00, 0x00
  , 0x00, 0x1c, 0x1f, 0xff, 0xe0, 0xf0, 0x00, 0x00
  , 0x00, 0x3c, 0x3f, 0xff, 0xf0, 0x78, 0x00, 0x00
  , 0x00, 0x78, 0x7c, 0x00, 0xf8, 0x3c, 0x00, 0x00
  , 0x00, 0x70, 0xf0, 0x00, 0x3c, 0x1c, 0x00, 0x00
  , 0x00, 0xe1, 0xe0, 0x00, 0x1e, 0x1c, 0x00, 0x00
  , 0x00, 0xe1, 0xc0, 0x00, 0x0f, 0x0e, 0x00, 0x00
  , 0x00, 0xc3, 0x81, 0xfc, 0x07, 0x0e, 0x00, 0x00
  , 0x00, 0x03, 0x83, 0xff, 0x07, 0x8e, 0x00, 0x00
  , 0x00, 0x07, 0x07, 0x8f, 0x83, 0x87, 0x00, 0x00
  , 0x00, 0x0f, 0x0f, 0x03, 0xc3, 0x87, 0x00, 0x00
  , 0x00, 0x1e, 0x0e, 0x01, 0xc3, 0x87, 0x00, 0x00
  , 0x00, 0x3c, 0x1c, 0x00, 0xe1, 0x87, 0x00, 0x00
  , 0x00, 0xf8, 0x1c, 0x30, 0xe1, 0x87, 0x00, 0x00
  , 0x07, 0xf0, 0x38, 0x70, 0xe1, 0x86, 0x00, 0x00
  , 0x07, 0xc0, 0x78, 0x70, 0xe3, 0x8e, 0x00, 0x00
  , 0x02, 0x00, 0xf0, 0xf0, 0xe3, 0x8e, 0x00, 0x00
  , 0x00, 0x01, 0xe0, 0xe0, 0xe3, 0x8e, 0x00, 0x00
  , 0x00, 0x03, 0xc1, 0xe1, 0xc3, 0x8e, 0x00, 0x00
  , 0x00, 0x0f, 0x83, 0xc3, 0xc3, 0x8e, 0x00, 0x00
  , 0x00, 0x7f, 0x07, 0x83, 0x83, 0x0e, 0x00, 0x00
  , 0x07, 0xfc, 0x0f, 0x07, 0x83, 0x0e, 0x00, 0x00
  , 0x07, 0xf0, 0x1e, 0x0f, 0x03, 0x0e, 0x00, 0x00
  , 0x07, 0x80, 0x7c, 0x1e, 0x03, 0x07, 0x00, 0x00
  , 0x00, 0x00, 0xf8, 0x3c, 0x03, 0x87, 0x80, 0x00
  , 0x00, 0x03, 0xf0, 0x78, 0x03, 0x83, 0xc0, 0x00
  , 0x00, 0x1f, 0xc0, 0xf0, 0x02, 0x00, 0x00, 0x00
  , 0x00, 0xff, 0x01, 0xe1, 0xc0, 0x00, 0x00, 0x00
  , 0x07, 0xfc, 0x03, 0xc3, 0xe1, 0xff, 0xc0, 0x00
  , 0x07, 0xe0, 0x0f, 0x87, 0xc7, 0xff, 0xf0, 0x00
  , 0x07, 0x00, 0x3f, 0x0f, 0x0f, 0xff, 0xf8, 0x00
  , 0x00, 0x00, 0x7c, 0x3e, 0x1f, 0xff, 0xfe, 0x00
  , 0x00, 0x03, 0xf8, 0x7c, 0x3f, 0xff, 0xff, 0x00
  , 0x00, 0x1f, 0xe0, 0xf0, 0x7f, 0xff, 0xff, 0x00
  , 0x00, 0xff, 0x83, 0xe0, 0xfe, 0xff, 0xbf, 0x80
  , 0x01, 0xfc, 0x07, 0xc0, 0xfc, 0x7f, 0x1f, 0xc0
  , 0x01, 0xe0, 0x1f, 0x01, 0xf8, 0x3e, 0x0f, 0xc0
  , 0x00, 0x00, 0xfe, 0x01, 0xf8, 0x1c, 0x07, 0xe0
  , 0x00, 0x03, 0xf8, 0x13, 0xf8, 0x00, 0x0f, 0xe0
  , 0x00, 0x1f, 0xe0, 0x73, 0xfc, 0x00, 0x1f, 0xe0
  , 0x00, 0x7f, 0x81, 0xf3, 0xfe, 0x00, 0x3f, 0xe0
  , 0x00, 0xfc, 0x03, 0xe3, 0xff, 0x00, 0x7f, 0xe0
  , 0x00, 0x60, 0x0f, 0xc3, 0xff, 0x80, 0xff, 0xe0
  , 0x00, 0x00, 0x3f, 0x03, 0xff, 0x00, 0x7f, 0xe0
  , 0x00, 0x00, 0xfc, 0x03, 0xfe, 0x00, 0x3f, 0xe0
  , 0x00, 0x07, 0xf0, 0x13, 0xfc, 0x00, 0x1f, 0xe0
  , 0x00, 0x0f, 0xc0, 0x79, 0xf8, 0x08, 0x0f, 0xe0
  , 0x00, 0x0f, 0x01, 0xf9, 0xf8, 0x1c, 0x0f, 0xc0
  , 0x00, 0x00, 0x07, 0xf1, 0xfc, 0x3e, 0x1f, 0xc0
  , 0x00, 0x00, 0x1f, 0xc0, 0xfe, 0x7f, 0x3f, 0x80
  , 0x00, 0x00, 0x7e, 0x00, 0xff, 0xff, 0xff, 0x80
  , 0x00, 0x00, 0xfc, 0x00, 0x7f, 0xff, 0xff, 0x00
  , 0x00, 0x00, 0xf0, 0x1f, 0x3f, 0xff, 0xfe, 0x00
  , 0x00, 0x00, 0x00, 0x7f, 0x1f, 0xff, 0xfc, 0x00
  , 0x00, 0x00, 0x01, 0xff, 0x8f, 0xff, 0xf8, 0x00
  , 0x00, 0x00, 0x03, 0xe0, 0xe3, 0xff, 0xe0, 0x00
  , 0x00, 0x00, 0x01, 0x80, 0x00, 0x7f, 0x00, 0x00
};
//---------------------------------------------------------------



Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2);

int relayPin = 23;
int buzzerPin = 15;

void setup()
{
  Blynk.begin(auth, ssid, pass);
  pinMode(relayPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);

  digitalWrite(relayPin, HIGH);
  digitalWrite(buzzerPin, LOW);

  Serial.begin(57600);
  Serial2.begin(115200);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
  {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  while (!Serial);
  delay(100);

  display.clearDisplay();
  display.drawBitmap(0, 0, logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
  display.display();

  Serial.println("Fingerprint Door Lock");
  delay(3000);
  display.clearDisplay();

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

  if (finger.verifyPassword())
  {
    Serial.println("Fingerprint Sensor Connected");
    display.clearDisplay();
    display.setTextSize(2);             // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);        // Draw white text
    display.setCursor(25, 0);            // Start at top-left corner
    display.println(("Sensor"));
    display.setCursor(5, 35);
    display.println("Connected");
    display.display();
    delay(3000);
    // display.clearDisplay();
  }

  else
  {
    display.clearDisplay();
    display.setTextSize(2);             // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);        // Draw white text
    display.setCursor(25, 0);            // Start at top-left corner
    display.println(("Sensor"));
    display.setCursor(5, 35);
    display.println("Not Found");
    display.display();

    Serial.println("Unable to find Sensor");
    delay(3000);
    Serial.println("Check Connections");

    while (1) {
      delay(1);
    }
  }
  display.clearDisplay();
  timer.setInterval(1000L, getFingerprintIDez);
}

void loop()                     // run over and over again
{
  timer.run();
  Blynk.run();
  getFingerprintIDez();
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez()
{
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)
  {

    display.clearDisplay();
    display.drawBitmap(0, 0, logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
    display.display();
    Serial.println("Waiting For Valid Finger");
    return -1;
  }

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)
  {
    display.clearDisplay();
    display.setTextSize(2);             // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);        // Draw white text
    display.setCursor(0, 0);            // Start at top-left corner
    display.println(("Messy  Image"));
    display.setCursor(0, 35);
    display.println("Try Again");
    display.display();

    Serial.println("Messy Image Try Again");
    delay(3000);
    display.clearDisplay();
    return -1;
  }

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  {

    display.clearDisplay();
    display.setTextSize(2);             // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);        // Draw white text
    display.drawBitmap(34, 0, Fingerprint_invalid_bts, Fingerprint_invalid_width, Fingerprint_invalid_height, 1);
    display.display();
    Serial.println("Not Valid Finger");
    digitalWrite(buzzerPin, HIGH);
    delay(3000);
    display.clearDisplay();
    Blynk.virtualWrite(V0, "Access Denied, Invalid Fingerprint" );

    digitalWrite(buzzerPin, LOW);
    return -1;
  }

  // found a match!
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setTextSize(2);
  display.drawBitmap(34, 0, Fingerprint_valid_bts, Fingerprint_valid_width, Fingerprint_valid_height, 1);
  display.display();
  digitalWrite(relayPin, LOW);
  delay(1000);
  display.clearDisplay();
  display.setCursor(40, 0);            // Start at top-left corner
  display.println(("Door"));
  display.setCursor(15, 20);            // Start at top-left corner
  display.println(("Unlocked"));
  display.setCursor(20, 40);
  display.println("Welcome");
  display.display();
  Blynk.virtualWrite(V0, "Access Granted, Door Unlocked" );
  delay(3000);

  display.clearDisplay();
  display.setTextSize(2);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(20, 20);            // Start at top-left corner
  display.println(("Closing"));
  display.setCursor(20, 40);            // Start at top-left corner
  display.println(("the Door"));
  display.display();
  digitalWrite(relayPin, HIGH);
  delay(3000);

  display.clearDisplay();

  Serial.println("Door Unlocked Welcome");

  return finger.fingerID;
}

Now replace the blynk credentials. Also, don’t forget to replace the placeholders with your Wi-Fi credentials.

/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID "TMPL6alI-f6lt"
#define BLYNK_TEMPLATE_NAME "Fingerprint Door Lock"
#define BLYNK_AUTH_TOKEN "W1ZqMfrYEiUwaca_ERfx_2DkF3XuzifEi"

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "IoT Projects Ideas";
char pass[] = "@12345678";
char auth[] = BLYNK_AUTH_TOKEN;

Make sure to install all the required libraries as well.

Once everything is set up, upload the program code to the ESP32 Doit Kit V1 by selecting the correct COM port.

Selecting ESP32 Board and COM Port in Arduino IDE

Demo and Testing: IoT Fingerprint Door Lock

After a successful upload, open the serial monitor at a baud rate of 57600. This will allow you to monitor the system’s output and debug any issues. Now, it’s time to test the system.

Serial Monitor

If you don’t know how to Enroll the fingerprint then go through this tutorial about the R307 Fingerprint sensor. Now Try placing your registered fingerprint on the sensor and observe the results. If the fingerprint is authorized, you’ll see the successful fingerprint verification and the relay turns ON to unlock the solenoid door lock. Indicating a successful unlock on the OLED display.

ESP32 based Biometric Door Lock system using Fingerprint R307 Sensor
ESP32 based Biometric Door Lock system using R307 Fingerprint Sensor & Blynk IoT

If your fingerprint does not match then the system will notify you through LED or Buzzer as well as From OLED Display.

ESP32 based Biometric Door Lock system using Fingerprint R307 Sensor and Blynk
ESP32 based Biometric Door Lock system using R307 Fingerprint Sensor & Blynk IoT

You can also monitor your door lock remotely from anywhere in the world using Blynk IoT mobile App as well as the blynk web dashboard.

IoT and ESP32 based Biometric Door Lock system using Fingerprint R307 Sensor
ESP32 based Biometric Door Lock system using R307 Fingerprint Sensor & Blynk IoT

You can always customize the project according to your needs and requirements.



Conclusion

Congratulations! You have successfully built your own ESP32-based biometric door lock system using the R307 fingerprint sensor and Blynk IoT platform. This project offers an enhanced level of security and convenience for accessing your door. Feel free to customize and expand upon this system to suit your specific requirements.


Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button