Fabrizio LylesFelix VivongsyDavid Pisacane
Published

IoT Makeshift Door Lock

Tired of getting off your couch to unlock your door for your roommate? Forget to lock your door on your way to class? Say no more…

IntermediateFull instructions provided360

Things used in this project

Hardware components

Photon
Particle Photon
×3
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Jumper wires (generic)
Jumper wires (generic)
×6
Elegoo 28BYJ-48 Stepper Motor + Driver Board
×1
Elegoo Stepper Motor Driver (uln2003 driver)
×1
3D Printed Base
×1
3D Printed Attachment
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Blynk
Blynk

Story

Read more

Custom parts and enclosures

Lock Cover

Lock Attachment

Schematics

Circuit Board

Circuit Board

Code

Unlock/Lock the door

C/C++
Here is how the motor is told to unlock/lock the door.
#define BLYNK_PRINT Serial  
#include <blynk.h>

int button = D3;
#define STEPPER_PIN_1 D7
#define STEPPER_PIN_2 D6
#define STEPPER_PIN_3 D5
#define STEPPER_PIN_4 D4

int step_number = 0;                                    // step_numer is the counter
bool shouldResetLow = false;                            // flag that says if the button is selected, set step_number back to zero
bool shouldResetHigh = false;                           // flag that says if the button is selected, set step_number back to zero (other state)
int maxCount = 5000;                                    // timer

char auth[] = "7b4d8606e64443138782c8dc9cb94c7b";       // authentication for Blynk button

void setup(){
    pinMode(STEPPER_PIN_1, OUTPUT);
    pinMode(STEPPER_PIN_2, OUTPUT);
    pinMode(STEPPER_PIN_3, OUTPUT);
    pinMode(STEPPER_PIN_4, OUTPUT);

    Blynk.begin(auth);
    
    Particle.subscribe("Connect_to_three", name4, MY_DEVICES); // Subscribe from 02-particle
    Particle.subscribe("Back_2", name5, MY_DEVICES); // subscribe from 03-particle
}

void name4(const char *event, const char *data){
delay(5000);
    if (digitalRead(D7) == HIGH){
        digitalWrite(D7, LOW);
        delay(5000);
        digitalWrite(D7, HIGH);
        delay(5000);
//return;
    }
    
    else if (digitalRead(D7) == LOW){
        digitalWrite(D7, HIGH);
        delay(1000);
        digitalWrite(D7, LOW);
        delay(5000);
//return;
    }
    
    delay(1000);
Particle.unsubscribe();
    
}


void name5(const char *event, const char *data){
    delay(5000);
    if (digitalRead(D7) == HIGH){
        digitalWrite(D7, LOW);
        delay(5000);
        digitalWrite(D7, HIGH);
//return;
    }
    else if (digitalRead(D7) == LOW){
        digitalWrite(D7, HIGH);
        delay(5000);
        digitalWrite(D7, LOW);
//return;    
    }
    delay(1000);
Particle.unsubscribe();

}


void loop(){
    Blynk.run();
    if (digitalRead(button) == LOW) {  // LOW is when the button is unlocked
        if (shouldResetLow) {
            step_number = 0;                            // starts at zero and runs steps
            shouldResetLow = false;                     // no longer reset
        
        
        Particle.publish("Connect", "unlocked", 60, PRIVATE);
        
        
        }
        if (step_number < maxCount) {                   // counts to maxCount and stalls until button is seleted
            OneStep(true);          
            if (step_number >= maxCount) {
                shouldResetHigh = true;                 // resets to zero when button is seltec (high)
            }
        }
    } else if (digitalRead(button) == HIGH) {           // HIGH is when the button is locked
        if (shouldResetHigh) {          
            step_number = 0;                            // starts at zero and runs steps  
            shouldResetHigh = false;                    // no longer reset
        }
        if (step_number < maxCount) {                   // counts to maxCount and stalls until button is seleted
            OneStep(false);
            if (step_number >= maxCount) {
                Particle.publish("Connect", "locked", 60, PRIVATE);
                shouldResetLow = true;
            }
        }
    }
}

