RFID Bluetooth Door Lock
RFID Bluetooth Door Lock
by trekprint
1 - HC-06 Bluetooth Module 1 - Momentary Push Switch (to operate from the
inside to lock/unlock the door)
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)
https://www.instructables.com/ORIG/FF9/N26X/ILSB0MSA/FF9N26XILSB0MSA.apk
RFID Re a de r: M o m e nt a ry Sw it ch:
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)
LCD S cre e n: S e rv o :
VCC - 5v VCC - 5v
GND -GND
/*
* ----------------------------------------------------------------------------
* 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
*
*/
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial);
SPI.begin();
mfrc522.PCD_Init();
{
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
lcd.begin(16,2);
}
/*
* 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);
}
}
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 loop() {
// 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;
}
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') {
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
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
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.
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?
Time in the UK is 17:00 now. Will send link tonight UK time once finished sorting my PC.
Hello again
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.
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!