Garage door open & close states


I have a nodemcu based garage door opener with an open and closed limit switch.
In blynk i have a button to activate the servo which pushes the button on the fob and then 3 leds.
One LED illuminates when the OPEN limit switch is active, one illuminates when the Closed limit swtich is active and a 3rd for ‘UNKNOWN’ which is where i need some help

I have searched high and low for the past few weeks but cant seem to resolve my problem

The door takes max 2 minutes to open. I want the ‘UNKNOWN’ state (which is when both OPEN & CLOSED limit switches are inactive) to illuminate, but only after say 3 minutes. This works, however i am now getting overlapping timers. Sometimes the UNKNOWN state illuminates immediately after a state change which i’m guessing is because a previous timer is running.

I feel like i’m missing something blaringly obvious, and possibly havent approached it the right way. This is a bout the millionth variation i’ve attempted.

Any help would be greatly appreciated.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

char auth[] = "xxxx"; //installed board

char ssid[] = "xxxx";
char pass[] = "xxxx";

BlynkTimer timer;

WidgetLED led3(V15); //open status
WidgetLED led4(V14); // closed status
WidgetLED led5(V16); // unknown status

Servo servo;

int Latch;
int Flag;
int Flag1;
String displaywifi;
int wifisignal;

const int limitswitch_OPEN = 0;   //taging limitswitch sense line to GPIO0 pin
const int limitswitch_CLOSED = 4; //taging limitswitch sense line to GPIO2 pin
boolean limitstate_OPEN = false;
boolean limitstate_CLOSED = false;
boolean limitstate_Unknown = false;

void setup() {
  pinMode(limitswitch_OPEN, INPUT_PULLUP);
  pinMode(limitswitch_CLOSED, INPUT);
  Blynk.begin(auth, ssid, pass);  

  servo.attach(12); // 12 means D6 pin of ESP8266
  digitalWrite(5, HIGH);
  Flag1 = 0;

  timer.setInterval(500L, buttonLedWidget_OPEN);
  timer.setInterval(500L, buttonLedWidget_CLOSED);

  timer.setInterval(10000L, sendwifi);
  digitalWrite(LED_BUILTIN, HIGH);  

void loop()
{; // You can inject your own code or combine it with other sketches.;

BLYNK_WRITE(V3) //Virtaul button on V3 to activate servo
  Latch = param.asInt();
  if (Latch == 1 && Flag == 0) {
    Flag = 1;  // Keeps from allowing button press more then once while relay activated
    if(param.asInt()==1) { // Activate servo
    timer.setTimeout(2000L, turnSERVOoff);  // Deactivare Relay after 3 seconds
  }  // END if
}  // END Blynk Function

void turnSERVOoff() {
  servo.write(0); // deActivate servo
  Flag = 0;  // reset flag after relay disables
}  // END Function

void buttonLedWidget_OPEN()
  // Read button
  boolean isPressed = (digitalRead(limitswitch_OPEN) == LOW);

  // If state has changed...
  if (isPressed != limitstate_OPEN) {
    if (isPressed) {;
      Blynk.notify("Garage Door Is Open");"","Subject: Garage door is Open","Garage Door Has been Opened");
    } else {;
      Flag1 = 0;
      timer.setInterval(180000L, buttonLedWidget_Unknown);
    limitstate_OPEN = isPressed;

void buttonLedWidget_CLOSED()
  // Read button
  boolean isPressed = (digitalRead(limitswitch_CLOSED) == LOW);

  // If state has changed...
  if (isPressed != limitstate_CLOSED) {
    if (isPressed) {;
      Blynk.notify("Garage Door Is Closed");"","Subject: Garage door is Closed","Garage Door is Closed");
    } else {;
      Flag1 = 0;
      timer.setInterval(180000L, buttonLedWidget_Unknown);
    limitstate_CLOSED = isPressed;

void buttonLedWidget_Unknown()
  if(Flag1  ==0){
    Flag1 = 1;
    if(digitalRead(limitswitch_CLOSED)==HIGH && digitalRead(limitswitch_OPEN)==HIGH){
      Blynk.notify("Garage Door Is UNKNOWN");"","Subject: Garage door is UNKNOWN","Garage Door is UNKNOWN");
      Flag1 = 0;

void sendwifi()
  wifisignal = map(WiFi.RSSI(), -105, -40, 0, 100);
  displaywifi = String("     Signal:  ") + wifisignal +String(" %");
  Blynk.setProperty(V3, "label", displaywifi);

I think you need to be using one- shoot timeout timers rather than a timer that runs all the time.

Also, the idea of using a servo to activate the remote control sounds a bit primitive. I’d either be sending the correct 433mhz signal from the NodeMCU, or interfacing with the door controller via a relay (most controllers have contacts for a manual open/close switch inside the garage.

A quick search of the forum will give lots of examples of garage door opener projects with notifications when the door is left open.


So simple. Thanks Pete. Already had that too in the servo piece of code.

Our door opener is quite new and they offer a automated/phone controller extra. As such they’ve locked down both the RF option and also the contacts on the motor

I doubt if the RF is locked-down, unless it used a true rolling code system - which is very unlikely.
The RC Switch library and a 433MHz receiver module is a good place to start sniffing the protocol.
If that doesn’t give anything then connecting the 433 Rx to your sound card and running Audacity will probably allow you to crack it.

This is what I did for my remote controlled sun blinds and now I have full Blynk and Alexa control over them.