Corey WorkmanCharles Lee Phelps
Created April 10, 2017

Wifi Connected Garage

Stay connected to your garage when you are away!

BeginnerFull instructions provided2 hours35
Wifi Connected Garage

Things used in this project

Hardware components

Photon
Particle Photon
×2
Resistor 330 ohm
Resistor 330 ohm
×2
Relay (generic)
×1
LED (generic)
LED (generic)
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Proximity Sensor
Proximity Sensor
×2

Software apps and online services

Particle

Story

Read more

Schematics

Photon 1 Circuit Diagram

Photon 2 Circuit Diagram

Code

Particle Photon 1: Control/Monitor

C/C++
This photon controls the relay to activate the garage door. It also monitors the position of the door by reading the values of the magnetic switches. When the garage is triggered, an event is published in order to connect to the second photon.
int Garage_Door = D0;
int reed1 = D1;
int reed2 = D2;
int val1 = 0;
int val2 = 0;
int doorstatus = 0;
String Position;
char*Position1 = "closed";
char*Position2 = "open";
char*Position3 = "limbo";

void setup() {
    pinMode(Garage_Door, OUTPUT);
    pinMode(reed1, INPUT_PULLUP);
    pinMode(reed2, INPUT_PULLUP);
    Particle.function("Garage_Door", Trigger);
    Particle.variable("Position", Position);
}

int Trigger(String command) {
    if (command == "open" && val1 == LOW) {
        Particle.publish("MEGR3171GROUP42", "Garage_Triggered");
        digitalWrite(Garage_Door, HIGH);
        delay(250);
        digitalWrite(Garage_Door, LOW);
        return 1;
    }
    else if (command == "close" && val2 == LOW) {
        Particle.publish("MEGR3171GROUP42", "Garage_Triggered");
        digitalWrite(Garage_Door, HIGH);
        delay(250);
        digitalWrite(Garage_Door, LOW);
        return 0;
    }
    else {
        return -1;
    }
}

    
void loop() {
    val1 = digitalRead(reed1);
    val2 = digitalRead(reed2);
  
    if (val1 == 0 && val2 == 1) {
        if (doorstatus == 0) {
            String state = String(doorstatus);
            Particle.publish("State", state, PRIVATE);
        }
    doorstatus = 1;
    Position = Position1;
    }

    if (val1 == 1 && val2 == 0) {
        if (doorstatus == 1) {
            String state = String(doorstatus);
            Particle.publish("State", state, PRIVATE);
        }
    doorstatus = 0;
    Position = Position2;
    }

    if (val1 == 0 && val2 == 0) {
        Position = Position3;
    }

    if (val1 == 1 && val2 == 1) {
        Position = Position3;
    }

}

Particle Photon 2: LED

C/C++
This photon subscribes to the published events sent from photon one. When an event is publish, a LED is set high for five seconds.
void setup() {
    pinMode(D7,OUTPUT);
    Particle.subscribe("MEGR3171GROUP42",myHandler);
    digitalWrite(D7,LOW);
}

void loop() {
}

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

Credits

Corey Workman

Corey Workman

1 project • 0 followers
Charles Lee Phelps

Charles Lee Phelps

1 project • 0 followers

Comments