0% found this document useful (0 votes)
239 views13 pages

RFID Bluetooth Door Lock

This document describes an RFID and Bluetooth door lock project. It contains instructions on the parts needed, wiring diagram, and Arduino code to operate the lock using RFID tags or Bluetooth. The lock can be unlocked by swiping an authorized RFID tag or sending the correct password via Bluetooth. It uses an Arduino, RFID reader, Bluetooth module, servo motor, buttons, and LCD screen. The Arduino code reads RFID tags, connects to Bluetooth to receive commands, and controls the servo motor to lock and unlock the door.

Uploaded by

Dawit Birhanu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
239 views13 pages

RFID Bluetooth Door Lock

This document describes an RFID and Bluetooth door lock project. It contains instructions on the parts needed, wiring diagram, and Arduino code to operate the lock using RFID tags or Bluetooth. The lock can be unlocked by swiping an authorized RFID tag or sending the correct password via Bluetooth. It uses an Arduino, RFID reader, Bluetooth module, servo motor, buttons, and LCD screen. The Arduino code reads RFID tags, connects to Bluetooth to receive commands, and controls the servo motor to lock and unlock the door.

Uploaded by

Dawit Birhanu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

instructables

RFID and Bluetooth Door Lock

by trekprint

Hi and the arduino code for reading bluetooth, and also


the arduino code for reading the r d' WAS NOT
This is my rst Instructable and my rst arduino created by me. They have been sourced from other
project, I hope you will nd it useful as well. projects in Instructables. I would like to thank 'Taifur'
for the Bluetooth app and code to go with it and
After looking through the projects on Instructables I apologise to the person who created the code for
could only nd either a bluetooth door lock or a r d reading the RFID, as I have forgotten who it was.
door lock, not both so I decided to create one myself.
Though the build is not totally complete I have tested 16 April 2016 - New Arduino code and Fritzing
it out properly and it does work without any diagram uploaded due to changes I have made to the
problems. originals.

I would rst like to make clear that the 'Bluetooth app

Step 1: The Parts Needed

RFID and Bluetooth Door Lock: Page 1


Parts required. 1 - RC522 RFID Reader (Possbly Sintron, can not
remember)
1 - Door Lock with Thumb Turn on the inside of the
door 1 - 16 x 2 - 4 wire LDC screen

1 - Arduino Uno r3 (or compatible) 1 - RGB LED

1 - 360 degree Servo 2 - 220 Resistors

1 - HC-06 Bluetooth Module 1 - Momentary Push Switch (to operate from the
inside to lock/unlock the door)

1 - 10k Resistor ---------------------------------------**

2 - Double Back Boxes (1 approx 45mm depth and the 2 - Double Blanking Plates
other approx 33mm depth)
1 - Length of 12 core alarm cable (length dependant
Jumper Wires on placement)

Power Supply ( I was going to use 2 x 9v batteries, but 2 - 5amp Block Connectors (12 wires each)
have decided to use mains powered 9v supply instead
as more reliable) ** ----------------------------------------------------------------------
-----------**
Screws or strong double sided tape
Andriod Bluetooth Lock App. BTControl.apk
1 - Servo Holder (I designed and printed my own)

** ----------------Waiting for delivery


Download

https://www.instructables.com/ORIG/FF9/N26X/ILSB0MSA/FF9N26XILSB0MSA.apk

Step 2: The Wiring

RFID and Bluetooth Door Lock: Page 2


Po w e r : SDA - Pin A4

9v Regulated Power Supply (or batteries) SCL - Pin A5

RFID Re a de r: M o m e nt a ry Sw it ch:

VCC - Pin 3.3v VCC - 5v (as shown above)

GND - GND GND to 10k resistor (as shown above)

Reset (RST) - Pin D9 Pin 8 arduino (as shown above)

SDA(SS) - Pin D10 RGB LED:

MOSI - Pin D11 Pin D7 to 220 resistor then to LED pin (Red)

MISO - Pin D12 Pin D6 to 220 resistor then to LED pin (Green)

SCK - Pin D13 Common (the long wire) - GND

LCD S cre e n: S e rv o :

VCC - 5v VCC - 5v

GND - GND GND - GND

Signal - Pin D5 TX - D0 (RX)

Blue t o o t h M o dule : RX - D1 (TX)

VCC - 5v Fritzing Diagram:

GND -GND

Step 3: Putting It All Together

RFID and Bluetooth Door Lock: Page 3


