Introduction: Easy Bluetooth Enabled Door Lock With Arduino + Android

Picture of Easy Bluetooth Enabled Door Lock With Arduino + Android
Thanks to everyone who supported this project and voted for it in the Arduino Challenge! I was awarded second prize and hope to participate in more Arduino contests in the near future.

This tutorial will explain a simple way to make a password protected bluetooth door lock using your Arduino, which can be unlocked by sending a four digit pin from your Android phone!  The hardware setup is quite simple,  and the programming side of it is a bit tricky, but should be no problem for any Arduino ameuture.

Step 1: Parts Needed

Picture of Parts Needed

1. Arduino (I am using the Duemilanove)

2. Electric Door Strike

3. Bluetooth Module ($9.99)

4. Power Supply (Required voltage and amperage differs among different door strikes/locks)

5. TIP120 Transistor

6. 1N4001 Diode

7. Hookup Wire

8. Solderless Breadboard

9. An Android phone (optional, considering that there are lots of devices you could use to send serial data to our bluetooth modem including Iphones, computers, and other Bluetooth devices)

Step 2: About the Transistor

Picture of About the Transistor

We'll start by focusing on one of the main components of the circuit, the transistor. Our transistor will allow us to control a device that requires more current than our Arduino can supply, by sending the transistor different values. The type of transistor we are using (the TIP120) has a base, collector, and an emitter which are labeled here. We will send the signal from pin 9 on the Arduino to the base of the transistor, and depending on the value sent, current will increase or decrease.

Step 3: Assemble the Circuit

Picture of Assemble the Circuit

The diagram shows how the transistor is wired up in our circuit. As you can see, we have a diode pointed away from ground that is connected to the collector of the transistor as well as the ground of the lock itself. This diode will protect our electronics from any back voltage that might be created when our lock is turned off. At this point you could set pin 9 to high or low to control the lock.

Step 4: Adding Bluetooth

Picture of Adding Bluetooth

Adding a Bluetooth module to our project is very easy. Simply connect RX on the Bluetooth module to TX on our Arduino board, TX on the module is then connected to RX on the Arduino, GND is obviously connected to ground, and lastly VCC is connected to 3.3 volts or 5 volts depending on your Bluetooth module.

Step 5: Final Product (without the Code)

Picture of Final Product (without the Code)

Here is a look at what everything should look like. Its a bit difficult to see everything, but this is just the completed circuit on the breadboard.

Step 6: The Code

The coding is a little tricky as I said in the intro, but I am a bit of a beginner with the Arduino so it should not be difficult for anyone to understand. Basically the Arduino will check to see if anything is being received through serial. If it is, it will read those chars into an array and from that point verify that what was received matches the password we defined. In my example the password defined is ABCD.



int lock = 9;          //pin 9 on Arduino
char final[4];         //Characters the Arduino will receive
char correct[4] = {'A','B','C','D'};    //User-Defined Password
int pass_correct = 0;          //Does Password match, 0=false 1=true

void setup()
{
pinMode(lock, OUTPUT);
Serial.begin(9600);
digitalWrite(lock, HIGH); 
//By default, lock is active(locked)
}

void loop()
{
while(Serial.available()) 
{
  for(int i=0; i<4; i++)   
//While data is available read 4 bytes
  {
   final[i] = Serial.read(); 
//Read 4 bytes into the array labled "final"
  }

  for(int i=0; i<4; i++)
  {
   if(final[i]==correct[i])
//Compare each char received to each car in our password in order
   {
    pass_correct = 1;  
//If we compare two chars and they match, set the pass_correct variable to true(1)
   }
   else
   {
    pass_correct = 0; 
//if the two compared chars do NOT match, set pass_correct variable to false(0)
    break;   //End loop and stop comparing chars
   }
  }
}

if(pass_correct==1) 
//If all chars compared match, deactivate(unlock) the lock for 5 seconds
{
  Serial.println("Unlocked");
  digitalWrite(lock, LOW);
  delay(5000);
  Serial.println("Locked");
  pass_correct = 0;
}
else
{
digitalWrite(lock, HIGH);
//Else if there was not a complete match, keep the lock high(locked)
}

/* FOR TESTING
Serial.print(final[0]);Serial.print(final[1]);Serial.print(final[2]);Serial.print(final[3]);
Serial.print(" | ");
Serial.print(correct[0]);Serial.print(correct[1]);Serial.print(correct[2]);Serial.print(correct[3]);
Serial.print(" ");
Serial.print(pass_correct);
Serial.println("");
*/
delay(500);


}

Step 7: Implementing Your Android Phone

Picture of Implementing Your Android Phone

