SMART HOME LOCK USING RFID AND OTP USING BHARAT PI

by c2ashwanikumar in Circuits > Arduino

238 Views, 2 Favorites, 0 Comments

SMART HOME LOCK USING RFID AND OTP USING BHARAT PI

WhatsApp Image 2023-09-23 at 10.59.40 PM.jpeg
WhatsApp Image 2023-09-19 at 9.26.34 PM.jpeg
WhatsApp Image 2023-09-23 at 10.59.43 PM.jpeg
WhatsApp Image 2023-09-23 at 11.13.25 PM.jpeg

In our ever-advancing world, we’re witnessing the transformation of the humble front door into a smart and secure portal. These Smart Door Locks, whether using RFID cards or OTP (One-Time Passwords), redefine home security. RFID card systems provide convenience with a simple swipe or tap, while OTP codes bolster security by allowing single-use access. These technologies enable remote control, entry monitoring, and integration with your smart home setup. Whether opting for RFID or OTP, these innovations are redefining home security, making your door not just an entrance but a dynamic and intelligent guardian of your home

Downloads

Supplies

WhatsApp Image 2023-09-23 at 11.21.54 PM.jpeg
download (1).jpg
download (5).jpg
download (4).jpg
download (3).jpg
download (2).jpg
  1. Bharat Pi (board)
  2. Servo Motor
  3. RFID Reader
  4. LEDS
  5. Jumper wires
  6. Buzzer Module

FEATURES

Step 1: FEATURES

  1. Dual Authentication: This smart lock combines two layers of security, utilizing RFID card access and OTP codes, ensuring enhanced protection for your home.
  2. RFID Convenience: The RFID card functionality offers a hassle-free way to enter your home. Simply swipe or tap the card for quick access, perfect for daily use.
  3. OTP for Added Security: One-Time Passwords (OTPs) provide an extra level of security. These unique, time-sensitive codes are ideal for situations where you need heightened protection.
  4. Auto-Locking: Some models offer auto-locking features, ensuring your door is securely locked behind you, providing peace of mind.
  5. Customized Access : Assign different access permissions to various users. For instance, family members might have full access, while guests receive limited access for a specifc duration.


COMPONENTS EXPLAINATION

download (5).jpg
download (4).jpg
download (3).jpg
download (2).jpg
download (1).jpg
WhatsApp Image 2023-09-23 at 11.21.54 PM.jpeg

Step 2: COMPONENTS EXPLAINATION

BHARAT PI (BOARD):we’re using the Bharat Pi, a handy device that combines an ESP32 microcontroller with a SimCom A7672S 4G/LTE module. It’s like a smart gadget for people who want to create things. Whether you’re a student, innovator, startup, or developer, Bharat Pi is perfect for making quick prototypes. It’s designed to be super easy to use and &ts with all sorts of programs and accessories, just like those for Arduino and ESP32. You can use it to connect wirelessly, either with WiFi or a Sim card for 4G/LTE. Plus, it’s tough and reliable, suitable for both testing ideas and even using it in real-life projects.

SERVO MOTOR : A servo motor is like a little helper that can turn and move things very precisely. It’s often used in machines, toys, and even doors to make them go exactly where you want. It’s a bit like a robot arm that can follow your instructions, making it great for tasks that need careful control, like opening and closing doors, steering remote-control cars, or moving things with great accuracy.

RFID READER : An RFID reader is like a special device that talks to two types of cards: “access cards” and “denied cards.” The “access card” works like a magic key when it’s near the reader, it opens doors. In contrast, the “denied card” is like a superhero shield; when it’s used with the reader, it says, “No entry,” and the door stays locked. Essentially, the RFID reader decides who can come in, making it a valuable tool for controlling access and ensuring security.

LEDS : LEDs (Light-Emitting Diodes) are small, energy-efficient lights that glow when electricity Fows through them. They come in different colors and are used in devices like phones, TVs, and as energy-saving bulbs in homes

