Arduino Solenoid Door lock system using fingerprint and keypad and LCD-I2C besides using GSM (Sim800L)

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);
}

you have 2 devices but trying to activate three Serials

what happen if keys not pressed quick enough ?
what happen if keys is pressed while delay() is active?

Can you edit the code to do the wanted function, i am new at programming so you will find many mistakes.

show schematic

1 Like

really ? you wrote it?

Ok i will do it and send it

Yes, with the help of AI

ah, well, it is explain many things
f.e. :

if someone interested my thoughts about ChatGPT sketches:
ChatGPT is not responsible for its results so you must be clever then it to find it's errors, but if you are so clever - you do not need ChatGPT at all. using of ChatGPT is like declaring self to incompetent/incapable. but if you consider yourself to be such, then it may be better to spend your life on something more attractive.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.