SyncPhysicalButton don't work why?

Why button don’t work
On the phone is fine but physical button not working
someone have a idea why
help

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "xxx";
char ssid[] = "xxx";
char pass[] = "xxx";
#define EspSerial Serial1

#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

const int led1Pin = 48;
const int btn1Pin = 8;
const int led2Pin = 49;
const int btn2Pin = 8;
const int led3Pin = 50;
const int btn3Pin = 8;
const int led4Pin = 47;
const int btn4Pin = 8;
const int led5Pin = 45;
const int btn5Pin = 8;
const int led6Pin = 44;
const int btn6Pin = 8;
const int led7Pin = 46;
const int btn7Pin = 8;
const int led8Pin = 38;
const int btn8Pin = 39;
const int led9Pin = 36;
const int btn9Pin = 40;
const int led10Pin = 37;
const int btn10Pin = 41;
const int led11Pin = 35;
const int btn11Pin = 42;
const int led12Pin = 43;
const int btn12Pin = 31;

const int btn13Pin = 33;
const int btn14Pin = 32;
const int btn15Pin = 53;
const int btn16Pin = 30;

WidgetLED led13(V13);
WidgetLED led14(V14);
WidgetLED led15(V15);
WidgetLED led16(V16);

SimpleTimer timer;

void checkPhysicalButton1();
void checkPhysicalButton2();
void checkPhysicalButton3();
void checkPhysicalButton4();
void checkPhysicalButton5();
void checkPhysicalButton6();
void checkPhysicalButton7();
void checkPhysicalButton8();
void checkPhysicalButton9();
void checkPhysicalButton10();
void checkPhysicalButton11();
void checkPhysicalButton12();

int led1State = LOW;
int btn1State = HIGH;
int led2State = LOW;
int btn2State = HIGH;
int led3State = LOW;
int btn3State = HIGH;
int led4State = LOW;
int btn4State = HIGH;
int led5State = LOW;
int btn5State = HIGH;
int led6State = LOW;
int btn6State = HIGH;
int led7State = LOW;
int btn7State = HIGH;
int led8State = LOW;
int btn8State = HIGH;
int led9State = LOW;
int btn9State = HIGH;
int led10State = LOW;
int btn10State = HIGH;
int led11State = LOW;
int btn11State = HIGH;
int led12State = LOW;
int btn12State = HIGH;

