SmartLock

Our project is a smart door switch that utilizes a servo. The door (servo) will open when someone gets closer to the sonar sensor, and when it gets too close the door will lock, indicating that the user has enter the room. It can also be controlled through bluetooth, and shows open door and close door sound in each case.

Components

mbedBLE
p28TX
p27RX
VoutVcc
GndGnd
SDMbed
CS8 (DigitalOut cs)
DI5 (SPI mosi)
VCCVOUT
SCK7 (SPI sclk)
GNDGND
DO6 (SPI miso)
CDnc
mbedAudioDriver
p18In+
GndIn-
mbedServo
p21PWM
External 5VV+
GndGnd

int main()
{
    thread1.start(ble);
    thread2.start(speaker);
//     
//     
//     
    mu.startUpdates();//start measuring the distance
    

    
    while(1) {
        //Do something else here
        mu.checkDistance();     //call checkDistance() as much as possible, as this is where
                                //the class checks if dist needs to be called.
        
        if (test <= 1 )  // open when something is close to the sensor
        { myLED1 = 1 ; myLED2 = 0; myLED3 = 0; myLED4 = 0; myservo = 1 ; close = true;}
        
        else if ( test > 1 and test <= 2 )
        { myLED1 = 0 ; myLED2 = 1; myLED3 = 0; myLED4 = 0; open = false; close = false;}
        
        else if ( test > 2 and test <= 3 )
        { myLED1 = 0 ; myLED2 = 0; myLED3 = 1; myLED4 = 0; open = false; close = false;}
        
        else if ( test > 3 and test <= 4 )
        { myLED1 = 0 ; myLED2 = 0; myLED3 = 0; myLED4 = 1; open = false; close = false;} 
        
        else if ( test > 5 and test <=8 ) // close when something is far away from the sensor
        
        { myLED1 = 1 ; myLED2 = 1; myLED3 = 1; myLED4 = 1; myservo = 0 ; open = true;}
        
        }


}


Please log in to post comments.