Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Based Smart Door Lock System with GSM and GPS

Image of Arduino-Based Smart Door Lock System with GSM and GPS

Circuit Documentation

Summary of the Circuit

This circuit is designed to function as a door lock system that is operated using a 4x4 membrane matrix keypad. The system features an LCD I2C display for user interaction, a relay module to control the lock mechanism, and a GSM SIM900 module for communication capabilities. Additionally, the circuit includes a GPS module for location tracking. The Arduino UNO serves as the central microcontroller, managing input from the keypad, controlling the LCD display, operating the relay, and handling communication with the GSM module.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P.
  • It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.

LCD I2C Display

  • A 16x2 character LCD display that uses the I2C communication protocol.
  • It is used to display messages to the user, such as prompts and status information.

Relay Module (1 Channel)

  • An electrically operated switch that allows you to control a high power circuit with a low power signal.
  • In this circuit, it is used to control the solenoid lock.

4X4 Membrane Matrix Keypad

  • A 16-button keypad that provides a user interface for entering a password.
  • It is used to input commands and the unlock code.

12V Solenoid Lock

  • An electromechanical lock that is controlled by an electrical signal.
  • It is the actuator that locks or unlocks the door.

9V Battery

  • A standard 9V battery that provides power to the relay module.

GSM SIM900 Module

  • A GSM/GPRS module that can be used for mobile communication.
  • It is used to send SMS messages for notifications.

Wiring Details

Arduino UNO

  • 5V connected to the 5V pins of the LCD I2C Display and Relay Module.
  • GND connected to the GND pins of the LCD I2C Display, Relay Module, and GSM SIM900 Module.
  • Vin connected to the 5V pin of the GSM SIM900 Module.
  • A4 (SDA) connected to the SDA pin of the LCD I2C Display.
  • A5 (SCL) connected to the SCL pin of the LCD I2C Display.
  • Digital Pins (D2-D10) connected to the corresponding pins of the 4X4 Membrane Matrix Keypad and the Relay Module.
  • D0 (RX) and D1 (TX) connected to the GSM SIM900 Module for serial communication.

LCD I2C Display

  • GND connected to the GND of Arduino UNO.
  • VCC connected to the 5V of Arduino UNO.
  • SDA connected to A4 of Arduino UNO.
  • SCL connected to A5 of Arduino UNO.

Relay Module (1 Channel)

  • S connected to D10 of Arduino UNO.
  • 5V connected to 5V of Arduino UNO.
  • GND connected to GND of Arduino UNO.
  • COM connected to the "+" of the 9V Battery.
  • NO connected to the VCC of the 12V Solenoid Lock.

4X4 Membrane Matrix Keypad

  • R1-R4 connected to D9-D6 of Arduino UNO, respectively.
  • C1-C4 connected to D5-D2 of Arduino UNO, respectively.

12V Solenoid Lock

  • VCC connected to the NO of the Relay Module.
  • GND connected to the "-" of the 9V Battery.

GSM SIM900 Module

  • GND connected to GND of Arduino UNO.
  • 5V connected to Vin of Arduino UNO.
  • D0 (RX) and D1 (TX) connected to D1 (TX) and D0 (RX) of Arduino UNO, respectively.

Documented Code

/*
 * Door Lock System using 4x4 Keypad, LCD, Relay, GPS, and GSM
 * This code reads input from a 4x4 keypad, displays it on an LCD using I2C,
 * checks if the entered code matches a predefined password to
 * unlock the door by activating a relay, reads GPS data, and sends an SMS.
 * Password: 1234
 */

#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

// Keypad setup
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; // Connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; // Connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 line display

// Relay setup
const int relayPin = 10; // Pin connected to the relay
String password = "1234";
String input = "";
unsigned long lastInteraction = 0;
const unsigned long timeout = 3000; // 3 seconds timeout for feedback

// GPS module setup
SoftwareSerial gpsSerial(4, 3); // RX, TX
TinyGPSPlus gps;

// GSM module setup
SoftwareSerial gsmSerial(7, 8); // RX, TX for GSM module

void setup() {
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW); // Ensure relay is off initially
  lcd.begin(16,2);
  lcd.backlight();
  lcd.print("Enter Password:");
  
  // Initialize GPS module
  gpsSerial.begin(9600);
  
  // Initialize GSM module
  gsmSerial.begin(9600);
  delay(1000); // Give time for GSM module to initialize
  gsmSerial.println("AT"); // Check if the module is ready
  delay(1000);
  gsmSerial.println("AT+CMGF=1"); // Set SMS mode to text
  delay(1000);
}

void loop() {
  char key = keypad.getKey();
  if (key) {
    lastInteraction = millis();
    if (key == '#') {
      if (input == password) {
        lcd.clear();
        lcd.print("Access Granted");
        digitalWrite(relayPin, HIGH); // Activate relay
        delay(5000); // Keep relay on for 5 seconds
        digitalWrite(relayPin, LOW); // Deactivate relay
        sendSMS(); // Send SMS notification
      } else {
        lcd.clear();
        lcd.print("Access Denied");
      }
      input = "";
    } else if (key == '*') {
      input = "";
      lcd.clear();
      lcd.print("Enter Password:");
    } else {
      input += key;
      lcd.setCursor(0, 1);
      lcd.print(input);
    }
  }
  if (millis() - lastInteraction > timeout && input != "") {
    lcd.clear();
    lcd.print("Enter Password:");
    input = "";
  }

  // Read GPS data
  while (gpsSerial.available() > 0) {
    gps.encode(gpsSerial.read());
  }

  if (gps.location.isUpdated()) {
    lcd.setCursor(0, 1);
    lcd.print("Lat: ");
    lcd.print(gps.location.lat(), 6);
    lcd.setCursor(0, 2);
    lcd.print("Lng: ");
    lcd.print(gps.location.lng(), 6);
  }
}

void sendSMS() {
  String message = "Access Granted. GPS Location: ";
  message += "Lat: ";
  message += String(gps.location.lat(), 6);
  message += ", Lng: ";
  message += String(gps.location.lng(), 6);

  gsmSerial.println("AT+CMGS=\"+1234567890\""); // Replace with your phone number
  delay(1000);
  gsmSerial.println(message);
  delay(100);
  gsmSerial.write(26); // ASCII code for CTRL+Z to send the SMS
  delay(1000);
}

This code is responsible for the operation of the door lock system. It initializes the keypad, LCD, relay, GPS, and GSM modules, and contains the main program loop that handles user input, password verification, relay control, GPS data reading, and SMS sending. The password is hardcoded as "1234", and upon successful entry, the relay is activated, the door is unlocked, and an SMS with the GPS location is sent.