Today, mobile-based authentication to verify a person’s identity is common. Online service providers often use it for access to services, approval of transactions, or to change a user’s credentials.
Imagine using a similar mobile-based authentication to enter your home, office, or any private space. It’s possible. In this project, we’ll design a mobile-based access system for access to a private room. This device controls the room’s door using a relay. The door only opens if the one-time password (OTP) sent via a registered mobile number is confirmed.
This device is built using Arduino Mega. It uses an IR sensor and a SIM900 modem to send an SMS containing a random OTP. The user can enter the OTP through a keypad. The system also has an OLED screen attached that serves as the user interface and guides users in accessing the room.
Components required
- Arduino Mega 2560 x1
- SIM900 GSM modem x1
- IR sensors x1
- SSD1306 OLED x1
- Relay/Electronic lock x1
- Connecting or Dupont wires
Circuit connections
To build this device, the SIM900 modem, SSD1306 OLED, IR sensor, 4×4 keypad, and relay or electronic lock are interfaced with Arduino Mega — which offers enough GPIOs to work with all these components.
To interface the SIM900, the modem’s GND, TX, and RX pins are connected to Arduino’s ground, RX1, and TX1 pins. The keypad is connected to Arduino’s GPIO 22, 24, 28, 30, 32, 34, and 36.
The seven-pin SSD1306 OLED module is used and connected to the Arduino as follows.
The IR sensor is connected to Arduino’s GPIO 8. The relay or electronic lock is interfaced at Arduino’s GPIO 50. The device’s circuit connections are shown below.
Arduino sketch
After making the circuit connections, upload the following sketch to Arduino Mega. Remember to replace the registered mobile number you want to receive the OTP in the sketch.
How it works
When the device is plugged in after installation, it initializes the display screen and sends the AT commands to the SIM900 modem to check network strength. The message “OTP-based Door Lock” is displayed on the OLED screen.
When a user is within the vicinity of the authenticated door, an OTP is generated, which is a random number between 1000 and 9999. The OTP is sent to the user’s registered mobile number. The OLED’s interface prompts the user to enter the OTP, which can be entered via the 4×4 keypad on the device.
If the passcode entered by the user is the same as the OTP that was sent to the registered mobile number, access is granted. The relay/electronic lock unlocks the door and keeps it open for ten seconds. Once the relay/electronic lock is operated, the door is locked again.
If the passcode entered by the user does not match the OTP sent to the registered mobile number, access is denied. The microcontroller does not trigger the relay/electronic lock, and the door remains shut.
The code
The code begins by importing the Keypad.h, SPI.h, Wire.h, Adafruit_GFX.h, and Adafruit_SSD1306.h libraries. The Keypad.h library handles input from the 4×4 membrane keypad. The SPI.h, Wire.h, Adafruit_GFX.h, and Adafruit_SSD1306.h libraries work with the SSD1306 OLED. This is followed by a declaration of variables for the OLED module’s pin connections and the related constants.
An object of the Adafruit_SSD1306 class is instantiated to operate the OLED display. The variables for the pin connections and key values of the keypad are defined. An object of the Keypad class is instantiated. The variables defining the pin connections for the relay and IR sensor are declared. The variables to hold the OTP are also declared.
The user-defined function sendATCommand() is used to send the AT commands to the SIM900 modem, connected to Arduino’s UART1 port. The user-defined function printText() is defined to print text on the OLED screen. The user-defined function SendSMS() is defined to send the generated OTP to the user’s registered mobile number. The user-defined function getOTP() is defined to parse the keypad input and match the passcode of the OTP, which was sent to the registered mobile number.
In the setup() function, the baud rate for the serial debug is set to 9600 bps. The display is initialized. The pin connecting the IR sensor is set as the input and the pin connecting relay/electronic lock is set as the output. The baud rate for serial communication with the SIM900 modem is set to 9600 bps. The AT commands are sent to check the network’s strength.
In the loop() function, the text “OTP-based Door Lock” is printed on the OLED screen. If the IR sensor detects the user at the door, the controller generates a four-digit OTP, which is a random number between 1000 and 9999. The display screen indicates that an OTP for granting access has been sent to the registered mobile number. The OTP is sent by calling the SendSMS() function. The OLED screen is updated, prompting the user to enter the passcode sent to their registered mobile number. The OTP is verified by calling the getOTP() function. Access is granted if the user-entered passcode matches the OTP.
You may also like:
Filed Under: Arduino Projects, Electronic Projects, Video
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.