void setup()
{ Serial.begin(9600);
  delay(10);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
pinMode(led1Pin, OUTPUT);
  pinMode(btn1Pin, INPUT_PULLUP);
  digitalWrite(led1Pin, led1State);
  pinMode(led2Pin, OUTPUT);
  pinMode(btn2Pin, INPUT_PULLUP);
  digitalWrite(led2Pin, led2State);
  pinMode(led3Pin, OUTPUT);
  pinMode(btn3Pin, INPUT_PULLUP);
  digitalWrite(led3Pin, led3State);
  pinMode(led4Pin, OUTPUT);
  pinMode(btn4Pin, INPUT_PULLUP);
  digitalWrite(led4Pin, led4State);
  pinMode(led5Pin, OUTPUT);
  pinMode(btn5Pin, INPUT_PULLUP);
  digitalWrite(led5Pin, led5State);
  pinMode(led6Pin, OUTPUT);
  pinMode(btn6Pin, INPUT_PULLUP);
  digitalWrite(led6Pin, led6State);
  pinMode(led7Pin, OUTPUT);
  pinMode(btn7Pin, INPUT_PULLUP);
  digitalWrite(led7Pin, led7State);
  pinMode(led8Pin, OUTPUT);
  pinMode(btn8Pin, INPUT_PULLUP);
  digitalWrite(led8Pin, led8State);
  pinMode(led9Pin, OUTPUT);
  pinMode(btn9Pin, INPUT_PULLUP);
  digitalWrite(led9Pin, led9State);
  pinMode(led10Pin, OUTPUT);
  pinMode(btn10Pin, INPUT_PULLUP);
  digitalWrite(led10Pin, led10State);
  pinMode(led11Pin, OUTPUT);
  pinMode(btn11Pin, INPUT_PULLUP);
  digitalWrite(led11Pin, led11State);
  pinMode(led12Pin, OUTPUT);
  pinMode(btn12Pin, INPUT_PULLUP);
  digitalWrite(led12Pin, led12State);

  pinMode(btn13Pin, INPUT_PULLUP);
  pinMode(btn14Pin, INPUT_PULLUP);
  pinMode(btn15Pin, INPUT_PULLUP);
  pinMode(btn16Pin, INPUT_PULLUP);
  
  timer.setInterval(100L, checkPhysicalButton1);
  timer.setInterval(100L, checkPhysicalButton2);
  timer.setInterval(100L, checkPhysicalButton3);
  timer.setInterval(100L, checkPhysicalButton4);
  timer.setInterval(100L, checkPhysicalButton5);
  timer.setInterval(100L, checkPhysicalButton6);
  timer.setInterval(100L, checkPhysicalButton7);
  timer.setInterval(100L, checkPhysicalButton8);
  timer.setInterval(100L, checkPhysicalButton9);
  timer.setInterval(100L, checkPhysicalButton10);
  timer.setInterval(100L, checkPhysicalButton11);
  timer.setInterval(100L, checkPhysicalButton12);
  
  timer.setInterval(500L, buttonLedWidget13);
  timer.setInterval(500L, buttonLedWidget14);
  timer.setInterval(500L, buttonLedWidget15);
  timer.setInterval(500L, buttonLedWidget16);
  
  Blynk.begin(auth, wifi, ssid, pass);
}
BLYNK_CONNECTED() {
  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);
  Blynk.syncVirtual(V4);
  Blynk.syncVirtual(V5);
  Blynk.syncVirtual(V6);
  Blynk.syncVirtual(V7);
  Blynk.syncVirtual(V8);
  Blynk.syncVirtual(V9);
  Blynk.syncVirtual(V10);
  Blynk.syncVirtual(V11);
  Blynk.syncVirtual(V12);
}
BLYNK_WRITE(V1) {
  led1State = param.asInt();
  digitalWrite(led1Pin, led1State);
}
void checkPhysicalButton1()
{
  if (digitalRead(btn1Pin) == LOW) {
    if (btn1State != LOW) {
      led1State = !led1State;
      digitalWrite(led1Pin, led1State);
      Blynk.virtualWrite(V1, led1State);
    }
    btn1State = LOW;
  } else {
    btn1State = HIGH;
  }
}
BLYNK_WRITE(V2) {
  led2State = param.asInt();
  digitalWrite(led2Pin, led2State);
}
void checkPhysicalButton2()
{
  if (digitalRead(btn2Pin) == LOW) {
    if (btn2State != LOW) {
      led2State = !led2State;
      digitalWrite(led2Pin, led2State);
      Blynk.virtualWrite(V2, led2State);
    }
    btn2State = LOW;
  } else {
    btn2State = HIGH;
  }
}
BLYNK_WRITE(V3) {
  led3State = param.asInt();
  digitalWrite(led3Pin, led3State);
}
void checkPhysicalButton3()
{
  if (digitalRead(btn3Pin) == LOW) {
    if (btn3State != LOW) {
      led3State = !led3State;
      digitalWrite(led3Pin, led3State);
      Blynk.virtualWrite(V3, led3State);
    }
    btn3State = LOW;
  } else {
    btn3State = HIGH;
  }
}
BLYNK_WRITE(V4) {
  led4State = param.asInt();
  digitalWrite(led4Pin, led4State);
}
void checkPhysicalButton4()
{
  if (digitalRead(btn4Pin) == LOW) {
    if (btn4State != LOW) {
      led4State = !led4State;
      digitalWrite(led4Pin, led4State);
      Blynk.virtualWrite(V4, led4State);
    }
    btn4State = LOW;
  } else {
    btn4State = HIGH;
  }
}
BLYNK_WRITE(V5) {
  led5State = param.asInt();
  digitalWrite(led5Pin, led5State);
}
void checkPhysicalButton5()
{
  if (digitalRead(btn5Pin) == LOW) {
    if (btn5State != LOW) {
      led5State = !led5State;
      digitalWrite(led5Pin, led5State);
      Blynk.virtualWrite(V5, led5State);
    }
    btn5State = LOW;
  } else {
    btn5State = HIGH;
  }
}
BLYNK_WRITE(V6) {
  led6State = param.asInt();
  digitalWrite(led6Pin, led6State);
}
void checkPhysicalButton6()
{
  if (digitalRead(btn6Pin) == LOW) {
    if (btn6State != LOW) {
      led6State = !led6State;
      digitalWrite(led6Pin, led6State);
      Blynk.virtualWrite(V6, led6State);
    }
    btn6State = LOW;
  } else {
    btn6State = HIGH;
  }
}
BLYNK_WRITE(V7) {
  led7State = param.asInt();
  digitalWrite(led7Pin, led7State);
}
void checkPhysicalButton7()
{
  if (digitalRead(btn7Pin) == LOW) {
    if (btn7State != LOW) {
      led7State = !led7State;
      digitalWrite(led7Pin, led7State);
      Blynk.virtualWrite(V7, led7State);
    }
    btn7State = LOW;
  } else {
    btn7State = HIGH;
  }
}
BLYNK_WRITE(V8) {
  led8State = param.asInt();
  digitalWrite(led8Pin, led8State);
}
void checkPhysicalButton8()
{
  if (digitalRead(btn8Pin) == LOW) {
    if (btn8State != LOW) {
      led8State = !led8State;
      digitalWrite(led8Pin, led8State);
      Blynk.virtualWrite(V8, led8State);
    }
    btn8State = LOW;
  } else {
    btn8State = HIGH;
  }
}
BLYNK_WRITE(V9) {
  led9State = param.asInt();
  digitalWrite(led9Pin, led9State);
}
void checkPhysicalButton9()
{
  if (digitalRead(btn9Pin) == LOW) {
    if (btn9State != LOW) {
      led9State = !led9State;
      digitalWrite(led9Pin, led9State);
      Blynk.virtualWrite(V9, led9State);
    }
    btn9State = LOW;
  } else {
    btn9State = HIGH;
  }
}
BLYNK_WRITE(V10) {
  led10State = param.asInt();
  digitalWrite(led10Pin, led10State);
}
void checkPhysicalButton10()
{
  if (digitalRead(btn10Pin) == LOW) {
    if (btn10State != LOW) {
      led10State = !led10State;
      digitalWrite(led10Pin, led10State);
      Blynk.virtualWrite(V10, led10State);
    }
    btn10State = LOW;
  } else {
    btn10State = HIGH;
  }
}
BLYNK_WRITE(V11) {
  led11State = param.asInt();
  digitalWrite(led11Pin, led11State);
}
void checkPhysicalButton11()
{
  if (digitalRead(btn11Pin) == LOW) {
    if (btn11State != LOW) {
      led11State = !led11State;
      digitalWrite(led11Pin, led11State);
      Blynk.virtualWrite(V11, led11State);
    }
    btn11State = LOW;
  } else {
    btn11State = HIGH;
  }
}
BLYNK_WRITE(V12) {
  led12State = param.asInt();
  digitalWrite(led12Pin, led12State);
}
void checkPhysicalButton12()
{
  if (digitalRead(btn12Pin) == LOW) {
    if (btn12State != LOW) {
      led12State = !led12State;
      digitalWrite(led12Pin, led12State);
      Blynk.virtualWrite(V12, led12State);
    }
    btn12State = LOW;
  } else {
    btn12State = HIGH;
  }
}
boolean btn13State = false;
void buttonLedWidget13()
{  boolean isPressed = (digitalRead(btn13Pin) == LOW);
  if (isPressed != btn13State) {
    if (isPressed) {
      led13.on();
    } else {
      led13.off();
    }
    btn13State = isPressed;
  }
}
boolean btn14State = false;
void buttonLedWidget14()
{  boolean isPressed = (digitalRead(btn14Pin) == LOW);
  if (isPressed != btn14State) {
    if (isPressed) {
      led14.on();
    } else {
      led14.off();
    }
    btn14State = isPressed;
  }
}
boolean btn15State = false;
void buttonLedWidget15()
{  boolean isPressed = (digitalRead(btn15Pin) == LOW);
  if (isPressed != btn15State) {
    if (isPressed) {
      led15.on();
    } else {
      led15.off();
    }
    btn15State = isPressed;
  }
}
boolean btn16State = false;
void buttonLedWidget16()
{  boolean isPressed = (digitalRead(btn16Pin) == LOW);
  if (isPressed != btn16State) {
    if (isPressed) {
      led16.on();
    } else {
      led16.off();
    }
    btn16State = isPressed;
  }
}
void loop()
{
  Blynk.run();
  timer.run();
}

Are you able to reduce your sketch so that it only includes 1 button. It will be easier to debug.

How can I do that
I have 12 reley and I need it each separately

Yup get 1 button working, then copy it to the 11 other buttons.

1 Like

Could you tell me which part of code I must chenge before copy to work fine

All ot it :slight_smile:

Try creating a separate sketch that utilizes just one virtual and one physical instance of whatever you are doing. Then if it still doesn’t work, post it so we can start assisting.