[SOLVED] Sync physical button to other ESP's

Hi all.
I need sketch for ESP8266 (nodemcu) to sync physical button on other ESP’s. for example when I pushed physical button on one ESP, then all other ESP’s GPIO2 turning on.

thanks & sorry for bad english

I believe this is what you want.

1 Like

thanks for reply. but I need for ESP and how this work ? which pin is for physical button and which for GPIO2 ?

You may use this example with little changes with ESP - https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=Widgets%2FBridge

1 Like

thanks for reply. I solved my problem with Eventor. I set same auth token on all esp with eventor
and final question: How can I change physical button mode to push in sketch ?

You mean pin mode?

1 Like

No. when I pushed physical button the LED is keep on but I want turn on a moment

You need to send 2 commands. One with HIGH and second one with LOW.

Can you help me to edit my sketch ?

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
//#define BLYNK_PRINT Serial // Defines the object that is used for printing
//#define BLYNK_DEBUG        // Optional, this enables more detailed prints

#define VPIN V2

char auth[] = "xxxx"; //blynk auth token

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxx";
char pass[] = "xxxx";

void lightOn();
void lightOff();

boolean LampState = 0;
boolean SwitchReset = true;

const int TacSwitch = D5; 
const int RelayPin = D6; 

SimpleTimer timer;
WidgetLED VLED(V12);

void setup()      
  pinMode(RelayPin, OUTPUT);
  pinMode(TacSwitch, INPUT_PULLUP);
  digitalWrite(RelayPin, LOW);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(100, ButtonCheck);
void loop()
void ButtonCheck() {
  boolean SwitchState = (digitalRead(TacSwitch));
  if (!SwitchState && SwitchReset == true) {
    if (LampState) {
    } else {
    SwitchReset = false;
  else if (SwitchState) {
    SwitchReset = true;
void ToggleRelay() {
  LampState = !LampState;
  if (LampState) {
  else lightOff();
void lightOn() {
    digitalWrite(RelayPin, LOW);
    LampState = 1;
    Blynk.virtualWrite(VPIN, HIGH); 
void lightOff() {
    digitalWrite(RelayPin, HIGH);
    LampState = 0;
    Blynk.virtualWrite(VPIN, LOW); 
  int SwitchStatus = param.asInt();
    if (SwitchStatus == 2){
  else if (SwitchStatus){
  else lightOff();

Can anyone help me ? :disappointed:

Help you with what exactly?

Please realise that most everyone here have their own code/project/life to troubleshoot, so not too many can take the time to sift through your entire code to first find and then fix whatever is apparently wrong.

1 Like

Help me how to add push mode physical key to my sketch !

Have you checked out any of the Sketch Builder examples?


1 Like

Its worked but I need timer on pushed button. I want to turn on GPIO for 5 second when I pushed physical button

Well you are already using timers, so you should understand how to add another to run for 5 seconds, after button push, and then turn off GPIO 5.

Here is one example of a basic timer snippet for an Action - Delay - Action function:

BLYNK_WRITE(Vx) {  // Virtual button on Vx to activate action
  int BTN = param.asInt();
  if (BTN == 1) {
    ActionON;  // Run ActionON function

void ActionON() {
  digitalWrite(pin, HIGH);  // Set pin high
  timer.setTimer(5000L, ActionOFF);  // Run ActionOFF function in 5 seconds

void ActionOFF() {
  digitalWrite(pin, LOW);  // Set pin Low
1 Like

thanks the problem is solved.
May God be pleased with you :tulip:

1 Like