Michael BennettAndrew Karam
Published © LGPL

App And Remote Controlled Servo Door Lock

Lock and unlock a door from anywhere using the in home controller or a smartphone app.

IntermediateShowcase (no instructions)2 hours1,638
App And Remote Controlled Servo Door Lock

Things used in this project

Hardware components

Particle Photon I²C 2-Channel SPDT 1-Amp Signal Relay
ControlEverything.com Particle Photon I²C 2-Channel SPDT 1-Amp Signal Relay
×2
Servos (Tower Pro MG996R)
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
2 breadboards were included with the Particle Photons
×2
LED (generic)
LED (generic)
2 LEDs were included with the Particle Photons
×2
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×2
Battery Power Bank with 2 micro USB cables
×2

Software apps and online services

Mobicle
ControlEverything.com Mobicle
This is where the the unlock and lock commands are sent from
Maker service
IFTTT Maker service
This app will notify you when the door is locked or unlocked

Hand tools and fabrication machines

Aluminum Foil (generic)
This gave the servo a steady base which was attached to the door
Hot glue gun (generic)
Hot glue gun (generic)
This held the components on the door

Story

Read more

Schematics

Breadboard Configurations

This Shows the image layout of the Particle Photons and the rest of the components on the breadboard. This image shows the particles on one breadboard but in reality, they are on two separate breadboards.

Code

Servo Particle Photon Code

C/C++
This code moves the servo when a signal is received from the tactile button or the Mobicle app.
The event names in Particle.publish were just the names that were used for this lock. These names will need to be changed if this code is used for another project
//Lock function
int lock(String) {
    //Moves servo to lock position
    serv.write(valLock);
    //Lock number changes to 1
    nLock = 1;
    //Publishes "Locked"
    Particle.publish("mbenne_door_lock","Locked");
    //Switches the external LED off
    digitalWrite(boardLed,LOW);
}

//Unlock function
int unlock(String) {
    //Moves servo to unlock position
    serv.write(valUnlock);
    //Lock number changes to 0
    nLock = 0;
    //Publishes "Unlocked"
    Particle.publish("mbenne_door_lock","Unlocked");
    //Switches the board LED on
    digitalWrite(boardLed,HIGH);
}

void loop() {
    //If the button is pressed, the locked switches between locked and unlocked
    if (analogRead(button)<100) {
        //Lock sequence
        if (nLock==0) {
            //Moves servo to locked position
            serv.write(valLock);
            //Changes lock number to 1
            nLock = 1;
            //Publishes "Locked"
            Particle.publish("mbenne_door_lock","Locked");
            //Switches the board LED off
            digitalWrite(boardLed,LOW);
            delay(1000);
        }
        //Unlock sequence
        else if (nLock==1) {
            //Moves servo to unocked position
            serv.write(valUnlock);
            //Changes lock number to 0
            nLock = 0;
            //Publishes "Unlocked"
            Particle.publish("mbenne_door_lock","Unlocked");
            //Switches the board LED on
            digitalWrite(boardLed,HIGH);
            delay(1000);
        }
    }
}

void myHandler(const char *event, const char *data) {
    //When the "Lock" event data is published with the sucribed with "akaram_door_lock", the lock switches bewtween lock and unlock
    if (strcmp(data,"Lock")==0) {
        //Lock sequence
        if (nLock==0) {
            //Moves servo to lock position
            serv.write(valLock);
            //Changes lock number to 1
            nLock = 1;
            //Publishes "Locked"
            Particle.publish("mbenne_door_lock","Locked");
            //Switches board LED off
            digitalWrite(boardLed,LOW);
        }
        //Unlock sequence
        else if (nLock==1) {
            //Moves servo to unlock position
            serv.write(valUnlock);
            //Changes lock number to 0
            nLock = 0;
            //Publishes "Unlocked"
            Particle.publish("mbenne_door_lock","Unlocked");
            //Switches the board LED on
            digitalWrite(boardLed,HIGH);
        }
    }
}

Controller Particle Photon

C/C++
This code is used to send an event to the servo Particle Photon when the tactile button is pressed and to indicate whether the door is unlocked or locked with LEDs.
//Power to switch is on pin A0
int power = A0;
//Button on pin A1
int button = A1;
//Lock LED is on pin D0
int ledLock = D0;
//Unlock LED is on pin D1
int ledUnlock = D1;
//Board LED is on pin D7
int boardLed = D7;
//Assigns variables to lock(1) or unlock(0)
int nLock = 0;

void setup() {
    //Describes outputs and input of pins
    pinMode(power,OUTPUT);
    pinMode(button,INPUT);
    pinMode(boardLed,OUTPUT);
    pinMode(ledLock,OUTPUT);
    pinMode(ledUnlock,OUTPUT);
    
    //Suscribes to other photon
    Particle.subscribe("mbenne_door_lock", myHandler);
    
    //Powers the pin connected to the switch 
    analogWrite(power,4095);
    
    //both LEDs turn on when switch is powered
    digitalWrite(ledLock,HIGH);
    digitalWrite(ledUnlock,HIGH);
    
    //Flashes board LED when setup is complete
    digitalWrite(boardLed,HIGH);
    delay(300);
    digitalWrite(boardLed,LOW);
    delay(300);
    digitalWrite(boardLed,HIGH);
    delay(300);
    digitalWrite(boardLed,LOW);
    delay(300);
    digitalWrite(boardLed,HIGH);
    delay(300);
    digitalWrite(boardLed,LOW);
    
    //Lock LED turns off to leave the Unlock LED on
    digitalWrite(ledLock,LOW);
}

void loop() {
   //If the button is pressed, "Lock" is published and the board LED flashes 3 times
    if (analogRead(button)<100) {
            Particle.publish("akaram_door_lock","Lock");
            digitalWrite(boardLed,HIGH);
            delay(100);
            digitalWrite(boardLed,LOW);
            delay(100);
            digitalWrite(boardLed,HIGH);
            delay(100);
            digitalWrite(boardLed,LOW);
            delay(100);
            digitalWrite(boardLed,HIGH);
            delay(100);
            digitalWrite(boardLed,LOW);
            delay(1000);
    }
}

void myHandler(const char *event, const char *data) {
    //When "Unlocked" is recieved from "mbenne_door_lock", the unlocked LED turns on and the locked LED turns off
    if (strcmp(data,"Locked")==0) {
        digitalWrite(ledUnlock,LOW);
        digitalWrite(ledLock,HIGH);
    }
    //When "Locked" is recieved from "mbenne_door_lock", the locked LED turns on and the unlocked LED turns off
    else if(strcmp(data,"Unlocked")==0) {
        digitalWrite(ledLock,LOW);
        digitalWrite(ledUnlock,HIGH);
    }
}

Credits

Michael Bennett

Michael Bennett

1 project • 1 follower
Andrew Karam

Andrew Karam

1 project • 0 followers

Comments