Simulating a PUSH button for GearBlynk



Hi guys, maybe it’s a small project for this community, but for sure there are some other noobs (like me) looking for this solution. I’m not sure if it’s perfect, but for me works well.
This simulation was needed especially for GearBlynk app. I have to control a gate using a push button only. The button should be active for ~1 second. GearBlynk doesn’t have this push/ switch button option, so i’ve done this. Also, even for the phone app, it’s more easy to press the button once and let the code do the job for you (keep the pin active for ~1.5 seconds then switch it off).

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "xxxxxx";
char ssid[] = "xxxx";
char pass[] = "xxxxx";


int Relay_Pin = 0;  // Connect the relay to GPIO0 

BLYNK_WRITE(V1)                             // This code is triggered when the App button widget on V1 changes state
  int pinValue = param.asInt();             // Assign incoming value from pin V1 to a variable

  if (pinValue==1)                          // Do this if it was an On command from the Button widget in the App
    Blynk.virtualWrite(V1, HIGH);   // Change the app button state and keep it ON while you remove the finger - for visual feedback
    digitalWrite(Relay_Pin, HIGH);          // Turn the relay On
    delay (1350);                            // Wait for 1.35 sec
    digitalWrite(Relay_Pin, LOW);  // Turn the relay Off
    Blynk.virtualWrite(V1, LOW);  //Change the app button state to OFF
  else                                      // Else do this if it was an Off command from the Button widget in the App
    digitalWrite(Relay_Pin, LOW);           // Turn/ Keep the relay Off

void setup()
  pinMode(Relay_Pin, OUTPUT);                  // Define the relay pin as an output
  Blynk.begin(auth, ssid, pass);

void loop()


GearBlynk - standalone app and widget for Samsung Gear S3 smartwatch series

While it may work in shorter durations, delay() is just plain bad programming form with regards to Blynk and any other timing sensitive processes. As has been referenced many times in this forum and documentation, for all no0Bs to read :wink: BlynkTimer (based on SimpleTimer) is the prefered method.

For example, non-blocking timer controlled button action is the prefered way to make a “Timed Button”