JUMPER WIRES AND BUZZER MODULE : Jumper wires are like Fexible electric strings used in electronics projects to connect different components. They make it easy to link things like sensors and LEDs on a breadboard.A buzzer module is a small sound-producing device that beeps or buzzes when you send it an electrical signal. It’s often used in projects to create sound alerts or alarms and can make different tones depending on the signal it receives.

BUZZER: A buzzer or beeper is an audio signaling device, which may be mechanical, electromechanical, or piezoelectric (piezo for short). Typical uses of buzzers and beepers include alarm devices, timers, train and confirmation of user input such as a mouse click or keystroke.

CIRCUIT AND CONNECTION

WhatsApp Image 2023-09-23 at 11.21.54 PM.jpeg
WhatsApp Image 2023-09-23 at 11.13.25 PM.jpeg

Step 3: CIRCUIT AND CONNECTION

1.Connect the RFID SS pin to the (29) GPIO5 Digital I/O pin on the Bharat Pi board.

2. Connect the RFID SCK pin to the (30) GPIO18 Digital I/O pin on the Bharat Pi board.

3. Connect the RFID MOSI pin to the (37) GPIO23 Digital I/O pin on the Bharat Pi board.

4. Connect the RFID MISO pin to the (31) GPIO19 Digital I/O pin on the Bharat Pi board.

5. Connect the RFID RST pin to the (11) GPIO27 Digital I/O pin on the Bharat Pi board.

6. Connect the RFID GND (ground) pin to the GND pin on the Bharat Pi board.

7. Connect the RFID VCC (power) pin to the 3.3V pin on the Bharat Pi board.

8. Connect the Servo Motor VCC (power) pin to the 5V pin on the Bharat Pi board.

9. Connect the Servo Motor GND (ground) pin to the GND pin on the Bharat Pi board.

10. Connect the Servo Motor Signal pin to a Digital I/O pin on the Bharat Pi board, such as pin 33.

11. Connect the longer leg (anode) of the GREEN LED to a Digital I/O pin on the Bharat Pi board, such as pin 13.

12. Connect the longer leg (anode) of the RED LED to a Digital I/O pin on the Bharat Pi board, such as pin 15.

13. Connect the shorter leg (cathode) of the GREEN LED and RED LED to the GND pin on the Bharat Pi board.

14. Connect the positive terminal of the Buzzer to a Digital I/O pin on the Bharat Pi board, such as pin 2.

15. Connect the negative terminal of the Buzzer to the GND pin on the Bharat Pi board.

CODE

#include <Arduino.h>

#include <ESP32Servo.h>

#include <SPI.h>

#include <MFRC522.h>

#define SS_PIN SDA

#define RST_PIN 27

#define LED_G 13 // Green LED pin

#define LED_R 15 // Red LED pin

#define BUZZER 2 // Buzzer pin

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

Servo myServo; // Define servo name

int generatedOTP = 0;

int greenLEDPin = 13;

int redLEDPin = 15;

int buzzerPin = 2;

int tries = 0;

void setup() {

Serial.begin(115200);

randomSeed(analogRead(0)); // Initialize random number generator

pinMode(greenLEDPin, OUTPUT);

pinMode(redLEDPin, OUTPUT);

pinMode(buzzerPin, OUTPUT);

myServo.attach(33); // Attaches the servo on pin 33

SPI.begin(); // Initialize SPI bus

mfrc522.PCD_Init(); // Initialize MFRC522

pinMode(LED_G, OUTPUT);

pinMode(LED_R, OUTPUT);

pinMode(BUZZER, OUTPUT);

noTone(BUZZER);

Serial.println(“Put your card to the reader…”);

Serial.println();

generateOTP(); // Generate the initial OTP

}

void loop() {

// Look for new cards

if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {

// Show UID on serial monitor

Serial.print(“UID tag: “);

String content = “”;

for (byte i = 0; i < mfrc522.uid.size; i++) {

Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? “ 0” : “ “);

Serial.print(mfrc522.uid.uidByte[i], HEX);

content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? “ 0” : “ “));