On the app market, you can search for Bluetooth SPP (Serial Port Profile). There are many apps that have been made to send serial data through Bluetooth on your phone. Mine is called Bluetooth SPP just like 4 or 5 other apps that are similar and can be found by going to the link below. After you install one of these Bluetooth SPP apps, you can pair with your bluetooth modem connected to the Arduino. If it asks for a key, it will usually be by default "1234" (without quotes of course). After that, you should beable to send ABCD and the door strike will unlock for around 5 and 1/2 seconds, and then lock itself again. This concludes my tutorial on making a Bluetooth enabled door lock. If you have any questions or corrections for my project let me know!

(Recommended) Bluetooth SPP App: https://play.google.com/store/apps/details?id=mobi.dzs.android.BluetoothSPP&feature=search_result#?t=W251bGwsMSwyLDEsIm1vYmkuZHpzLmFuZHJvaWQuQmx1ZXRvb3RoU1BQIl0.

Comments

CempronF (author)2017-11-29

it is arduino programming

SethE16 (author)2017-07-19

Anyone know what is powering the Arduino itself? Is that power also coming from the power supply of 12V? Would that just go into the Vin? Just confused what is powering the arduino it appears as though the 12V is just powering the lock. Thanks.

AngelicaP20 (author)2017-06-04

hello. i just want to ask, what programming language did you use in coding? thank you. i will use your article as reference for my thesis.

it is c language

jibays (author)2017-06-04

is there any available full video tutorial of this project?

thank you :)

dugle (author)2017-03-24

i took this for gratuation project, so can i get the schematic diagram of this

please i am patient, contact me dugle888@gmail.com

VinleeC (author)2017-02-15

i wanted to change to arduino uno is that's possible

SanjjievR (author)2016-12-21

i want to like this but im using gsm module not bluethooth module..so i need coding for gsm module

GullP made it! (author)2016-12-15

i have made this project . all is fine . but the issue is my door lock is not working . connections are perfect accordingly , code is running, but only lock is not working accordingly ,. here are the screen shots off all the progress . plz guide me through why my lock is not working?

SabriM made it! (author)2014-12-14

Hello guys. I made it as a part of my graduation project. I am building android application too.The logic of the circuit in pics is %98 same with this one. My android application is ready too. I will upload it in few weeks.Images are HD. You can see the circuit clearly. Thanks Collin Amedee. But I changed Arduino code to this one in the link : http://english.cxem.net/arduino/arduino5.php

VishnukumarN (author)SabriM2016-11-23

HI Sabri. can you post the making video of the entire setup. i am trying to do the same project but i dont know where I went wrong. please help me

BenP74 (author)SabriM2016-09-22

Thanks!!!

IZwadieA (author)SabriM2015-08-22

Hello SabriM.

I would like to ask about the output device..can i use electromagnetic door lock instead of electric door strike??

SabriM (author)IZwadieA2015-09-03

Hello IZwadieA,

I just control electric from code. There are two controls about it. Deactive electric from door lock to lock and activate the electric to activate door lock. If your device support this of cource you can.

Mary JaneV (author)SabriM2016-02-22

SabriM can you send be the full input and output of this? thanks kennent_rod@yahoo.com

SabriM (author)Mary JaneV2016-02-23

Hi,

check the video below Mary.

IZwadieA (author)SabriM2015-09-17

Hi SabriM,

It really work now.I have complete the connection.Thank you very much for your advice I really appreciate it.By the way,is it possible to trace someone that using the same bluetooth connection like checking the history of user??

SabriM (author)IZwadieA2015-09-29

hello IZwadieA,

I didn't make that log system. There is no database in my application. But if you wish sure you can add log system in your android application.

MirulZ (author)SabriM2015-10-06

can u give me the operation for this circuit ?

Collin Amedee (author)SabriM2015-05-18

Hello SabriM,

I very much appreciate you building onto this project, and especially answering questions whilst I have been inactive over the past several months! I do hope that you received a good grade on your project!

Thanks, and good luck!

SabriM (author)Collin Amedee2015-09-29

Thanks Collin Amedee :)

Expecting a lot of instructions from you.

Mark ReginaldL (author)SabriM2015-09-19

can i use Arduino Uno R3?

SabriM (author)Mark ReginaldL2015-09-29

Sure you can. Its a simple hardwire connection.

HaziqS (author)SabriM2015-09-02

Hi is this possible to use WIFI + bluetooth to unlock the multiple door ? and if yes what changes ive to made??

SabriM (author)HaziqS2015-09-03

Hi HaziqS,

Sure you can. But you just need to use multiple cable to connect all of them into one source.

HaziqS (author)SabriM2015-09-13

ok !! but how i mean ho ill connect bluetooth aswell as wifi cux for serialized communicate it jus have one RX and TX

bigworld21 (author)SabriM2015-05-06

hi sir sabri, hmm i m interested with this project,may i see ur full circuit,n ur android apk for control the lock .. pls mail me wellsinclair@gmail.com

SabriM (author)bigworld212015-09-03

Hi the circuit is just above and developed from this project.

You can download the app from the link below in Play Store :

