Davis RochesterNick Shoffner
Published

Magnet Door Sensor Project

If you want increased security, look no further than our door sensor that sends an immediate notification to your phone and triggers lights.

IntermediateShowcase (no instructions)45
Magnet Door Sensor Project

Things used in this project

Hardware components

Reed Switch, Magnet Switch Set
Reed Switch, Magnet Switch Set
×1
LED (generic)
LED (generic)
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Argon
Particle Argon
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Schematics

LED Light Schematic

Magnet Switch Schematic

Flowchart

Data Recorded

Code

Magnet Switch Code

C/C++
This code is for the magnet switch. This code publishes that the door is open or closed to the Particle Web IDE and can be used to get notifications on your phone.
void setup() {
    pinMode(D7,INPUT_PULLUP); //configure D7 to input with an internal resistor pullup.
}

void loop() {
    if (digitalRead(D7) == TRUE){
        Particle.publish("team12_dooropen", "open");  //subscribe to door status
        delay(10000);
    }
    else {
    Particle.publish("team12_doorclosed", "closed");
    delay(10000);
}
}

LED Light Code

C/C++
This is our LED Light Code. The void loops tell the LED when to light up on the second Particle when receiving data from the first Particle.
void setup() { 
Particle.subscribe("team12_dooropen", doorsubscribeopen, MY_DEVICES);
Particle.subscribe("team12_doorclosed",doorsubscribeclosed, MY_DEVICES);
pinMode(A1, OUTPUT);
digitalWrite(A1, HIGH);
delay(500);
digitalWrite(A1,LOW);
}


void doorsubscribeopen(const char *event, const char *data) { 
  
    digitalWrite(A1, 0); 
    delay(10000);
    digitalWrite(A1, 1);
}
void doorsubscribeclosed(const char *event, const char *data) {  
  
    digitalWrite(A1, 1);  
    delay(10000);
    digitalWrite(A1, 0);
}

Credits

Davis Rochester

Davis Rochester

1 project • 1 follower
Nick Shoffner

Nick Shoffner

1 project • 1 follower

Comments