OTP Based Door Lock Using Arduino And SIM800L
Introduction
The OTP-Based Door Lock System is designed to enhance the security of doors by implementing a one-time password authentication mechanism. This project utilizes an Arduino Uno microcontroller along with various components such as an I2C 16×2 LCD, relay module, 4×4 keypad, and GSM SIM800L module. The system requires users to enter a unique OTP generated by the Arduino using the keypad, and upon successful authentication, the relay module activates, unlocking the door. Additionally, the GSM module can be employed to send notifications to the authorized user regarding access attempts.
In this article, we will guide you through the process of creating an OTP (One-Time Password) based door lock system using Arduino and various components like I2C 16×2 LCD, relay, 4×4 keypad, and GSM SIM800L module. The system will enhance the security of your doors by requiring a unique password each time someone wants to gain access. Let’s get started!
Components Needed
- Arduino Uno
- I2C 16×2 LCD module
- Relay module
- 4×4 keypad
- GSM SIM800L module
- Jumper wires
- Zero PCB
- 9V power supply
Arduino Uno
Arduino Uno is a popular microcontroller board that is part of the Arduino family. It is widely used in various electronic projects and prototyping due to its simplicity and versatility. Here’s an explanation of the Arduino Uno


- The Arduino Uno is built around the Atmega328P microcontroller. This microcontroller has 32KB of flash memory, 2KB of SRAM, and 1KB of EEPROM. It operates at a clock speed of 16 MHz, providing enough processing power for most projects.
- The Arduino Uno features a total of 14 digital input/output pins, marked as D0 to D13. These pins can be configured as either inputs or outputs, allowing you to connect various sensors, actuators, and other digital devices. Additionally, 6 of these pins (D3, D5, D6, D9, D10, and D11) also support Pulse Width Modulation (PWM), enabling you to generate analog-like outputs.
- The board also includes 6 analog input pins (A0 to A5), which can measure voltage levels ranging from 0 to 5 volts. These pins are useful for interfacing with analog sensors or reading variable inputs.
16×2 LCD Module With I2C
A 16×2 LCD display refers to a liquid crystal display with two rows and 16 characters per row. It is a commonly used alphanumeric display in many electronic projects and devices. The I2C (Inter-Integrated Circuit) interface is a communication protocol that allows for easy and efficient communication between microcontrollers and peripheral devices.
- When an LCD display is connected using the I2C interface, it typically requires fewer pins compared to a direct parallel connection, making it more convenient for projects with limited available pins on the microcontroller.
- I2C Interface: The I2C interface uses a master-slave communication protocol. The microcontroller acts as the master and the LCD display module as the slave. The I2C interface allows for multiple devices to be connected on the same bus, each with a unique address.
- I2C Address: The LCD display module with an I2C interface has a specific address that is set by the manufacturer. This address can usually be found in the documentation or can be identified using an I2C scanner program.
Relay module
A relay module is an integrated circuit board that incorporates a relay and additional components for easy integration into electronic projects. It provides a convenient way to control higher voltage or current loads using a lower voltage signal, such as the output from a microcontroller or Arduino.
The relay itself is the primary component of the module. It consists of an electromagnet and a set of contacts. The contacts can be normally open (NO), normally closed (NC), or both, depending on the relay type. When the coil of the relay is energized, the contacts change their state.
4×4 keypad
A 4×4 keypad, also known as a matrix keypad, is a commonly used input device that provides a convenient interface for entering numerical or alphanumeric data. It consists of a grid of buttons arranged in a 4 by 4 configuration, where each button represents a specific input.
- A 4×4 keypad consists of 16 buttons arranged in a grid of four rows and four columns. Each button is a separate switch that can be pressed or released to generate a specific input. The buttons are usually made of conductive material and have a spring mechanism for tactile feedback.
- The buttons in a 4×4 keypad are connected in a matrix configuration. The rows of buttons (R1 to R4) and columns of buttons (C1 to C4) are connected to the input/output pins of a microcontroller or a keypad scanning circuit. The rows and columns are typically connected using a combination of pull-up or pull-down resistors and GPIO pins.
- To detect which button is pressed, the microcontroller or scanning circuit uses a technique called matrix scanning. It scans the rows and columns of the keypad one by one and determines the active button based on the intersection of the pressed row and column. This allows multiple keys to be read using a limited number of input/output pins.
GSM SIM800L module
GSM SIM800L is a popular module that enables communication over GSM (Global System for Mobile Communications) networks. It provides functionalities for making calls, sending and receiving SMS messages, and connecting to the internet.


