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.
/*
* 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.