Sync Phisical Button

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

#include <SoftwareSerial.h>

char auth[] = "injNDPE8b3xILv8aGcuMlJJ55cvnqswO";
char ssid[] = "WiFi-EMR-2.4GHz";                           //WiFi que quiero conectar al Esp8266
char pass[] = "martinfierro897";                           //Contraseña del WiFi

const int btnPin = D2;          
const int RelayPin = D4;         

BlynkTimer timer;
void checkPhysicalButton();
int btnPinState = LOW;           // ON
int RelayPinState = HIGH;

#define TURN_ON 0                 // TURN_ON and TURN_OFF are defined to account for Active High relays
#define TURN_OFF 1                // Used to switch relay states

void setup()
  Serial.begin (9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(RelayPin, OUTPUT);            //  initialize your pin as output.
  pinMode(btnPin, INPUT_PULLUP);        //  initialize your pin as input with enable internal pull-up resistor "input_pullup"
  digitalWrite(RelayPin, RelayPinState);
  digitalWrite(RelayPin, TURN_OFF);     // remain off till command is receive

  // Setup a function to be called every 100 ms
  timer.setInterval(100L, checkPhysicalButton);

// Every time we connect to the cloud...
  // Request the latest state from the server

// When App button is pushed - switch the state
// Map this Virtual Pin to your Mobile Blynk apps widget.
  RelayPinState = param.asInt();
  digitalWrite(RelayPin, RelayPinState);

void checkPhysicalButton()
  if (digitalRead(btnPin) == LOW)
    // btnPinState is used to avoid sequential toggles
    if (btnPinState != LOW)
      // Toggle relay state
      RelayPinState = !RelayPinState;
      digitalWrite(RelayPin, RelayPinState);
      Blynk.virtualWrite(V1, RelayPinState);  //Update button widget

    btnPinState = LOW; 
    btnPinState = HIGH;

void loop()
{;                               // Run Blynk;                               // Run SimpleTimer

Hello, my project is about turning a 220v light on and off through my Blynk app and a home switch.
I managed to make it work but I would like the light to be able to turn on and off with the switch when receiving a positive pulse as zero.
With the programming that you carry out, it only changes state when it receives a LOW pulse at the D2 input of the Wemos D1.

For that type of functionality, you’d be better attaching a CHANGE interrupt to pin D2, and having some debounce code in your ISR routine.


What would an interrupt change be? Might you help me

If you mean write the code for you then you’ve probably come to the wrong place.

However, if you do some research you’ll find all the information you need to make the changes yourself and if you get stuck with the minor details then members of this community will often help you out.


I never said you need the code. same thanks