void OneStep(bool dir) {                                // OneStep is exactly as stated. Entire function runs through a single step in the motor
        if(dir) {                                       // Sets a true/false
            switch(step_number %4){                     // step_number divided by 4; motor rotates clockwise
              case 0:
              digitalWrite(STEPPER_PIN_1, HIGH);        
              digitalWrite(STEPPER_PIN_2, LOW);
              digitalWrite(STEPPER_PIN_3, LOW);
              digitalWrite(STEPPER_PIN_4, LOW);
              break;
              case 1:
              digitalWrite(STEPPER_PIN_1, LOW);
              digitalWrite(STEPPER_PIN_2, HIGH);
              digitalWrite(STEPPER_PIN_3, LOW);
              digitalWrite(STEPPER_PIN_4, LOW);
              break;
              case 2:
              digitalWrite(STEPPER_PIN_1, LOW);
              digitalWrite(STEPPER_PIN_2, LOW);
              digitalWrite(STEPPER_PIN_3, HIGH);
              digitalWrite(STEPPER_PIN_4, LOW);
              break;
              case 3:
              digitalWrite(STEPPER_PIN_1, LOW);
              digitalWrite(STEPPER_PIN_2, LOW);
              digitalWrite(STEPPER_PIN_3, LOW);
              digitalWrite(STEPPER_PIN_4, HIGH);
              break;
            } 
        } else {
            switch(step_number %4){                     // step_number divided by 4; motor rotates counter-lockwise
              case 0:
              digitalWrite(STEPPER_PIN_1, LOW);
              digitalWrite(STEPPER_PIN_2, LOW);
              digitalWrite(STEPPER_PIN_3, LOW);
              digitalWrite(STEPPER_PIN_4, HIGH);
              break;
              case 1:
              digitalWrite(STEPPER_PIN_1, LOW);
              digitalWrite(STEPPER_PIN_2, LOW);
              digitalWrite(STEPPER_PIN_3, HIGH);
              digitalWrite(STEPPER_PIN_4, LOW);
              break;
              case 2:
              digitalWrite(STEPPER_PIN_1, LOW);
              digitalWrite(STEPPER_PIN_2, HIGH);
              digitalWrite(STEPPER_PIN_3, LOW);
              digitalWrite(STEPPER_PIN_4, LOW);
              break;
              case 3:
              digitalWrite(STEPPER_PIN_1, HIGH);
              digitalWrite(STEPPER_PIN_2, LOW);
              digitalWrite(STEPPER_PIN_3, LOW);
              digitalWrite(STEPPER_PIN_4, LOW);
              break;
            }
        }
        step_number++;
} 

Indicator for when door is unlocked

C/C++
This will publish to the cloud that your door is unlocked.
void setup() {
    pinMode(D7, OUTPUT);
    Particle.subscribe("Connect", name2, MY_DEVICES); // subscribe from 01-particle


}

void name2(const char *event, const char *data){
    delay(5000);
    if(digitalRead(D7) == LOW){
    digitalWrite(D7, HIGH);
    delay(5000);

//    digitalWrite(D7, LOW);
            Particle.publish("Connect_to_three", "light is off", 60, PRIVATE);
    return;
    }
            
//    Particle.unsubscribe();
    
    
    Particle.subscribe("Back_2", name3, MY_DEVICES); // subscribe from 03-particle
}


void name3(const char *event, const char *data){
    delay(5000);
    if (digitalRead(D7) == HIGH){
        digitalWrite(D7, LOW);
        delay(5000);
    }
    else if (digitalRead(D7) == LOW){
        digitalWrite(D7, HIGH);
        delay(5000);

//    Particle.unsubscribe();
    }

}


void loop() {
//    if(digitalRead(D7) == HIGH){
//        Particle.publish("Connect_to_three", "on", 60, PRIVATE); // publish to 03-particle and back to 01-particle
//    }
    

}

Presence indicator

C/C++
Publishes a script to your phone to let you or someone you care about know that you have left/arrived.
int led = D7;

void setup() {
    pinMode(D7, OUTPUT);
    Particle.subscribe("Connect_to_three", name3, MY_DEVICES);
}

void name3(const char *event, const char *data){

    delay(2000);
    if(digitalRead(led) == LOW){
        digitalWrite(led, HIGH);
        delay(10000);
        Particle.publish("Back_2", "I am back", 60, PRIVATE);
        delay(2000);        
        return;
    }
    else if (digitalRead(led) == HIGH){
        digitalWrite(led, LOW);
        delay(10000);
        Particle.publish("Back_2", "I am back", 60, PRIVATE);
        delay(2000);
        return;
    }    
    
    
    
 /*   if (digitalRead(D7) == LOW){
        delay(5000);
        digitalWrite(D7, HIGH);
        delay(2000);
    
        Particle.publish("position", "on mode", 60, PRIVATE); // Connects back to 02-particle
    }
    else if (digitalRead(D7) == HIGH){
        delay(5000);
        digitalWrite(D7, HIGH);
        delay(2000);
        
        Particle.publish("position", "on mode", 60, PRIVATE); // Connects back to 02-particle
 */   }
    

    

void loop() {
        if(digitalRead(D7) == HIGH){

        String data = String(1);
        delay(30000);

        Particle.publish("position", data, PRIVATE);
        delay(30000);
    }
    
    else if (digitalRead(D7) == LOW){
        String data = String(0);
        delay(30000);

        Particle.publish("position", data, PRIVATE);
        delay(30000);
    }   

}

Credits

Fabrizio Lyles

Fabrizio Lyles

1 project • 0 followers
Felix Vivongsy

Felix Vivongsy

1 project • 0 followers
David Pisacane

David Pisacane

1 project • 0 followers

Comments

Add projectSign up / Login