Emma HardmanJake ShattuckWill Birchfield
Published

Automated Door Lock- IOT group 36

An easy way to unlock your door by simply standing near it or using your phone or a button.

IntermediateFull instructions provided19
Automated Door Lock- IOT group 36

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04
SparkFun Ultrasonic Sensor - HC-SR04
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Breadboard (generic)
Breadboard (generic)
×3
Argon
Particle Argon
×3

Software apps and online services

Maker service
IFTTT Maker service

Hand tools and fabrication machines

Drill / Driver, Cordless
Drill / Driver, Cordless

Story

Read more

Schematics

CIRCUIT DIAGRAMS

ULTRASONIC SENSOR DOOR LOCK/UNLOCK DATA

Code

SERVO CODE

C/C++
Servo myservo;  // create servo object to control a servo
                

void setup()
{
  myservo.attach(A2);  // attaches the servo on the A2 pin to the servo object
  
myservo.write(10);
}

void loop()
{
Particle.subscribe("LockActivation1234", DoorUnlock);
  // Subscribe will listen for the event and, when it finds it, will run the function
  delay(1000);
Particle.subscribe("button", DoorUnlock);
  delay(1000);
}

void DoorUnlock(const char *event, const char *data)
{
  /* Particle.subscribe handlers are void functions, which means they don't return anything.
  They take two variables-- the name of your event, and any data that goes along with your event. */
  
    {
    myservo.write(180); 
    Particle.publish("DoorStatus","Open");
    delay(240000);
    myservo.write(10); 
    delay(1000);
    Particle.publish("TaskStatus1234","Completed");
  }
 
}

BUTTON CODE

C/C++
void setup() {
pinMode(D7, INPUT);
}

void loop() {
int tfbutton = digitalRead(D7);
if (tfbutton == HIGH) {
    Particle.publish("button","on");
}

}

SONIC RANGER FINDER CODE

C/C++
/*
 * UltrasonicDisplayOnTerm.ino
 * Example sketch for ultrasonic ranger
 *
 * Copyright (c) 2012 seeed technology inc.
 * Website    : www.seeed.cc
 * Author     : LG, FrankieChu
 * Create Time: Jan 17,2013
 * Change Log :
 *
 * The MIT License (MIT)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */


/***************************************************************************/
//	Function: Measure the distance to obstacles in front and print the distance
//			  value to the serial terminal.The measured distance is from
//			  the range 0 to 400cm(157 inches).
//	Hardware: Grove - Ultrasonic Ranger
//	Arduino IDE: Arduino-1.0
/*****************************************************************************/

#include "Grove-Ultrasonic-Ranger.h"

int delaystart = 0;
int enable = 1;
int pub = 0;	
long RangeInInches;
long RangeInCentimeters;
Ultrasonic ultrasonic(7);
void setup()
{
	Serial.begin(9600);
	Particle.subscribe("DoorStatus", DoorOpen);
}
void loop()
{
	
	RangeInCentimeters = ultrasonic.MeasureInCentimeters();
	if (RangeInCentimeters < 100) {
	    pub = 1;
	}
	if ((delaystart + 240000) > millis()){
	    enable = 1;
	}
	if ((pub == 1) && (enable == 1)) {
	    Particle.publish("Doordetect","open");
	    pub = 0;
	}
	delay(250);
}
void DoorOpen(const char *event, const char *data)
{
    pub = 0;
    delaystart = millis();
    enable = 0;
    
}

Credits

Emma Hardman

Emma Hardman

1 project • 1 follower
Jake Shattuck

Jake Shattuck

1 project • 1 follower
Will Birchfield

Will Birchfield

0 projects • 1 follower

Comments

Add projectSign up / Login