Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Trenten DumasDale London
Published

Magnetic reed switch door alarm

Magnetic reed switch that senses when a door is opened and sets off an alarm on a second photon. Using IFTTT to send emails when triggered.

IntermediateFull instructions provided8 hours1,930
Magnetic reed switch door alarm

Things used in this project

Hardware components

Photon
Particle Photon
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×2
Adafruit magnet reed switch
×1
Buzzer
Buzzer
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Schematics

Circuit Diagrams

Circuit setup for two photons. One with a magnetic reed switch attached to pins DO and D1 and the second with a buzzer attached to pins D7 and GND.

Code

Reed switch code

C/C++
Code that reads the voltage drop when the reed switch is opened and publishes a door status event of "DOOR OPEN" on the particle console page.
int DAP = D0;
int DAR = D1;
int boardLed = D7;

void setup() {

pinMode(DAP,OUTPUT);
pinMode(DAR,INPUT);

  

}

void loop() {

while (Particle.connected()){

if(digitalRead(DAR)==HIGH){

Particle.publish("doorStatus","DOOR OPEN",60);
delay(2000);
}
else{
delay(400);
}
}
}

Buzzer alarm code

C/C++
This code supplies power to the D7 node on a second photon when a "DOOR OPEN" event status is posted on the particle console page.
int led = D7;

void setup() {
     Serial.begin(230400);
    pinMode(led, OUTPUT);
 
  
  Particle.subscribe("doorStatus", myHandler);

}

void myHandler(const char *event, const char *data)
{
  
     if(strcmp(data,"DOOR OPEN")==0){
        
        digitalWrite(led, HIGH);
        delay(5000);
        digitalWrite(led,LOW);
}
}

Credits

Trenten Dumas

Trenten Dumas

-1 projects • 1 follower
Dale London

Dale London

-1 projects • 1 follower

Comments