Joel HofflerJack Martin
Published

3171 Door Sensor Project

This project uses two Particle Argon's, a magnetic switch, and an LED to signal when a door opens.

IntermediateShowcase (no instructions)108
3171 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
Breadboard (generic)
Breadboard (generic)
×1
Argon
Particle Argon
×1

Story

Read more

Schematics

LED Diagram

Magnet Switch Diagram

Flow Chart

Live Data

The particle event log uploads to Google Sheets, which we transferred to Excel. This graph tracks the amount of time the door is open per day during a given week.

Code

LED Code

C/C++
We used two Particle.subscribe commands to be able to communicate between the argon kits. These two void loops tell the LED what to do when the switch is open vs closed.
void setup() { 
Particle.subscribe("team47_dooropen", doorsubscribeopen, MY_DEVICES);
Particle.subscribe("team47_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, 1); 
    delay(10000);
    digitalWrite(A1, 0);
}
void doorsubscribeclosed(const char *event, const char *data) {  
  
    digitalWrite(A1, 0);  
    delay(10000);
    digitalWrite(A1, 1);
}

Magnet Switch Code

C/C++
We used two Particle.publish commands to publish events to the console. One makes the event read "open," and the other makes the event read "closed."
void setup() {
    pinMode(D7,INPUT_PULLUP); //configure D7 to input with an internal resistor pullup.
}

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

Credits

Joel Hoffler
1 project • 0 followers
Contact
Jack Martin
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.