I am trying to have my garage door SMS me when the door has been open for ten minutes.
I took the code from here.
https://www.circuitspecialists.com/blog/diy-smartphone-garage-opener-with-status/
I changed his code so when the door is closed the reed switch will read LOW and will read High when open
The problem is that that the time intervals between texts are as follows; 15,17,6,44,21,12,3,15,8,23,29,15(this last one I got two texts at the same time) minutes between texts. Once Particle publishes “garageStatus” IFTTT texts me
The code I’m using is this
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
char auth[] = "30c7d03a598a436c837f5ed187f9eb73";
int reedSwitch = D4; //input for the reed switch - detects open/closed status
bool current = 0; //logical placeholder - current status of the garage
bool previous = 1; //logical placeholder - previous status of the garage
int seconds = 0;
int openlimit = 600; //number of seconds before text sent indicating garage open
void setup()
{
Serial.begin(9600); //begin serial communication
Blynk.begin(auth); //begin Blynk app communication
pinMode(D0, OUTPUT); //initialize D0 as output pin - relay coil control
pinMode(D4,INPUT); //initialize reedswitch pin as input
}
void loop()
{
Blynk.run(); //run Blynk app
current = digitalRead(reedSwitch); //set current status open/closed
if (current != previous){ //only run if there is a status change from previous state
previous = current; //reinitialize
if (digitalRead(reedSwitch) == LOW) { //is signal HIGH? i.e. garage is closed
delay(500);
Particle.publish("garageStatus","closed",60,PRIVATE); //this line commented out as closed status not of interest
}
else {
// Otherwise, this isn't a new status, and we don't have to do anything.
}
if (digitalRead(reedSwitch) == HIGH) { //is signal LOW? i.e. garage is open
delay(500);
while (seconds < openlimit && digitalRead(reedSwitch) == HIGH){ //while loop to publish only if garage is open more than ten minutes
++seconds;
delay(1000);
if (seconds ==599){
Particle.publish("garageStatus","open",60,PRIVATE); //send to spark publish which then triggers text via IFTTT
seconds = 0;
}
}
}
else {
// Otherwise, this isn't a new status, and we don't have to do anything.
}
delay(500);
}
}
Aside from the timing issues my other questions are,
if in IFTTT if I have not just “garageStatus” but “garageStatus open” or “garageStatus” “open” that I can differentiate between open and closed so I can get notifided once it closes.
Last question is about adding another garage door. I think I should duplicate the same code add another pin for input and say “garagetwo” for publishing. Does that sound correct?
Thank you,
Doug