Smart Door Lock¶
Overview¶
A smart door lock system was designed with the purpose of adding some sort of security to any door. A servo was connected to a door lock which locks and unlocks it. The door can be locked and unlocked using a an app on a phone, pushbuttons and timers which lock the door after a certain time. Sonar was used to determine if the door is closed or open. A speaker and an amplifier are included
which are used as an alarm that goes off when the door is opened without being authorized. An LCD was used to display the current settings.
Wiring¶

Servo Motor | Mbed |
Black | Gnd |
RED | 5V |
Yellow | p21 |

Sonar Senor | Mbed |
Vcc | 5V |
Gnd | Gnd |
trig | p6 |
echo | p7 |

uLCD cable | Mbed |
Vcc | 5V |
Gnd | Gnd |
TX | p13 |
RX | p14 |
RESET | p15 |

Adafruit BLE | Mbed |
Vin | Vu |
gnd,CTS | Gnd |
TXO | p10 |
RXI | p9 |

Pushbutton | Mbed |
Pin1 | p23, p24 |
Pin2 | Gnd |

LED light | Mbed |
Pin1 | p8 |
Pin2 | Gnd |

RGBLED light | Mbed |
RED | p26 |
Gnd | Gnd |
GREEN | p29 |
BLUE | p30 |

MBED | Adafruit BLE | Amplifier | Servo | Speaker | Sonar | uLCD cable | | |
Vout | | table | vvf | | | | | |
Ground | gnd,CTS | table | - | | Gnd | Gnd |
Vu | Vin | table | | | Vcc | 5V |
P6 | | table | | | trig | |
P7 | | table | | | echo | |
P8 | | table | | | | | |
P9 | RXI | table | | | | |
P10 | TXO | table | | | | |
P13 | | table | | | | TX |
P14 | | table | | | | RX |
P15 | | table | | | | RESET |
P20 | | table | | | | | |
P21 | | le | signal | | | | | | | |
P22 | | table | | speaker | | |
P23 | | table | | bottom 1 | | |
P24 | | table | | bottom 2 | | |
P25 | | table | | | | |
P26 | | table | | RED | | |
P27 | | table | | | | |
P28 | | table | | | | |
P29 | | table | | GREEN | | |
P30 | | table | | BLUE | | |
Vin | | | + | | | |
Bluetooth¶
To be able to wirelessly unlock the door knob we used the adafruit BLE which can communicate with the Bluefruit app. We created a function which prints a line to the phone asking for a password. It waits until something is typed in and if the password is correct it unlocks/locks the door. If the password is not correct it just prints the same line again. This function runs on a separate thread so that other things can be done simultaneously.
void bluetooth(){
while(1){
blue.printf("enter password\n");
if (blue.getc()=='!')
{
if (blue.getc()=='!')
{
if (blue.getc()=='!')
{
if (blue.getc()=='!')
{
i=!i;
blue.printf("password is correct\n");
}
}
}
}
}//end while loop
}
LCD¶
Another thread was used for displaying the status of the door. If the door is locked a green message is displayed on the LCD and a red message is displayed if the in unlocked. The LCD also tells if the door is open or closed. The code for the LCD is provided below. This thread also checks if the door is opened without authorization and if it is the alarm goes off.
void LCD()
{
while(1)
{
if (j==0)
{
mut.lock();
uLCD.cls();
uLCD.line(0, 0, 127, 0, RED);
uLCD.line(127, 0, 127, 127, RED);
uLCD.line(127, 127, 0, 127, RED);
uLCD.line(0, 127, 0, 0, RED);
uLCD.color(RED);
uLCD.locate(7,8);
uLCD.text_width(1);
uLCD.text_height(1);
uLCD.printf("CLOSE");
// LEDR =0;
//LEDG = 0;
LEDB =0;
if(i==0){
uLCD.locate(7,9);
uLCD.printf("Locked");}
else
{uLCD.locate(7,9);
uLCD.printf("Unlocked");}
wait(1);
mut.unlock();
}
if(j==1)
{
mut.lock();
uLCD.cls();
uLCD.line(0, 0, 127, 0, GREEN);
uLCD.line(127, 0, 127, 127, GREEN);
uLCD.line(127, 127, 0, 127, GREEN);
uLCD.line(0, 127, 0, 0, GREEN);
uLCD.color(GREEN);
uLCD.locate(7,8);
uLCD.text_width(1);
uLCD.text_height(1);
uLCD.printf("OPEN");
LEDR =0;
LEDG = 0;
LEDB =1;
if (i==0){
uLCD.locate(7,9);
uLCD.printf("Locked");
speaker.period(1.0/969.0); }
//wait(1);
mut.unlock();
}
}
}
}