Michael StewartNate Rumph
Published

WiFi Connected Door Lock

Modifies existing door locks to be controlled via servo and Mobicle.io. This is a working prototype used for demonstration purposes.

BeginnerFull instructions provided3 hours2,337
WiFi Connected Door Lock

Things used in this project

Hardware components

Servos (Tower Pro MG996R)
Link for updated servo: https://www.amazon.com/DS3218-update-digital-Waterproof-Control/dp/B01MU7TQV8
×1
Jumper wires (generic)
Jumper wires (generic)
×5
Photon
Particle Photon
×1
AA Batteries
AA Batteries
Rechargeable batteries are preferred.
×1
4xAA battery holder
4xAA battery holder
×1
Generic Plastic Housing
This component can be essentially any appropriately sized housing that can be mounted.
×1
Mounting Adhesive
This is just recommended but proper mounting hardware is also suggested. This can also be used to attach the bracket for the servo lever arm
×1
Zinc Fastener
These were what we used to construct the bracket for the servo arm.
×1
Adafruit Tiny breadboard
The smaller the breadboard, the better and this quarter size board is perfect for small projects. The one shown in the photos came with the Maker Kit but the Adafruit Tiny board is the optimal choice.
×1

Software apps and online services

Mobicle
ControlEverything.com Mobicle

Hand tools and fabrication machines

Dremel
This tool is by no means required but is recommended if a slot in the housing is not already present.

Story

Read more

Custom parts and enclosures

Servo Arm Bracket

This a Creo file that can be used if a 3-D printer is available and replaces the zinc fasteners that could be glued on the servo arm. Inner Diameter fits most locks and 8-32 UNC holes are tapped.

Schematics

Circuit Diagram

Any pin will work but this particular example chose A7 for the servo.
The battery pack will also be grounded with the servo and the positive wire goes into the Vin Pin.
Sourced from http://diotlabs.daraghbyrne.me/6-controlling-outputs/servo/

Code

WiFi Connected Lock

Arduino
This code with buttons created on Mobicle will allow users to unlock/lock doors and publish event data. Argument parameters for the buttons:
Unlocked = -90
Locked = 90
// Mike Stewart
// Lock Setup & Configuration
// MEGR 3171
// Variable & integer declarations
int servoPin = A7;
// servo name declaration
Servo EMax;
int servoPos = 0;
int boardLed = D7;
// flag used to trigger if we have a new status for the event
bool lockActivated = false; 
void setup() {
// the onboard LED is our output as well as the servo
pinMode(boardLed,OUTPUT);
// enables the servo as an output of the function
pinMode( servoPin,OUTPUT);
// attaches the servo on the A7 pin to the servo object
EMax.attach( servoPin );
    // register our particle to control the servo
    Particle.function("servo", servoControl);
    // keep a cloud variable for the current position
    Particle.variable( "servoPos" , &servoPos , INT );
// The subscribe function allows our photon to receive data from another person's photon
Particle.subscribe("Lock Activation", myHandler);
}
void loop(){
// Loop for publishing lock events to the Particle Console
if (servoPos = -90){
    if(lockActivated==true){
        Particle.publish("Lock Activation","Locked",60,PRIVATE);
        digitalWrite(boardLed,HIGH);
        delay(500);
        digitalWrite(boardLed,LOW);
        
        lockActivated=false;
    }else{
        // Otherwise this status isn't new and nothing should be done
    }
}else{
    if (lockActivated==false){
        Particle.publish("Lock Activation","Unlocked",60,PRIVATE);
        digitalWrite(boardLed,HIGH);
        delay(500);
        digitalWrite(boardLed,LOW);
    
        lockActivated=true;
    }else{
    }
}
}
// command for servo over the cloud
int servoControl(String command)
{   int newPos = command.toInt();
    // Parameters for servo degrees of rotation
    servoPos = constrain( newPos, -180 , 180);
    EMax.write( servoPos );
    return 1;
}
// the myHandler function is called when the cloud tells us that our friend's event is published
void myHandler(const char *event, const char *data)
{ 
    if (strcmp(data,"Locked")==0) {
        // if your friend's Lock is engaged, then the board LED will turn on 
        digitalWrite(boardLed,HIGH);
    }
    else if (strcmp(data,"Unlocked")==0) {
        // if the Lock is disengaged, then the board LED will turn off
        digitalWrite(boardLed,LOW);
    }
    else{
    // data shouldn't be anything but the two options listed above
    }
}

Credits

Michael Stewart

Michael Stewart

1 project • 0 followers
Nate Rumph

Nate Rumph

0 projects • 0 followers

Comments