Riley RedmonThomas Fudala
Published

Simply Safe Door Security

Protect your family with latest and greatest door position sensing system!

BeginnerFull instructions provided1 hour231
Simply Safe Door Security

Things used in this project

Hardware components

Argon
Particle Argon
×2
LED (generic)
LED (generic)
×1
Reed Switch, Magnet Switch Set
Reed Switch, Magnet Switch Set
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Particle 1 (Door Sensor)

Magnetic switch connected from D0 to ground.

Particle 2 (Door Subscription)

Resistor and LED in series connected to ground and D7.

Code

Door Sensor

C/C++
This code reads if the switch is open or closed and uploads the current status to the cloud every 10 seconds.
#include "lib1.h"

int doorstatus = 0;  

void setup() {
  pinMode(D0,INPUT_PULLUP); //configure D0 to input with an internal resistor pullup.
}

void loop() {
    
doorstatus = digitalRead(D0);
if (doorstatus == TRUE){
    Particle.publish("MEGR3171/team58/doorstatus", "open",PUBLIC);  //subscribe to door status
    delay(10000);  //delay between readings sent to the cloud
    }
}

Door Subscription

C/C++
This code reads what the door sensor sends to the cloud. If the door sensor uploads open the code instructs the particle to send power to D7. If the door sensor uploads nothing the code instructs the particle to do nothing.
int i;  

void setup() { //Runs once
Particle.subscribe("MEGR3171/team58/doorstatus", doorsubscribe);  //subscribe to this door event.
Serial1.begin(115200);  //Turns on the particle serial port
pinMode(D7, OUTPUT);
digitalWrite(D7, HIGH);  //blink on reset
delay(500);
digitalWrite(D7,LOW);
}

void loop() {
//nothing happens here for this sketch
}

void doorsubscribe(const char *event, const char *data) {  //do this when the door status is published.
  i++;  
  Serial.print(i); //print the number of times this has been called over the serial port
  Serial.print(event);  //print the event name
  Serial.print(", data: ");
  if (data)
    Serial.println(data);
  else
    Serial.println("NULL");
  
    digitalWrite(D7, 1);  //make the LED turn on if the door is open
    delay(10000);
    digitalWrite(D7, 0);
}

Credits

Riley Redmon

Riley Redmon

1 project • 1 follower
Thomas Fudala

Thomas Fudala

1 project • 1 follower

Comments

Add projectSign up / Login