You are on page 1of 9

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.p
rint(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=W251bGwsMSwyLDEsIm1vYmkuZHpzLmFuZHJvaWQuQmx1ZXRvb3
RoU1BQIl0.

You might also like