I hope this message finds you well. I am currently working on an exciting project involving the development of a secure safe, which incorporates both Bluetooth communication via HC-05 and fingerprint authentication using the DY50 fingerprint scanner.
Here's a snippet of the relevant code I'm working with:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_Fingerprint.h>
#include <RTClib.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
SoftwareSerial mySerial(2, 3); // RX, TX piny pro čtečku otisků prstů
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
SoftwareSerial BTSerial(10, 11); // RX, TX piny pro komunikaci s HC-05
RTC_DS3231 rtc;
char enteredPIN[5]; // Změna délky pole na 5 pro PIN kód + 1 na konec řetězce
const char correctPIN[] = "1234";
byte pinIndex = 0;
bool accessGranted = false;
bool showDateTime = true;
const int greenLedPin = 4;
const int redLedPin = 5;
const int lockPin = 7;
void setup() {
Wire.begin();
lcd.begin();
lcd.backlight();
rtc.begin();
lcd.print("Setting time...");
//rtc.adjust(DateTime(F(DATE), F(TIME)));
delay(2000);
lcd.clear();
finger.begin(57600);
BTSerial.begin(9600); // Inicializace komunikace s HC-05
pinMode(greenLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
pinMode(lockPin, OUTPUT);
digitalWrite(redLedPin, LOW);
digitalWrite(lockPin, HIGH);
}
void blinkRedLED(int numBlinks, int delayMs) {
for (int i = 0; i < numBlinks; i++) {
digitalWrite(redLedPin, HIGH);
delay(delayMs);
digitalWrite(redLedPin, LOW);
delay(delayMs);
}
}
bool checkPIN() {
for (byte i = 0; i < 4; i++) {
if (enteredPIN[i] != correctPIN[i]) {
return false;
}
}
return true;
}
void loop() {
while (true) { // Neustálé opakování programu
if (BTSerial.available() > 0) {
char command = BTSerial.read();
if (command == 'D') {
showDateTime = false;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("PLACE FINGER....");
}
}
if (!accessGranted) {
if (finger.getImage() == FINGERPRINT_OK) {
if (finger.image2Tz() == FINGERPRINT_OK) {
if (finger.fingerFastSearch() == FINGERPRINT_OK) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" FINGER CORRECT");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" ENTER PIN:");
char key = BTSerial.read();
if (key != -1 && pinIndex < 4) {
if (isDigit(key)) {
enteredPIN[pinIndex] = key;
pinIndex++;
lcd.setCursor(5 + pinIndex - 1, 1);
lcd.print('*');
}
}
if (pinIndex == 4) {
lcd.clear();
lcd.setCursor(0, 0);
if (checkPIN()) {
lcd.print(" PIN CORRECT");
delay(2000);
lcd.clear();
lcd.print(" ACCESS GRANTED");
digitalWrite(greenLedPin, HIGH);
delay(1000);
digitalWrite(greenLedPin, LOW);
digitalWrite(lockPin, LOW);
delay(3000);
digitalWrite(lockPin, HIGH);
accessGranted = true;
showDateTime = true;
pinIndex = 0;
} else {
lcd.print(" WRONG PIN");
blinkRedLED(2, 300);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("PLACE FINGER....");
}
}
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("FINGER INCORRECT");
blinkRedLED(2, 300);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("PLACE FINGER....");
}
}
}
}
if (showDateTime) {
DateTime currentTime = rtc.now();
int year = currentTime.year();
int month = currentTime.month();
int day = currentTime.day();
int hour = currentTime.hour();
int minute = currentTime.minute();
int second = currentTime.second();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Date: ");
lcd.print(day);
lcd.print(".");
lcd.print(month);
lcd.print(".");
lcd.print(year);
lcd.setCursor(0, 1);
lcd.print("Time: ");
if (hour < 10) lcd.print("0");
lcd.print(hour);
lcd.print(":");
if (minute < 10) lcd.print("0");
lcd.print(minute);
lcd.print(":");
if (second < 10) lcd.print("0");
lcd.print(second);
delay(1000);
}
}
}
However, I'm encountering difficulties with the fingerprint scanner functionality. Despite my efforts to troubleshoot and ensure correct wiring, the fingerprint scanner fails to respond or recognize fingerprints.
If anyone has experience with integrating fingerprint scanners, particularly the DY50 model, into Arduino projects or troubleshooting similar issues, I would greatly appreciate any guidance or advice you can offer.
Thank you sincerely for your time and assistance.