content.concat(String(mfrc522.uid.uidByte[i], HEX));

}

Serial.println();

Serial.print(“Message: “);

content.toUpperCase();

// Check if the RFID card is authorized

if (content.substring(1) == “96 2C 71 06”) { // Change the UID of the authorized card

Serial.println(“Authorized access”);

Serial.println();

delay(500);

digitalWrite(LED_G, HIGH);

tone(BUZZER, 500);

delay(300);

noTone(BUZZER);

myServo.write(180);

delay(5000);

myServo.write(0);

digitalWrite(LED_G, LOW);

} else {

Serial.println(“Access denied”);

digitalWrite(LED_R, HIGH);

tone(BUZZER, 300);

delay(1000);

digitalWrite(LED_R, LOW);

noTone(BUZZER);

}

// Clear the UID read

mfrc522.PICC_HaltA();

}

// Print the generated OTP to the Serial Monitor

Serial.println(“Generated OTP: “ + String(generatedOTP));

// Wait for user input

Serial.println(“Enter OTP:”);

while (!Serial.available()) {

// Wait for user input

}

// Read user input

String userOTPString = Serial.readString();

int userOTP = userOTPString.toInt();

// Verify OTP

if (userOTP == generatedOTP) {

Serial.println(“OTP Verified!”);

// Rotate the servo to 180 degrees

myServo.write(180);

digitalWrite(greenLEDPin, HIGH);

delay(5000); // Wait for 5 seconds

// Return the servo to the initial position (e.g., 0 degrees)

myServo.write(0);

// Blink green LED

digitalWrite(greenLEDPin, LOW);

digitalWrite(redLEDPin, HIGH);

// Generate a new OTP

generateOTP();

} else {

Serial.println(“OTP Verification Failed. Try Again.”);

// Beep the buzzer when access is denied

digitalWrite(greenLEDPin, LOW);

delay(500);

digitalWrite(redLEDPin, HIGH);

digitalWrite(buzzerPin, HIGH);

delay(500);

digitalWrite(buzzerPin, LOW);

digitalWrite(redLEDPin, LOW);

tries++;

// Beep for a longer duration when access is denied after 3 tries

if (tries == 3) {

Serial.println(“OTP invalid”);

digitalWrite(redLEDPin, HIGH);

digitalWrite(buzzerPin, HIGH);

delay(1000);

digitalWrite(buzzerPin, LOW);

digitalWrite(redLEDPin, LOW);

}

}

}

void generateOTP() {

// Generate a new 6-digit OTP

generatedOTP = 0;

for (int i = 0; i < 6; i++) {

generatedOTP = generatedOTP * 10 + random(0, 10); // Generate a random digit between 0 and 9

}

}

Downloads

WORKING

Smart Home Lock Using OTP and RFID
Smart Home Lock Using OTP and RFID

In the smart home lock they having two distinct authentication methods: RFID card detection and OTP generation. For RFID authentication, when the user presses the lowercase letter ‘a,’ in the serial monitor the system initiates RFID card detection. Upon placing an RFID access card on the RFID reader, the system responds by activating a servo motor, causing it to rotate 180 degrees, and illuminating a Green LED as an indicator of successful card detection. After a brief 5- second pause, the servo motor returns to its initial position at 0 degrees. In cases where an unauthorized RFID card is presented, the system denies access by keeping the servo motor stationary and turning on a Red LED. On the other hand, for OTP authentication, the user initiates the process by pressing the capital letter ‘A,’ in the serial monitor and the system to generate a random one-time password (OTP) displayed on the serial monitor. To gain access, the user must accurately input the displayed OTP. If they succeed, a Green LED is activated, and the servo motor rotates 180 degrees before returning to 0 degrees after a 5-second delay. However, if the user inputs an incorrect OTP, the system displays an OTP verification failure message and activates the Red LED to signify denied access.