High/Low State issue with Linking Physical Switch with Virtual Switch Widget

Hello Im currently implementing synchphysicalbutton.ino and running into issues with the toggle switch override. I can successfully maneuver the pins via esp8266 and blynk button but not the physical switch itself.

my impromptu wiring


ideally i would like to control pins and have either button override the other and vice versa. is there something im missing

I can’t really tell where the pink wires from the switch are connected to on your ESP01, but I’m assuming they are connected to one of the top three inboard pins, which are GPIO 3, 0 or 2 respectively.

In the code, btnPin is defined as GPIO 8, which isn’t accessible on the ESP01, so you’ll need to change the code to reference the pin you’ve actually used (I’d avoid GPIO 0 if I were you).

Hopefully the voltage regulator, which is shown as 5v in your diagram is actually a 3.3v output, as ESP01s aren’t 5v tolerant.




sorry, it was something a buddy and i put together in replacement of design schematics, as i cant read those.

But here is a quick picture

The toggle is D6 and MOSFET to D5, with those going to GPIO pins 12, and 14 respectively

Just an observation: I don’t know if ESP-boards has INPUT_PULLUP on their GPIO’s. So you could remove either that form the code or the external resistor :slight_smile:

Can’t tell if the button itself is NO or NC. It should be NO (normally open) and when pushed to GND sets the input pin to LOW.

EDIT: Upload your code instead of the example.

// Set your LED and physical button pins here, D4 is onboard, D5 is GPIO14, D7 is GPIO13
const int ledPin = 14;
const int btnPin = 12;
const int ledPin1 = 13;
const int btnPin1 = 15;

//BlynkTimer timer;
void checkPhysicalButton();

int ledState = LOW;
int btnState = HIGH;

int ledState1 = LOW;
int btnState1 = HIGH;

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

  // Alternatively, you could override server state using:
  //Blynk.virtualWrite(V2, ledState);

// When App button is pushed - switch the state
 ledState = param.asInt();
  digitalWrite(ledPin, ledState);

void checkPhysicalButton()
  if (digitalRead(btnPin) == LOW) {
    // btnState is used to avoid sequential toggles
    if (btnState != LOW) {

      // Toggle LED state
      ledState = !ledState;
      digitalWrite(ledPin, ledState);

      // Update Button Widget
      Blynk.virtualWrite(V2, ledState);
   btnState = LOW;
  } else {
    btnState = HIGH;

void setup()
  // Debug console

  Blynk.begin(auth, ssid, pass);

  pinMode(ledPin, OUTPUT);
  pinMode(btnPin, INPUT_PULLUP);
  digitalWrite(ledPin, ledState);

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

void loop()

@Sonny_Doan please use this method for formatting your posted code… cleaning up all those > characters is a pain :stuck_out_tongue:

Blynk - FTFC

please close issue

it was a soldering issue


Funny how a wiring diagram and the breadboard equivalent can vary so much :wink:
Glad you found the problem in the end.


thanks everybody

theres a lot of fine tuning left to do, but it was a good relief to find a quick fix. its often the simplest solution that is the right one

1 Like