The project is about a smart solenoid door lock that open with password or fingerprint sensor, and there is an LCD screen that shows the login status, besides if there 3 unsuccessful attempts an sms message send
I wrote this code but unfortunatly it doesn't work
Can any body help me
I am using Arduino Uno
This is the code:
#include <SoftwareSerial.h>
#include <Adafruit_Fingerprint.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
#define FINGERPRINT_RX 0
#define FINGERPRINT_TX 1
#define GSM_RX 2
#define GSM_TX 3
#define Relay_Pin 5
#define MAX_ATTEMPTS 3
SoftwareSerial gsmSerial(GSM_RX, GSM_TX);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial);
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {6,7,8,9};
byte colPins[COLS] = {10,11,12,13};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2);
int attempts = 0;
void setup() {
Serial.begin(9600);
gsmSerial.begin(9600);
finger.begin(57600);
pinMode(Relay_Pin, OUTPUT);
lcd.init();
lcd.backlight();
lcd.print("Enter your fingerprint");
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
lcd.clear();
lcd.print("Enter password");
delay(1000);
char password[4];
for (int i = 0; i < 4; i++) {
password[i] = keypad.getKey();
lcd.setCursor(i, 1);
lcd.print("*");
delay(500);
}
if (checkPassword(password)) {
unlockDoor();
lcd.clear();
lcd.print("Access granted");
delay(5000);
lcd.clear();
lcd.print("Enter fingerprint");
attempts = 0;
} else {
attempts++;
lcd.clear();
lcd.print("Access denied");
delay(5000);
lcd.clear();
lcd.print("Enter fingerprint");
if (attempts == MAX_ATTEMPTS) {
sendNotification();
attempts = 0;
}
}
}
if (finger.getImage() == FINGERPRINT_OK) {
int id = finger.fingerFastSearch();
if (id == -1) {
lcd.clear();
lcd.print("Access denied");
delay(5000);
lcd.clear();
lcd.print("Enter fingerprint");
attempts++;
if (attempts == MAX_ATTEMPTS) {
sendNotification();
attempts = 0;
}
} else {
unlockDoor();
lcd.clear();
lcd.print("Access granted");
delay(5000);
lcd.clear();
lcd.print("Enter fingerprint");
attempts = 0;
}
}
}
bool checkPassword(char* password) {
// Check if the password is valid
// Return true if the password is valid, false otherwise
char correctPassword[4] = {'1', '2', '3', '4'}; // Change this to the correct password
for (int i = 0; i < 4; i++) {
if (password[i] != correctPassword[i]) {
return false;
}
}
return true;
}
void unlockDoor() {
digitalWrite(Relay_Pin, HIGH);
delay(5000);
digitalWrite(Relay_Pin, LOW);
}
void sendNotification() {
gsmSerial.println("AT+CMGF=1");
delay(1000);
gsmSerial.println("AT+CMGS=\"+966508637808\"");
delay(1000);
gsmSerial.println("Unauthorized access detected!");
delay(1000);
gsmSerial.write(0x1A);
}