hi

Dependencies:   4DGL-uLCD-SE Servo HC_SR04_Ultrasonic_Library mbed-rtos mbed

You are viewing an older revision! See the latest version

Homepage

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

/media/uploads/Philipjp/servoproduct.jpg.200x200_q85.jpg /media/uploads/Philipjp/servocable.png

Servo MotorMbed
BlackGnd
RED5V
Yellowp21

/media/uploads/Philipjp/hcsr04.jpg

Sonar SenorMbed
Vcc5V
GndGnd
trigp6
echop7

/media/uploads/Philipjp/8185.png

uLCD cableMbed
Vcc5V
GndGnd
TXp13
RXp14
RESETp15

/media/uploads/Philipjp/ble.jpg

Adafruit BLEMbed
VinVu
gnd,CTSGnd
TXOp10
RXIp9

/media/uploads/Philipjp/bottom.jpg

PushbuttonMbed
Pin1p23, p24
Pin2Gnd

/media/uploads/Philipjp/lrf.png

LED lightMbed
Pin1p8
Pin2Gnd

/media/uploads/Philipjp/rgbled.jpg

RGBLED lightMbed
REDp26
GndGnd
GREENp29
BLUEp30

/media/uploads/Philipjp/speaker.jpg /media/uploads/Philipjp/2n3904.jpg

SpeakerMbed
+Vu
-Gnd
MBEDAdafruit BLEAmplifierServoSpeakerSonaruLCD cable
Vouttablevvf
Groundgnd,CTStable-GndGnd
VuVintableVcc5V
P6tabletrig
P7tableecho
P8table
P9RXItable
P10TXOtable
P13tableTX
P14tableRX
P15tableRESET
P20table
P21lesignal
P22tablespeaker
P23tablebottom 1
P24tablebottom 2
P25table
P26tableRED
P27table
P28table
P29tableGREEN
P30tableBLUE
Vin+

Bluetooth Thread

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 Thread

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();
        }  
           
           
           
    }
    
    
    
}
}

Light Sensor Thread

A light sensor is used to tell if it is night time. This thread constantly checks if the amount of light is low and if it is it locks the door after 10 seconds of low light.

Main Thread

The main thread initializes the Bluetooth and LCD threads, checks if the pushbuttons are pressed and checks if the door is closed or open, The pushbuttons simply unlock and lock the door. There is a third pushbutton that locks the door but it after a few seconds after being pressed. This gives the person time to open and close the door before it locks. Sonar is used to check if the door is closed or open. The main thread initializes the sonar so that the distance from the sensor to an object is constantly measured. If this distance is greater than a certain value then it means that the door is open. This is used for the alarm which is turned on if the door is open while it is locked. <</code>> int main() { uLCD.baudrate(3000000); pb1.mode(PullUp); pb2.mode(PullUp); mu.startUpdates();start measuring the distance thread.start(bluetooth); thread2.start(LCD);

while(1){ if (pb1==0){

i = 0; LEDG = 0; LEDB = 0; LEDR=1; } if (pb2==0){ i = 1; LEDR=0; LEDB =0; LEDG = 1; }

myservo=i;

mut.lock(); mu.checkDistance(); mut.unlock();

if (dist2>0.5f) { led=1; j=1;

} else { led=0; j=0;

}

if (j==1) { mut.lock();

uLCD.color(BLACK); uLCD.text_width(2); uLCD.text_height(2); uLCD.printf("CLOSED");

uLCD.color(RED); uLCD.text_width(2); uLCD.text_height(2); uLCD.printf("OPEN"); mut.unlock(); } if(j==0) {

mut.lock();

uLCD.color(BLACK); uLCD.text_width(2); uLCD.text_height(2); uLCD.printf("OPEN");

uLCD.color(GREEN); uLCD.text_width(2); uLCD.text_height(2); uLCD.printf("CLOSED"); mut.unlock(); }

}end while }end main <</code>>


All wikipages