Monitoring my two garage doors is my first official OAK project. Basically it is up and running, but I'd like to enhance the project if I can. What I'd like is to monitor the doors with an app on my Android phone and better than that, I'd like the system to send me a door open text message if I put it into a special mode, such as when I'm away from home.
My code is below. Please feel free to offer comments and ideas, especially on how to make it better.
/*Program to monitor double garage doors
*
* by: Scott Murchison
*
ottawamaker@gmail.com *
* To monitor my two garage doors, I installed magnetic switches
* beside each door. The magnets are mounted on the doors themselves.
* When the doors are closed, the magnets are right next to the
* switches and that causes the switch to close. On the OAK, I have
* one switch wired between P3 and GND and the other between P4 and GND.
* I configured P3 and P4 as INPUT_PULLUP so that when the doors open, the
* inputs are pulled high.
*/
int Door1Switch = 3;
int Door2Switch = 4;
int Door1Status = 5;
int Door2Status = 5;
void setup() {
Particle.begin();
pinMode(1, OUTPUT); //LED on Oak
pinMode(Door1Switch, INPUT_PULLUP); //Switch on door 1
pinMode(Door2Switch, INPUT_PULLUP); //Switch on door 2
}
void loop() {
//flash LED twice
for (int i = 1; i < 3; i++) {
digitalWrite(1, HIGH);
delay(300);
digitalWrite(1, LOW);
delay(130);
/*
* Get status of door switches. This is useful to see the actual
* result of the digitalRead calls. They will give you 0 or 1. After
* you verify that your switches are working, you can comment it
* out like I did.
*/
// Door1Status = digitalRead(Door1Switch);
// Particle.println("Door 1 Status: ");
// Particle.println(Door1Status);
// Particle.println(" - ");
// Door2Status = digitalRead(Door2Switch);
// Particle.println("Door 2 Status: ");
// Particle.println(Door2Status);
// Now loop through checking each door
if (digitalRead(Door1Switch) == LOW) {
Particle.publish("Door 1 Status", "Closed", PRIVATE);
}
else
{
Particle.publish("Door 1 Status", "Open", PRIVATE);
}
if (digitalRead(Door2Switch) == LOW) {
Particle.publish("Door 2 Status", "Closed", PRIVATE);
}
else
{
Particle.publish("Door 2 Status", "Open", PRIVATE);
}
}
delay(5000);
}