Set pin value = 1 and immediately after = 0 (like a button on push mode) through web request (IFTTT+Webhooks)

Thank you very much @Gunner Gunner!

I installed the simple timer and made it work flawless. Some minutes ago I had succeeded using a delay funtion (thanks to this topic I found: Virtual pin to control momentary latch relay) and trigging the virtual pin trough webhook to change the state of the digital pin, but now its even better with the timer your time function.

I have some comments about the code though, for whoever needs it in the future:

1 - After setting the digital pin low, it’s better to set the virtual pin low as well.
2 - It’s necessary to add the timer funcion to the void loop to make the timer work.

And you are right about investing in some coding to really utilise the power of Blynk!

Thanks also to @wanek wanek and @scropion86

Working Code:

...(other libraries)+
#include <SimpleTimer.h>
SimpleTimer timer;

void setup() { 
 ...(other confings) +

pinMode (14, OUTPUT);

}

BLYNK_WRITE(V1) {
   if (param.asInt()==1){  // act only on the HIGH and not the LOW of the momentary
    digitalWrite(14, !digitalRead(14));  // invert pin state just once
    timer.setTimeout(100L, [](){
    digitalWrite(14, !digitalRead(14));  // then invert it back after 100ms
  Blynk.virtualWrite(V1, LOW);
//    });
  
    });
    }
}

void loop() {
  
  Blynk.run();
  timer.run();
}
3 Likes