Easy Bluetooth Enabled Door Lock With Arduino + Android

338,229

814

137

Published

Introduction: Easy Bluetooth Enabled Door Lock With Arduino + Android

About: I live to learn
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

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

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

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

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)

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

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.

Arduino Challenge

Second Prize in the
Arduino Challenge

3 People Made This Project!

Recommendations

  • Clocks Contest

    Clocks Contest
  • Water Contest

    Water Contest
  • Creative Misuse Contest

    Creative Misuse Contest

137 Discussions

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.

1 reply

You could find a nearby outlet box and mount a transformer on it or next to it. Dig out the drywall saw.

it is arduino programming

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.

1 reply
0
user
jibays

1 year ago

is there any available full video tutorial of this project?

thank you :)

0
user
dugle

1 year ago

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

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

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

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

can use arduino uno instead of duemilanove?

0
user
BenP74

1 year ago

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

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

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.

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.

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

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 .

Hi,any one give circuit diagram for this project

appreciable work for beginners

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 :)