Things used in this project

Hardware components:
Photon new
Particle Photon
×1
Relay Shield
×1
Power Supply 7-15v 1A 5.5mm Barrel Jack
×1
Reed Switch
×1
Super Neodymium Disc Magnet
×1
Software apps and online services:
Q8wtlimqnp04fzhtr9v5
IFTTT Maker service
IFTTT Do Button

Schematics

Simple Garage Opener Schematic for Reed Switch wiring
Very simple connections. You should be able to zoom in on the pic for a closer look and follow how it is wired.
Simple Schematic
Zoom in and you will see exactly how to wire this. Not wiring needed if you don't do the reed switch to sense open or closed.
Reed Switch with super magnet
Used a NeoDyn magnet for door side of reed switch for clearance when door operates. Also made for a quick and easy install!
Reedandmagnet

Code

Particle Code (also in manual)C/C++
Paste this code into Particle.io Build Screen, Verify, then Flash the Photon chip with it. If you tried this and it didn't work, try again. Looks like how strings were handled changed so I had to update this on 10/13. Thanks to Jason Millard for the code assist!
// This #include statement was automatically added by the Particle IDE.
#include "RelayShield/RelayShield.h"

// Create an instance of the RelayShield library, so we have something to talk to
RelayShield myRelays;

// Create prototypes of the Spark.functions we'll declare in setup()
int relayOn(String command);
int relayOff(String command);
int checkStatus(String command);

//pin initializations
const int pinReedSensor = A0;

// Initialize a generic message in case we don't get a real status lower.
const char* STATUS_MESSAGE_UNAVAILABLE = "Status unavailable.";
const char* STATUS_MESSAGE_CLOSED = "Closed";
const char* STATUS_MESSAGE_OPEN = "Open";

void setup() {
    
    //.begin() sets up a couple of things and is necessary to use the rest of the functions
    myRelays.begin();

    // Register Spark.functions and assign them names
    Particle.function("relayOn", relayOn);
    Particle.function("relayOff", relayOff);
    Particle.function("toggleRelay", toggleRelay);
    Particle.function("checkStatus", checkStatus);
    // door reed sensor - this is visible from an IFTTT check if you wish
    Particle.variable("doorStatus", STATUS_MESSAGE_UNAVAILABLE, STRING);

}
//sense if door is open or not in this loop.
void loop() {
    // loop over Reed switch status to see if doors are open or closed.

    const char* message = STATUS_MESSAGE_UNAVAILABLE;
    
    if(digitalRead(pinReedSensor) ==1){
        // Left door closed (removed code for right to simplify)
        message = STATUS_MESSAGE_CLOSED; 
    }
    
    if(digitalRead(pinReedSensor) ==0){
        // door open
        message = STATUS_MESSAGE_OPEN;
    }    
   
    // this constantly sets the variable for dooStatus that can be seen by IFTTT
    Particle.variable("doorStatus", message, STRING);
}

// function to check door status that we can use from DO Button app.  
//  Same as in loop, but only checks when called.  
//  The DO Button calls this, and raises a Spark.publish("status") variable which IFTTT listens for.
//  This is what allows you to call the function via your iPhone or Apple Watch, and in about a second, get an answer.
int checkStatus(String command){
    // Ritual incantation to convert String into Int
    char inputStr[64];
    command.toCharArray(inputStr,64);
    
    const char* message = STATUS_MESSAGE_UNAVAILABLE;
    
    if(digitalRead(pinReedSensor) ==1){
        // Left door closed
        message = STATUS_MESSAGE_CLOSED;
    }
    
    if(digitalRead(pinReedSensor) ==0){
        // door open
        message = STATUS_MESSAGE_OPEN;
    }    
   
    Particle.publish("status", message);
    return 1;
}

int relayOn(String command){
    // Ritual incantation to convert String into Int
    char inputStr[64];
    command.toCharArray(inputStr,64);
    int i = atoi(inputStr);
    
    // Turn the desired relay on.  
    // From your Do Button config, call the relay, and pass in 1 through 4 for the Relay to turn on.
    myRelays.on(i);
    
    // Respond
    return 1;    
}

// Momentarily turn on, then off the relay you want.  This simulates a button press when you hook the 
// physical button to the normally open (two left) leads on the relay.  Again, pass in the number of the relay to control.
// In IFTTT Do Button app, call the Photon, then point the function to toggleRelay, and in the arguments field, jut put a 1 for example.
int toggleRelay(String command){
    // Ritual incantation to convert String into Int
    char inputStr[64];
    command.toCharArray(inputStr,64);
    int i = atoi(inputStr);
    
    // Turn the desired relay on
    myRelays.on(i);
    delay(500);
    myRelays.off(i);
    // Respond
    return 1;    
}

//  This is used in toggleRelay, however, it can also be used stand alone if you have a normally closed relay and want
//  to temporarily open it.
int relayOff(String command){
    // Ritual incantation to convert String into Int
    char inputStr[64];
    command.toCharArray(inputStr,64);
    int i = atoi(inputStr);
    
    // Turn the desired relay off
    myRelays.off(i);
    
    // Respond
    return 1;    
}

Credits

Rickbirthday
Rick Troiani

IT Directory who still loves to play.

Contact
Thanks to David Gatti.

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Whats My I2C Address?
Easy
  • 20
  • 1

Protip

The story of how a Brix will be a clock by using an LCD 1602 or LCD 2004 over I2C.

MyHumidity Controlled by BME280 and Photon
Easy
  • 98
  • 2

Full instructions

Checks if humidity threshold is reached and informs the user by using Blynk/IFTTT-services with softAP integration.

MyLight-Clock with NeoPixel Ring 12 Controlled by Photon
Easy
  • 244
  • 2

Full instructions

Read the time at night? Without glasses? Impossible? Focus on 2 light points, which will tell you the hour and the minute.

Map Your Particles!
Easy
  • 1,318
  • 20

Protip

Locate your Particle Photons, P1s and Electrons on a map without needing extra hardware. Use Ubidots or an offline map alternative

Cheapest Smart Home for $38
Easy
  • 7,022
  • 27

Full instructions

Use Raspberry Pi Zero W to make the cheapest and easiest yet very useful smart home automation for $38 only and no skills needed!

BME280 measures and displays on OLED controlled by Photon
Easy
  • 314
  • 2

Protip

I share my first steps with the sensor BME280 (temp / humi / pressure / altitude) and an OLED 128 * 64 px

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login