The Arduino, Bluetooth Module and Momentary The RFID and LCD Screen ts within the 33mm Back
Switch + RGB Led circuit ts into the 45mm Back Box. I Box with a slot cut out for the LCD Screen to t
have just used Blu-Tac to hold them in place as they through. These will the be wired to the arduino with
will not be moved once xed to the wall. I have the 12 Core Alarm Cable and Block Connector.
soldered the switch, led and resistors to a circuit
board along with creating a GND and VCC For the Servo to connect to the door lock I 3D printed
connections on either side of the circuit board, a Block a holder to be screwed to the door and attached to
Connector will also be placed in for the 12 Core Alarm the door lock.
Cable to connect the RFID and LCD Screen to the
arduino. The lid will get 2 holes drilled in it to
accommodate the switch and led.

RFID and Bluetooth Door Lock: Page 4


RFID and Bluetooth Door Lock: Page 5
Step 4: The Code - (Updated on 12 October 2020) - Also New File Uploaded.

/*
* ----------------------------------------------------------------------------
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
*/

RFID and Bluetooth Door Lock: Page 6


#include <SPI.h>
#include <Servo.h>
#include <MFRC522.h>
#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define RST_PIN 9 // Configurable, see typical pin layout above


#define SS_PIN 10

#define Green_LED 6 //pin for green "door unlocked" indicator LED


#define Red_LED 7 //pin for red "door locked" indicator LED

String inputString = "";


String command = "";
String value = "";
String password = "password"; // this is the password for opening and closing your door by Bluetooth
// you can set any pasword you like using digit and symbols
boolean stringComplete = false;

char array1[]="Swipe To Unlock"; // the string to print on the LCD


char array2[]=" Door Locked ";
char array3[]=" Door Unlocked ";
char array4[]=" Locking ";
char array5[]=" Unlocking ";
char array6[]=" Accepted ";
char array7[]=" Swipe To Lock ";
int tim = 1; //the value of delay time

// initialize the library with the numbers of the interface pins


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

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


Servo myservo;

String read_rfid; // RFID tags ID


String ok_rfid_1="c6ecd82b";
String ok_rfid_2="f5642a50";
String ok_rfid_3="4314622993c81";
// String ok_rfid_4="43ef222993c81";

int addr = 1; // initalise eeprom address


int eVal = 0; // initalise value to be stored in eeprom
int lockPosition; // initialise lockPosition, used to value to sore in eVal
int servo_position;
int BUTTON1 = 8; // initialise the pin input of the lock/unlock button

void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial);
SPI.begin();
mfrc522.PCD_Init();

inputString.reserve(50); // reserve 50 bytes in memory to save for string manipulation


command.reserve(50);
value.reserve(50);
boolean stringOK = false;

{
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
lcd.begin(16,2);
}

// sets pin modes input/output and lights led


pinMode(Green_LED, OUTPUT);
pinMode(Red_LED, OUTPUT);
digitalWrite(Green_LED, LOW);
digitalWrite(Red_LED, HIGH);
pinMode(BUTTON1,INPUT);

myservo.attach(5); // servo pin number

RFID and Bluetooth Door Lock: Page 7


// sets initial locl position
lockPosition = EEPROM.read(1);
// Serial.print(EEPROM.read(1));
if(lockPosition == 1){
digitalWrite(Red_LED, LOW);
digitalWrite(Green_LED, HIGH);
}
else {
digitalWrite(Red_LED, HIGH);
digitalWrite(Green_LED, LOW);
lockUnlock();
}
swipeText();

