Author Topic: Monitor two garage doors - working!  (Read 7568 times)


  • Newbie
  • *
  • Posts: 41
Monitor two garage doors - working!
« on: September 14, 2016, 06:01:26 pm »
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
  * 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() {
  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);
    digitalWrite(1, LOW);

 * 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);
          Particle.publish("Door 1 Status", "Open", PRIVATE);
        if (digitalRead(Door2Switch) == LOW) {
          Particle.publish("Door 2 Status", "Closed", PRIVATE);
          Particle.publish("Door 2 Status", "Open", PRIVATE);
« Last Edit: September 14, 2016, 06:10:14 pm by ScottM »


  • Jr. Member
  • **
  • Posts: 87
Re: Monitor two garage doors - working!
« Reply #1 on: December 18, 2016, 11:35:32 am »
Hey Scott,

If you're interested in having push notifications sent to your phone (either by txt or email) you should check out a cloud service called Carriots

It's moderately complicated, but they have a couple of decent tutorials. The key feature is that your Oak could send data to their server when ever your garage door opens, and their server would send either a text or email to your phone.

Something else you might want to look at is the concept of interrupts. Instead of having your Oak polling the pins ever 5 sec you could tell it to listen for any changes in those pins. A change, either going high or going low, would launch a function that tells either Particle or Carriots that the door opened. I've played with interrupts it a few times but haven't had a lot of success.