- The GSM SIM800L module is designed to work with GSM networks, allowing devices to establish communication through cellular networks. It operates on various frequencies and supports 2G,3G connectivity, making it compatible with most GSM networks worldwide.
- The module requires a power supply of around 3.7 to 4.2 volts. It can be powered using an external power source, such as a battery or a regulated power supply. It is important to ensure a stable power supply to ensure reliable operation.
- The module communicates with other devices, such as microcontrollers or computers, using serial communication. It typically utilizes UART (Universal Asynchronous Receiver-Transmitter) protocol, enabling devices to send and receive commands and data through serial communication.
Circuit Diagram
- Connect the I2C 16×2 LCD module to the Arduino using the SDA(A4) and SCL(A5) pins.
- Connect the relay module to the Arduino’s digital pin 4, which will control the door lock mechanism.
- Connect the 4×4 keypad to the Arduino using digital pins (13,12,11,10,9,8,7,6) for both row and column connections.
- Connect the GSM SIM800L module to the Arduino’s serial pins (3 and 2) and power it using a separate power supply.
- Connect the IR Sensor module to the Arduino’s Analog pins A0.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
//Prateek //wwww.justdoelectronics.in //https://www.youtube.com/c/JustDoElectronics/videos #include <SoftwareSerial.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <Keypad.h> #define relay 4 #define red 16 #define green 15 const byte ROWS = 4; const byte COLS = 4; char hexaKeys[ROWS][COLS] = { { '1', '2', '3', 'A' }, { '4', '5', '6', 'B' }, { '7', '8', '9', 'C' }, { '*', '0', '#', 'D' } }; byte rowPins[ROWS] = { 13, 12, 11, 10 }; byte colPins[COLS] = { 9, 8, 7, 6 }; Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); LiquidCrystal_I2C lcd(0x27, 16, 2); SoftwareSerial sim800l(3, 2); int irsensor = A0; int otp; String otpstring = ""; int i = 0; void setup() { pinMode(irsensor, INPUT_PULLUP); sim800l.begin(4800); Serial.begin(115200); lcd.init(); lcd.backlight(); Serial.print("Welcome to SIM800L Project"); sim800l.println("AT"); updateSerial(); pinMode(relay, OUTPUT); pinMode(red, INPUT); pinMode(green, INPUT); digitalWrite(relay, LOW); delay(500); sim800l.println("AT+CSQ"); updateSerial(); delay(1000); } void updateSerial() { delay(500); while (Serial.available()) { sim800l.write(Serial.read()); } while (sim800l.available()) { Serial.write(sim800l.read()); } } void loop() { lcd.setCursor(0, 0); lcd.print(" OTP Based"); lcd.setCursor(0, 1); lcd.print(" Door Lock"); if (digitalRead(irsensor) == LOW) { otp = random(2000, 9999); otpstring = String(otp); Serial.println(otpstring); while (digitalRead(irsensor) == LOW) {} lcd.clear(); lcd.setCursor(0, 0); lcd.print(" OTP Sent to"); lcd.setCursor(0, 1); lcd.print(" Your Mobile"); Serial.print("OTP is "); delay(100); Serial.println(otpstring); delay(100); SendSMS(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Enter OTP :"); getotp(); } } void getotp() { String y = ""; int a = y.length(); while (a < 4) { char customKey = customKeypad.getKey(); if (customKey) { lcd.setCursor(0, 1); y = y + customKey; lcd.print(y); a = y.length(); } } Serial.print("Entered OTP is "); Serial.println(y); if (otpstring == y) { lcd.setCursor(0, 0); lcd.print("Access Granted"); lcd.setCursor(0, 1); lcd.print("Door Opening"); digitalWrite(relay, HIGH); digitalWrite(red, HIGH); digitalWrite(green, LOW); delay(5000); digitalWrite(relay, LOW); digitalWrite(red, LOW); digitalWrite(green, HIGH); } else { lcd.setCursor(0, 0); lcd.print("Access Failed"); lcd.setCursor(0, 1); lcd.print("Try Again !!!"); delay(3000); } } void SendSMS() { Serial.println("Sending SMS..."); sim800l.print("AT+CMGF=1\r"); delay(100); sim800l.print("AT+CSMP=17,167,0,0\r"); delay(500); sim800l.print("AT+CMGS=\"+91xxxxxxxxxxx\"\r"); delay(500); sim800l.print("Your OTP is " + otpstring + " Just Type OTP And Unlock The Door"); delay(500); sim800l.print((char)26); delay(500); sim800l.println(); Serial.println("Text Sent."); delay(500); } |
Video
Arduino Based Projects
- Smart Bike And Car Starter
- Fingerprint Sensor-Based Biometric Security System
- Rfid And Fingerprint Based Bike And Car Ignition System
- Fingerprint And Alcohol Sensor-Based Bike Ignition System
- Fingerprint And Rfid Based Bike And Car Ignition Systems
- Fingerprint-Based Biometric Voting Machine Project
Conclusion
By following this guide, you have successfully built an OTP-based door lock system using Arduino, an I2C 16×2 LCD, a relay module, a 4×4 keypad, and a GSM SIM800L module. This system provides an additional layer of security to your doors, ensuring that only authorized individuals with the correct OTP can gain access. Feel free to customize and expand upon this project to suit your specific requirements.