/*
* Dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
read_rfid="";
for (byte i = 0; i < bufferSize; i++) {
read_rfid=read_rfid + String(buffer[i], HEX);
}
}

void lockUnlock() { // locks or unlocks door

myservo.attach(5);
if(lockPosition == 1) {
lock1();
servo_position = 0;
myservo.write(servo_position);
digitalWrite(Red_LED, HIGH);
digitalWrite(Green_LED, LOW);
delay(2500);
lockPosition = 2;
eVal = lockPosition;
EEPROM.write(1,eVal);
// Serial.print(eVal);

}
else if(lockPosition == 2) {
lock2();
servo_position = 180;
myservo.write(servo_position);
digitalWrite(Red_LED, LOW);
digitalWrite(Green_LED, HIGH);
delay(2500);
lockPosition = 1;
eVal = lockPosition;
EEPROM.write(1,eVal);
// Serial.print(eVal);
}
myservo.detach();
}

void swipeText() // sends text to the lcd screen


{
if(lockPosition == 1){
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
lcd.setCursor(0,0); // set the cursor to column 15, line 0
for (int positionCounter1 = 0; positionCounter1 < 15; positionCounter1++)
{
lcd.print(array3[positionCounter1]); // Print a message to the LCD.
delay(tim); //wait for 250 microseconds
}
lcd.setCursor(0,1); // set the cursor to column 15, line 1
for (int positionCounter = 0; positionCounter < 15; positionCounter++)
{
lcd.print(array7[positionCounter]); // Print a message to the LCD.
delay(tim); //wait for 250 microseconds
}
}
else if(lockPosition == 2){
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
RFID and Bluetooth Door Lock: Page 8
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
lcd.setCursor(0,0); // set the cursor to column 15, line 0
for (int positionCounter1 = 0; positionCounter1 < 15; positionCounter1++)
{
lcd.print(array2[positionCounter1]); // Print a message to the LCD.
delay(tim); //wait for 250 microseconds
}
lcd.setCursor(0,1); // set the cursor to column 15, line 1
for (int positionCounter = 0; positionCounter < 15; positionCounter++)
{
lcd.print(array1[positionCounter]); // Print a message to the LCD.
delay(tim); //wait for 250 microseconds
}
}
}

void lock1() // sends text to the lcd screen locking


{
lcd.clear();
lcd.setCursor(0,0);
for (int positionCounter1 = 0; positionCounter1 < 15; positionCounter1++)
{
lcd.print(array6[positionCounter1]);
delay(tim);
}
lcd.setCursor(0,1);
for (int positionCounter1 = 0; positionCounter1 < 10; positionCounter1++)
{
lcd.print(array4[positionCounter1]);
delay(tim);
}
}

void lock2() // sends text to the lcd screen for unlocking


{
lcd.clear();
lcd.setCursor(0,0);
for (int positionCounter1 = 0; positionCounter1 < 15; positionCounter1++)
{
lcd.print(array6[positionCounter1]);
delay(tim);
}
lcd.setCursor(0,1);
for (int positionCounter1 = 0; positionCounter1 < 12; positionCounter1++)
{
lcd.print(array5[positionCounter1]);
delay(tim);
}
}

void loop() {

// checks for lock/unlock button press


if(digitalRead(BUTTON1) == HIGH){
lockUnlock();
swipeText();
}

// checks if bluetooth has sent a command


// if arduino receive a string termination character like \n stringComplete will set to true
if (stringComplete) {
//Serial.println(inputString);
delay(100);
// identified the posiion of '=' in string and set its index to pos variable
int pos = inputString.indexOf('=');
// value of pos variable > or = 0 means '=' present in received string.
if (pos > -1) {
// substring(start, stop) function cut a specific portion of string from start to stop
// here command will be the portion of received string till '='
// let received string is open=test123
// then command is 'open'
command = inputString.substring(0, pos);
// value will be from after = to newline command
// for the above example value is test123
// we just ignoreing the '=' taking first parameter of substring as 'pos+1'
// we are using '=' as a separator between command and vale
RFID and Bluetooth Door Lock: Page 9
// we are using '=' as a separator between command and vale
// without '=' any other character can be used
// we are using = menas our command or password must not contains any '=', otherwise it will cause error
value = inputString.substring(pos+1, inputString.length()-1); // extract command up to \n exluded
//Serial.println(command);
//Serial.println(value);

// checks password from bluetooth and is correct locks or unlocks the door
// password.compareTo(value) compare between password tring and value string, if match return 0
if(!password.compareTo(value) && (command == "OPEN")){
// if password matched and command is 'OPEN' than door should open
lockUnlock(); // call lockUnlock() function
Serial.println(" OPEN"); // sent open feedback to phone
delay(100);
swipeText();
}
if(!password.compareTo(value) && (command == "CLOSE")){
// if password matched and command is 'CLOSE' than door should close
lockUnlock();
Serial.println(" CLOSE"); // sent " CLOSE" string to the phone
delay(100);
swipeText();
}
if(password.compareTo(value)){
// if password not matched than sent wrong feedback to phone
Serial.println(" WRONG");
delay(100);
swipeText();
}
}
// clear the string for next iteration
inputString = "";
stringComplete = false;
}

// looks for rfid tag to be presented


if ( ! mfrc522.PICC_IsNewCardPresent())
return;

// Select one of the cards


if ( ! mfrc522.PICC_ReadCardSerial())
return;

dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);

// checks if an rfid tags ID matches the stored list, if so it will then lock or unlock the door
Serial.println(read_rfid);
if (read_rfid==ok_rfid_1) {
//ok, open the door.
lockUnlock();
swipeText();
}
//Add below as many "keys" as you want
if (read_rfid==ok_rfid_2) {
//also ok, open the door
lockUnlock();
swipeText();
}
//Add below as many "keys" as you want
if (read_rfid==ok_rfid_3) {
//also ok, open the door
lockUnlock();
swipeText();
}
}

void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
//Serial.write(inChar);
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline or a carriage return, set a flag
// so the main loop can do something about it:
if (inChar == '\n' || inChar == '\r') {

RFID and Bluetooth Door Lock: Page 10


stringComplete = true;
}
}
}

Download

https://www.instructables.com/ORIG/FTO/BRVL/KG6JQOW0/FTOBRVLKG6JQOW0.ino

Step 5:

Hello, I'm tying to make the project for my personal room. I have followed all the instructions as you
guide. But when I insert the code Arduino IDE showing "MFRC522.h: No such file or directory"
massage. Please see the attached picture and help me. Thanks

LCD screen from Amazon. https://www.amazon.co.uk/Youmile-Serial-Module-Shield-


Arduino/dp/B07PWWTB94/ref=sr_1_5?
dchild=1&keywords=16x4+LCD+screen&qid=1601764059&sr=8-5
Hi, I got the lcd and connected as you guided. But now I’m facing a new problem. When I insert the
code,Arduino showing “Redefinition of void setup” please see the attached picture. Please help me
to fix the problem. I’m really excited to complete the project. Waiting for your response. Thanks

Can you please send me a copy of the code you are trying to upload to the arduino. The exactly
the same as you are trying to upload.

Copy code from arduino software to a text file and send that.

Thanks
Hi,
I download your updated code and used directly without any changes. Please see the attached text
file and help me.

Will look at it within the next couple of days. Having to wipe pc, once up and running will let you
know

thanks
Sure. I’ll wait for your reply.
Thanks.
RFID and Bluetooth Door Lock: Page 11
Hello Again

Do you live in the UK. Are you using a Mac or Windows computer. What board are you trying to
upload to.

Hi. I’m from Bangladesh. I’m using Mac. And my board is Arduino uno.
Hi again

I have just tested on my Mac and everything is fine on that.

I have an idea for you to try.

Send me your email address and I will send a link for you to download a zip (compressed) file, this
has the latest Arduino software, the sketch file and all my libraries, plus a text file called
instructions - this outlines what I think will be the best way to sort this out (hopefully).

Download the zip file and un-compress to your desktop, the follow instructions in the text file.

Great..you are awesome. I’m really thankful. Here is my email.


[email protected]
I’ll update you accordingly. Thanks
Email with link has been sent. Good luck.

Nick
Hi Nick,
Hope you’re fine and safe.

Sketch has uploaded without any problem. But below issues are happening..
1) lcd showing nothing (blank)(please see the attached picture)
2) momentary switch not working.( I attached a momentary switch diagram.which I understand
from your diagram. please advise it’s ok or not)
3) RFID tag read perfectly but cannot activate the relay module.
4) Bluetooth module connected with BTcontrol android app. but cannot activate the relay module.
I’m using a 5volt relay module instead of a servo to use solenoid lock. Is there any chance to not
working all the things to using the relay module instead of servo?

Please help me.

Thanks & regard


Tutul

Time in the UK is 17:00 now. Will send link tonight UK time once finished sorting my PC.

Hello again

RFID and Bluetooth Door Lock: Page 12


Do you live in the UK. Are you using a Mac or Windows computer. What board are you trying to
upload to
Hi. I’m from Bangladesh. I’m using Mac. And my board is Arduino uno.

hi

I have tested the code you sent me on my PC and it is fine and uploaded to arduino uno without
problem. wiill test it on my mac to see if it works on that first. if not will figure out why.
Hi

It sounds as if you do not have the MFRC522 Libraries installed, you can get these from "git hub".
Do a search for MFRC522. Also new code has been uploaded, which you can download.
Hello...please help me

Thank you so much. You’re awesome. Another thing, I didn’t Find the lcd screen in market. Can I
run the project without lcd? If yes than what should be the code. Please help.

Thanks once again


I'm trying to build something similar, but I've seen around the internet that you're supposed to use a
voltage divider on the bluetooth chip's RXD out if you want to use the Arduino 5V TXD (pin 1).. But
you didn't run into any problems? (Link to source: https://www.hackster.io/Notthemarsian/take-
control...)
Hi philipfigari
As you can see from my diagram that I have not used a voltage divider on the HC-06 bluetooth
module. I have had no problems wiring it this way, though a voltage divider can make the voltage
more stable.
Below is a diagram showing how to divide the voltage on the TX/RX line.

Another source, suggesting that a voltage divider should be used to prevent damage to bluetooth
module: http://42bots.com/tutorials/how-to-connect-arduino...
Cool!

RFID and Bluetooth Door Lock: Page 13

You might also like