My youngest is now capable of opening exterior doors and while we always tell him not to unlock or open the door without us present we always worry that he might slip out without us seeing or hearing him. So off to the garage!
I used a normally closed door contact, Adafruit PermaProto board, 2 x single row female headers & a terminal block I had in the parts bin.
The Photon sends the Particle.publish message that is sent to Pushover.net via a Webhook and virtually instantly arrives on both my phone and my wife’s phone.
New version I built so that me and the wife can open the door without triggering the alert.
The idea is that the kids are under 5’ tall so I mounted the device so that me and my wife will trigger the sensor as it is setup at about the 5’ tall area. I have the onboard LED set to turn on when it detects us so that we know its safe to open the door without triggering the alert.
New version utilizes a HC SR04 Ultrasonic sensor.
Version 2
V2 Photon Code
#include <HC_SR04.h>
double cm = 0.0;
double inches = 0.0;
int led1 = D7; // we will use the built in LED for a visual door open indicator
int Input1 = D6; // define the pin used for the door sensor
int lastState = 0; // set the default state
String Distance;
// Setup HC-SR04 trig & echo pins
int trigPin = D4;
int echoPin = D5;
HC_SR04 rangefinder = HC_SR04(trigPin, echoPin, 5.0, 61.0);
void setup() {
pinMode(led1, OUTPUT);
pinMode(Input1, INPUT_PULLUP);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Particle.variable("cm", &cm, DOUBLE);
Particle.variable("inches", &inches, DOUBLE);
}
void loop() {
int Input1State;
inches = rangefinder.getDistanceInch();
cm = rangefinder.getDistanceCM();
Distance = String(inches);
delay(100);
Input1State = digitalRead(Input1); // Turn onboard LED on when we are detected by the sensor
if (inches > 2) {
digitalWrite(led1, HIGH);
}
else if (inches == -1) { // turn off onboard LED when we are not detected by the sensor
digitalWrite(led1, LOW);
}
if (((Input1State == HIGH) && (lastState == 0) && (inches == -1))) {
Particle.publish("Offspring_Alert","Back Door Open", 10);
lastState = 1;
}
else if (((Input1State == LOW) && (lastState == 1) && (inches == -1))) {
Particle.publish("Offspring_Alert","Back Door Closed", 10);
lastState = 0;
}
if (((Input1State == HIGH) && (lastState == 0) && (inches >= 2))) {
// Particle.publish("Offspring_Alert","Back Door Opened by Adult", 10);
lastState = 2;
}
else if ((Input1State == LOW) && (lastState == 2)) {
lastState = 0;
}
}
Version 1
V1 Photon Code:
int led1 = D7; // we will use the built in LED for a visual door open indicator
int Input1 = D6; // define the pin used for the door sensor
int lastState = 0; // set the default state
void setup() {
pinMode(led1, OUTPUT);
pinMode(Input1, INPUT_PULLUP);
}
void loop() {
int Input1State;
Input1State = digitalRead(Input1);
if ((Input1State == HIGH) && (lastState == 0)) {
digitalWrite(led1, HIGH);
Particle.publish("Offspring_Alert","Back Door Open", 10);
lastState = 1;
}
else if ((Input1State == LOW) && (lastState == 1)) {
digitalWrite(led1, LOW);
Particle.publish("Offspring_Alert","Back Door Closed", 10);
lastState = 0;
}
}