https://play.google.com/store/apps/details?id=sabr...

And Dowload Arduino code from :

https://www.dropbox.com/s/a82sect5ng11nqf/control....

nobodykid (author)SabriM2015-03-24

hi i'd like to ask about the bluetooth modules. if i'm using different modules, will the codes changes too? if so, which one is likely to be changed, the Arduino or the one in phone? thanks

SabriM (author)nobodykid2015-03-24

No I don't think that will change anything. I used HC 06 but you can use HC 05 too.

SabriM (author)nobodykid2015-03-25

The code is not about Bluetooth module. It doesn't effect it. You can use it. Differences between Bluetooth modules is about their security.

amâdnêŝŝ1 (author)SabriM2015-03-03

hi . i want to add this project to my graduation project "advanced easy home security systems"
so can u please send me all the details of this project to this email seda4unit@gmail.com

SabriM (author)amâdnêŝŝ12015-03-14

This is the link of my Term project : Language is Turkish but you can get some details from video. I will try to add English subtitle.

buttercupme (author)2016-09-25

can use arduino uno instead of duemilanove?

BenP74 (author)2016-09-22

Great job! Would it be possible to show a more detailed birds-eye view of the breadboard layout? Thanks!

Naviddya Batra (author)2016-09-14

Respected sir,
I wan a circuit of that. Plzzz
Resply as soon as possible

shakeel-avenir (author)2016-07-26

Hey SAbri! you're project work is awesome dude! Keep the good work doing...

I Need your Help! I am unable to find Electric Door Strike.

I would
like to know instead of Electric Door Strike what can I use as an
alternative... So, Please kindly let me know as soon as possible.

Can I make a circuit using solenoid?

Thanks in advance.

shakeel-avenir (author)2016-07-26

Hello! Friend! Need Help! I am unable to find Electric Door Strike.

I would like to know instead of Electric Door Strike what can I use as an alternative... So, Please kindly let me know as soon as possible.

Thanks in advance.

Regards,

Mohammad Shakeel Ahmed.

Research Engineer, Avenir Labs.

SAURABHC18 (author)2016-06-06

Please contact me at ersaurabh101@gmail.com or 9216142737 , I need to discuss a paid project with you, regarding the above sample project.

Nazmul_Milon (author)2016-05-22

I want to make it in a different way.please anybody suggest me,when i come back in my room, it is self unlock the door lock, use arduino & hc 05,my buetooth run at command mode ,at first collect the last pair buletooth mac and it is compair with +inq mac address ,if my phone mac is available then unlock the door automaticly .

Kishor_inov_IND (author)2016-05-14

can u spesify the lock name please

SaravananF (author)2016-03-25

Hi,any one give circuit diagram for this project

MuhammadH137 (author)2016-03-10

appreciable work for beginners

all4alex (author)2015-12-13

can i ask ? i want to make the same concept about this experiment for my project in school, but i want to use servo motor and a normal door lock instead of electric door lock because I cannot afford it ? it will work right? pls answer ASAP :)

МаркоГ (author)2015-11-02

Can you please post the schematic, i am having a hard time figuring out connections through a photo. Thx

RejA1 (author)2015-10-18

Hi. I have an HC 05 bluetooth shield instead of just the HC05 itself. I followed the steps exactly except I just mounted the bluetooth shield onto the arduino uno rather than manually connecting them pin-to-pin. Also, I altered the code according to the logci of my project, which is a simple on/off motor control. It doesnt work. Can anyone help me?

My device can pair with the HC05, but when I send the password via the bluetooth spp, the motor doesn't turn on.

RejA1 (author)RejA12015-10-18

Here's the modified code

int motor = 9; //pin 9 on Arduino

char final[4]; //Characters the Arduino will receive

char correct[4] = {'Q','W','E','R'}; //User-Defined Password

int pass_correct = 0; //Does Password match, 0=false 1=true

void setup() {

pinMode(motor, OUTPUT);

Serial.begin(9600);

}

void loop() {

while(Serial.available()){

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

final[i] = Serial.read();

}

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

if(final[i]==correct[i]){

pass_correct = 1;

}

else{

pass_correct = 0;

break;

}

}

}

if(pass_correct==1){

digitalWrite(motor, HIGH);

Serial.println("motor is on");

delay(4000);

pass_correct = 0;

}

else{

digitalWrite(motor, LOW);

}

}

Kdmath (author)2015-09-16

Are there any Bluetooth SSP applications that can be installed and used for an iPhone? Or is the iPhone not compatable?

HaziqS (author)2015-09-02

Hi is this possible to use WIFI + bluetooth to unlock the multiple door ? and if yes what changes ive to made??

About This Instructable

331,281views

812favorites

License:

Bio: I live to learn
More by Collin Amedee:Easy Bluetooth Enabled Door Lock With Arduino + AndroidUniversal Power Supply For Arduino + Breadboard
Add instructable to: