Photon/Blynk Garage Door Controller

I’ve deployed a garage door controller (two doors). It uses a Photon and the Photon relay shield, magnetic switches for door sensors, and a Blynk cloud app. The app has a button and led status for each door. Fun project. Works great!


Here’s the current GARAGE app code. The project needs to include the BLYNK and SPARKCOREPOLLEDTIMER libraries. You should be able to get an idea from the pins how things are connected/wired, but let me know if you still need a schematic and I’ll post it shortly, I’d need to draw it on a napkin first! You may also need to refer to the relay shield data sheet Make sure you fill in your auth key too.

// This #include statement was automatically added by the Particle IDE.
#include "blynk/blynk.h"
#include "SparkCorePolledTimer/SparkCorePolledTimer.h"

char auth[] = "";

// door 1 sensor and control
const int magSwitch1 = D0;
const int relaySwitch1 = D3;
// door 2 sensor and control
const int magSwitch2 = D1;
const int relaySwitch2 = D4;

// door 1 status
int magStatus1 = 0;
int ledStatus1 = 0;
// door 2 status
int magStatus2 = 0;
int ledStatus2 = 0;

// timeout in milliseconds
SparkCorePolledTimer updateTimer(1000);

void OnTimer(void) {

void setup() {
    while (Blynk.connect() == false) {
        // Wait until connected

    pinMode(relaySwitch1, OUTPUT);
    pinMode(relaySwitch2, OUTPUT);
    pinMode(magSwitch1, INPUT_PULLDOWN);
    pinMode(magSwitch2, INPUT_PULLDOWN);


void sendDoorStatus() {
    Blynk.virtualWrite(V5, ledStatus1);
    Blynk.virtualWrite(V6, ledStatus2);

void loop() {;

    //constantly monitor the door magnetic switch status (garage door open or closed)
    magStatus1 = digitalRead(magSwitch1);
    magStatus2 = digitalRead(magSwitch2);

    if (magStatus1 == HIGH) {
        ledStatus1 = 1023; // 100% brightness
        //Serial.println("LED1: high");
    } else {
        ledStatus1 = 0;
        //Serial.println("LED1: low");
    if (magStatus2 == HIGH) {
        ledStatus2 = 1023;
    } else {
        ledStatus2 = 0;


Looks like a great project. I created a single door Blynk app with a single button. Works great but your code is much better. I would appreciate a “back of a napkin” wiring diagram if you feel like posting one.

Thanks for the share.

So here’s a “back of napkin” wiring diagram.

Please keep in mind that this diagram is in the context of using the Relay Shield. The relay connections are to the Normally Open (NO) and Common terminals.

The door control connections go to the garage door motor switch connectors. The sensor connection digital inputs go to the magnetic switch Normally Open (NO) terminals. The magnetic switch common terminals go to the ground pin connections. There is no polarity to any of these connections though.


You saved me!!! I have been messing with those stupid Virtual LEDs for a week plus now. I’ve been driving those guys at Blynk crazy. Yours was a one and done solution.

Do you mind if I build on it?


1 Like

Yes, please do! Have fun with your project.