BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

A timeout issue with Garage Door Opener Please Help


#1

Hello all,
I tried to use timer.setTimeout but cannot figgure how to use it for my needs.
I would like to Push the Button Widget and have the D12 pin set or reset as needed. But I don’t want another push until 30 seconds have passed (give the garage door time to fully open or close.)

MacOS High Sierra 10.13.5
Arduino IDE 1.8.5
Blynk v0.5.2 on ESP-12
Adafruit Feather HUZZAH with ESP8266 https://bit.ly/2zHqWvd
iPhone 11.3.1

BLYNK_WRITE(V12)  // Garage Door # 2
{
  if (param.asInt() == 0)  {   //  get bool status of V12
    digitalWrite(12, LOW); //GPIO12
  }
  else {
    digitalWrite(12, HIGH); // GPIO12
  }
}


#2

There are lots of ways to do it, but I’d use a flag to indicate that the door is in motion.
Set the flag to false at start-up. When your V12 button is pressed, check if the flag is false. If it is then set it to true, start your timer and activate your digital pin.
When the timer completed then set the flag to false again.

If the button is pressed when the flag I should true then you do nothing.

Pete.


#3

Thank you I working on it. I have been programming for several years, but so infrequently (hobby) that I never was proficient . But I working on it. Just as much fun!
Thanks.


#4

I have some examples of timers here…

Something like this should work for you (untested)…

int doorTimer = 0;
BLYNK_WRITE(V12)  // Garage Door # 2  Button set as switch
{
  if (doorTimer == 0) { // Run if Flag is LOW
    doorTimer = 1;  // Set Flag
    // Timed Lambda Function - Flag reset
    timer.setTimeout(30000L, []() {  // Run Flag reset in 30 seconds, meanwhile carry on...
      doorTimer = 0;
    });  // END Timer Function
    if (param.asInt() == 0)  {   // Run if state of V12 is LOW (and Flag is LOW)
      digitalWrite(12, LOW); //GPIO12
    }
    else {   // Run if state of V12 is HIGH (and Flag is LOW)
      digitalWrite(12, HIGH); // GPIO12
    }
  }
}

However it will not take into consideration what the current button/switch state is, so it is possible to switch from one state to another within the 30 seconds, and get stuck “reopening” an open door for another 30 seconds, etc. :stuck_out_tongue:

A better way would be more logic or different way of triggering (momentary button to trigger another door state flag to open if closed or close if opened, etc.)


#6

FYI, the above example was more for showing one way on how a timeout timer can be setup… not so much as a fully functional option :stuck_out_tongue:


#7

Thank you for your help . I Added this to my script and it never goes LOW. I must be missing something but I don’t see it. If you can help me again my family will be so proud of me.

BLYNK_WRITE(V12) // Garage Door # 2 Button set as switch
{
if (doorTimer == 0) { // Run if Flag is LOW
doorTimer = 1; // Set Flag
// Timed Lambda Function - Flag reset
timer.setTimeout(5000L, { // Run Flag reset in 30 seconds, meanwhile carry on…
doorTimer = 0;
}); // END Timer Function
if (param.asInt() == 0) { // Run if state of V12 is LOW (and Flag is LOW)
digitalWrite(12, LOW); //GPIO12
Serial.println(" 12 LOW “);
}
else { // Run if state of V12 is HIGH (and Flag is LOW)
digitalWrite(12, HIGH); // GPIO12
Serial.println(” 12 HIGH ");
}
}
}

#8

For formatting posted code in this forum, use backticks, not commas or other characters.

Blynk - FTFC


#9

Is the button in switch mode?

The BLYNK_WRITE() function gets called every state change, so if the button is set as a momentary, then the function would get called twice (for press and release) and thus the OFF mode would never get recognised as first state change (ON mode) would start the timer and process the ON part of the if()… but the timeout timer would prevent the OFF function from being red for 30 seconds… meaning you would have to HOLD the button down for 31 seconds (or over 5 in your test) before releasing and thus shutting the door.

As mentioned… just a quick, untested, example to show the timer more than anything else…


#10

Thanks,
It works as it should.
It’s a let down when the script does what I told it to do but not what I wanted to do.

I wanted to push the button and the door would move. At that point set the D12 LOW. Because the door will move up or down or stop depending on the last movement.

So my code works with button as a push. I can just leave it there for phase One. And this project is done.

When I get this project complete with pictures and complete code I will post it in the community.

Thanks again