Timed button

Hi.
I have a button that activates a relay. But i wan’t to achieve something like a timed button.
When i press my button on the blynk app, a timer would start and after 3 seconds the relay would go LOW no matter what the button is doing. i.e if the wifi hangs or looses its connection when the button is beeing pressed.

Is this something that can be achieved?

Hope that this makes sense :stuck_out_tongue:

Simple. Setup a timer in your button function, then when button pressed it will start a timer that runs a relay function.

http://docs.blynk.cc/#blynk-firmware-blynktimer

timer.setTimer(3000L, ActivateRelay, 1);  // in 3 seconds run the void ActivateRelay() once

As for the whole “keep the sketch running if WiFi disconnects”… that is another process.

http://docs.blynk.cc/#blynk-firmware-configuration-blynkconfig

http://docs.blynk.cc/#blynk-firmware-connection-management

1 Like

Not sure where to put that line. I dont have a button function?

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
 
 
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "**********************************";
 
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***********";
char pass[] = "***********";
 
void setup()
{
  Serial.begin(115200);
   Blynk.begin(auth, ssid, pass);
}
 
void loop()
{
 Blynk.run();
}

@redkite Blynkers don’t generally have the time to go looking at pastebin. Next time ensure you post your formatted code in the thread like this:

//test 
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
 
 
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "**********************************";
 
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***********";
char pass[] = "***********";
 
void setup()
{
  Serial.begin(115200);
   Blynk.begin(auth, ssid, pass);
}
 
void loop()
{
 Blynk.run();
}

I tried to paste my code here, but the # messed up the code

It’s well documented how to post formatted code to this site.

Looks like you are using the simple direct pin control. That will work for basics, but once you start wanting to do timing, more intense logic, etc. then you need the virtual pins, codeing and functions. Reading the Documentation and Help Center and looking at the Sketch Builder (all those links located at the upper right of this page) will get you started.