Relay : green led and red led

My lass code

#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#include <SPI.h>
#include <Wire.h>

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

BlynkTimer timer;

char auth[] = "K6esA6BJYKRFxgfnqCVpIS0zowxgKxAW";

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

// Set your LED and physical button pins here
const int relais1 = 14;
const int btn1 = 27;
const int ledV1 = 5;
const int ledR1 = 2;


const int relais2 = 32;
const int btn2 = 26;
const int ledV2 = 18;
const int ledR2 = 4;


const int relais3 = 15;
const int btn3 = 25;
const int ledV3 = 19;
const int ledR3 = 16;

const int relais4 = 12;
const int btn4 = 33;
const int ledV4 = 17;
const int ledR4 = 13;

// one wire temperature
#define ONE_WIRE_BUS 23
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int deviceCount = 3;
float tempC;







void temperature();


int relais1Sate = LOW;
int btn1State = HIGH;
int ledV1State = LOW;
int ledR1State = LOW;

int relais2Sate = LOW;
int btn2State = HIGH;
int ledV2State = LOW;
int ledR2State = LOW;

int relais3Sate = LOW;
int btn3State = HIGH;
int ledV3State = LOW;
int ledR3State = LOW;

int relais4Sate = LOW;
int btn4State = HIGH;
int ledV4State = LOW;
int ledR4State = LOW;

int brightness = 50;

int lcd_position[] = {16, 30, 44}; // position temperature sur l'écran



BLYNK_WRITE(V1) {
  relais1Sate = param.asInt();
  Serial.print("Widget Button V1 changed. Writing ");
  Serial.print(relais1Sate);
  Serial.print(" to Relay 1 and LED V1, and ");
  Serial.print(!relais1Sate);
  Serial.println(" to LED R1 ...");

  digitalWrite(relais1, relais1Sate);
  digitalWrite(ledV1, relais1Sate);
  digitalWrite(ledR1, !relais1Sate);



}

BLYNK_WRITE(V2) {
  relais2Sate = param.asInt();
  digitalWrite(relais2, relais2Sate);
  digitalWrite(ledV2, relais2Sate);
  digitalWrite(ledR2, !relais2Sate);


}

BLYNK_WRITE(V3) {
  relais3Sate = param.asInt();
  digitalWrite(relais3, relais3Sate);
  digitalWrite(ledV3, relais3Sate);
  digitalWrite(ledR3, !relais3Sate);


}

BLYNK_WRITE(V4) {
  relais4Sate = param.asInt();
  digitalWrite(relais4, relais4Sate);
  digitalWrite(ledV4, relais4Sate);
  digitalWrite(ledR4, !relais4Sate);


}

void temperature()
{
  display.clearDisplay();
  display.display();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);


  display.setCursor(0, 0);
  display.println("---------------------");
  display.setCursor(0, 6);
  display.print("|    Temperature    |");
  display.setCursor(0, 12);
  display.println("---------------------");

  display.setCursor(0, 16); // position 0
  display.println(" Interieur  |");
  display.print("---------------------");
  display.display();

  display.setCursor(0, 30); // position 1
  display.println(" Exterrieur |");
  display.print("---------------------");
  display.display();

  display.setCursor(0, 44); // position 2
  display.println(" Eau        |");
  display.print("---------------------");
  display.display();




  // Send command to all the sensors for temperature conversion
  sensors.requestTemperatures();

  // Display temperature from each sensor
  for (int i = 0;  i < deviceCount;  i++)
  {

    tempC = sensors.getTempCByIndex(i);
    Blynk.virtualWrite(i + 21, tempC);
    display.setCursor(80, lcd_position[i]);
    display.print(tempC);
    display.display();


  }
}



void checkPhysicalButton1()
{
  if (digitalRead(btn1) == LOW)
  {
    Serial.print("Location A, btn1 = ");
    Serial.print(digitalRead(btn1));
    Serial.print(" btn1State = ");
    Serial.println(btn1State);
                
    // btnState is used to avoid sequential toggles
    if (btn1State != LOW)
    {
      Serial.print("Location B, btn1 = ");
      Serial.print(btn1);
      Serial.print("btn1State = ");
      Serial.println(btn1State);
      
      // Toggle LED state
      relais1Sate = !relais1Sate;

      Serial.print("Location C, writing ");
      Serial.print(relais1Sate);
      Serial.println(" to Relay 1 ...");     
              
      digitalWrite(relais1, relais1Sate);
      
      ledV1State = !ledV1State;
      
      Serial.print("Location D, writing ");
      Serial.print(!ledV1State);
      Serial.print(" to LED V1 and ");   
      Serial.print(ledV1State);
      Serial.println(" to LED R1 ...");        
       
      digitalWrite(ledV1, !ledV1State);
      digitalWrite(ledR1, ledV1State);

      // Update Button Widget

      Serial.print("Location E, writing ");
      Serial.print(!relais1Sate);
      Serial.println(" to Button Widget on pin V1 ...");   
     
      Blynk.virtualWrite(V1, !relais1Sate);
      
      btn1State = LOW;     
    }
  }
  else
  {
    btn1State = HIGH;
  }




  

  if (digitalRead(btn2) == LOW) {

    // btnState is used to avoid sequential toggles
    if (btn2State != LOW) {


      // Toggle LED state
      relais2Sate = !relais2Sate;

      digitalWrite(relais2, relais2Sate);
      ledV2State = !ledV2State;
      digitalWrite(ledV2, !ledV2State);
      digitalWrite(ledR2, ledV2State);



      // Update Button Widget
      Blynk.virtualWrite(V2, !relais2Sate);


    }
    btn2State = LOW;
  } else {
    btn2State = HIGH;

  }

  if (digitalRead(btn3) == LOW) {
    // btnState is used to avoid sequential toggles
    if (btn3State != LOW) {


      // Toggle LED state
      relais3Sate = !relais3Sate;

      digitalWrite(relais3, relais3Sate);
      ledV3State = !ledV3State;
      digitalWrite(ledV3, !ledV3State);
      digitalWrite(ledR3, ledV3State);





      // Update Button Widget
      Blynk.virtualWrite(V3, !relais3Sate);


    }
    btn3State = LOW;
  } else {
    btn3State = HIGH;


  }

  if (digitalRead(btn4) == LOW) {

    // btnState is used to avoid sequential toggles
    if (btn4State != LOW) {



      // Toggle LED state
      relais4Sate = !relais4Sate;

      digitalWrite(relais4, relais4Sate);
      ledV4State = !ledV4State;



      digitalWrite(ledV4, !ledV4State);
      digitalWrite(ledR4, ledV4State);




      // Update Button Widget
      Blynk.virtualWrite(V4, !relais4Sate);



    }
    btn4State = LOW;
  } else {
    btn4State = HIGH;


  }



}

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);
  Blynk.syncVirtual(V4);

}

void checkPhysicalButton1();



void setup()
{
  WiFi.begin(ssid, pass);
  //timer.setInterval(3000L, checkBlynk); // check if connected to Blynk server every 3 seconds
  Blynk.config(auth);
  sensors.begin();  // debut de la librairie capteur de température
  // Debug console
  Serial.begin(9600);


  pinMode(relais1, OUTPUT);
  pinMode(btn1, INPUT_PULLUP);
  digitalWrite(relais1, relais1Sate);
  pinMode(ledV1, OUTPUT);
  pinMode(ledR1, OUTPUT);

  pinMode(relais2, OUTPUT);
  pinMode(btn2, INPUT_PULLUP);
  digitalWrite(relais2, relais2Sate);
  pinMode(ledV2, OUTPUT);
  pinMode(ledR2, OUTPUT);

  pinMode(relais3, OUTPUT);
  pinMode(btn3, INPUT_PULLUP);
  digitalWrite(relais3, relais3Sate);
  pinMode(ledV3, OUTPUT);
  pinMode(ledR3, OUTPUT);

  pinMode(relais4, OUTPUT);
  pinMode(btn4, INPUT_PULLUP);
  digitalWrite(relais4, relais4Sate);
  pinMode(ledV4, OUTPUT);
  pinMode(ledR4, OUTPUT);


  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  // Clear the buffer
  display.clearDisplay();
  display.display();


  timer.setInterval(100L, checkPhysicalButton1);

  timer.setInterval(10000L, temperature);


}



void loop()
{

  Blynk.run();
  timer.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

My serial monitor

16:35:38.421 -> [5243] Connecting to blynk-cloud.com:80
16:35:38.797 -> Location A, btn1 = 0 btn1State = 0
16:35:38.865 -> Location A, btn1 = 0 btn1State = 0
16:35:38.966 -> Location A, btn1 = 0 btn1State = 0
16:35:39.068 -> Location A, btn1 = 0 btn1State = 0
16:35:39.103 -> [5974] Ready (ping: 311ms).
16:35:39.448 -> Location A, btn1 = 0 btn1State = 0
16:35:39.482 -> Location A, btn1 = 0 btn1State = 0
16:35:39.585 -> Location A, btn1 = 0 btn1State = 0
16:35:39.686 -> Location A, btn1 = 0 btn1State = 0
16:35:39.721 -> Widget Button V1 changed. Writing 1 to Relay 1 and LED V1, and 0 to LED R1 ...
16:35:39.789 -> Location A, btn1 = 0 btn1State = 0
16:35:39.856 -> Location A, btn1 = 0 btn1State = 0
16:35:39.959 -> Location A, btn1 = 0 btn1State = 0
16:35:40.060 -> Location A, btn1 = 0 btn1State = 0
16:35:40.163 -> Location A, btn1 = 0 btn1State = 0
16:35:40.264 -> Location A, btn1 = 0 btn1State = 0
16:35:40.366 -> Location A, btn1 = 0 btn1State = 0
16:35:40.469 -> Location A, btn1 = 0 btn1State = 0
16:35:40.572 -> Location A, btn1 = 0 btn1State = 0
16:35:40.675 -> Location A, btn1 = 0 btn1State = 0
16:35:40.778 -> Location A, btn1 = 0 btn1State = 0
16:35:40.879 -> Location A, btn1 = 0 btn1State = 0
16:35:40.980 -> Location A, btn1 = 0 btn1State = 0
16:35:41.083 -> Location A, btn1 = 0 btn1State = 0
16:35:41.185 -> Location A, btn1 = 0 btn1State = 0
16:35:41.255 -> Location A, btn1 = 0 btn1State = 0
16:35:41.359 -> Location A, btn1 = 0 btn1State = 0
16:35:41.459 -> Location A, btn1 = 0 btn1State = 0
16:35:41.562 -> Location A, btn1 = 0 btn1State = 0
16:35:41.664 -> Location A, btn1 = 0 btn1State = 0
16:35:41.766 -> Location A, btn1 = 0 btn1State = 0
16:35:41.868 -> Location A, btn1 = 0 btn1State = 0
16:35:41.970 -> Location A, btn1 = 0 btn1State = 0
16:35:42.073 -> Location A, btn1 = 0 btn1State = 0
16:35:42.174 -> Location A, btn1 = 0 btn1State = 0
16:35:42.277 -> Location A, btn1 = 0 btn1State = 0
16:35:42.382 -> Location A, btn1 = 0 btn1State = 0
16:35:42.484 -> Location A, btn1 = 0 btn1State = 0
16:35:42.586 -> Location A, btn1 = 0 btn1State = 0
16:35:42.655 -> Location A, btn1 = 0 btn1State = 0
16:35:42.757 -> Location A, btn1 = 0 btn1State = 0
16:35:42.859 -> Location A, btn1 = 0 btn1State = 0
16:35:42.963 -> Location A, btn1 = 0 btn1State = 0
16:35:43.064 -> Location A, btn1 = 0 btn1State = 0
16:35:43.167 -> Location A, btn1 = 0 btn1State = 0
16:35:43.269 -> Location A, btn1 = 0 btn1State = 0
16:35:43.373 -> Location A, btn1 = 0 btn1State = 0
16:35:44.405 -> Location A, btn1 = 0 btn1State = 0
16:35:44.473 -> Location A, btn1 = 0 btn1State = 0
16:35:44.577 -> Location A, btn1 = 0 btn1State = 0
16:35:44.681 -> Location A, btn1 = 0 btn1State = 0
16:35:44.783 -> Location A, btn1 = 0 btn1State = 0
16:35:44.886 -> Location A, btn1 = 0 btn1State = 0
16:35:44.954 -> Location A, btn1 = 0 btn1State = 0
16:35:45.055 -> Location A, btn1 = 0 btn1State = 0
16:35:45.156 -> Location A, btn1 = 0 btn1State = 0
16:35:45.258 -> Location A, btn1 = 0 btn1State = 0
16:35:45.360 -> Location A, btn1 = 0 btn1State = 0
16:35:45.462 -> Location A, btn1 = 0 btn1State = 0
16:35:45.565 -> Location A, btn1 = 0 btn1State = 0
16:35:45.667 -> Location A, btn1 = 0 btn1State = 0
16:35:45.770 -> Location A, btn1 = 0 btn1State = 0
16:35:45.873 -> Location A, btn1 = 0 btn1State = 0
16:35:45.974 -> Location A, btn1 = 0 btn1State = 0
16:35:46.078 -> Location A, btn1 = 0 btn1State = 0
16:35:46.180 -> Location A, btn1 = 0 btn1State = 0
16:35:46.282 -> Location A, btn1 = 0 btn1State = 0
16:35:46.384 -> Location A, btn1 = 0 btn1State = 0
16:35:46.486 -> Location A, btn1 = 0 btn1State = 0
16:35:46.554 -> Location A, btn1 = 0 btn1State = 0
16:35:46.656 -> Location A, btn1 = 0 btn1State = 0
16:35:46.756 -> Location A, btn1 = 0 btn1State = 0
16:35:46.856 -> Location A, btn1 = 0 btn1State = 0
16:35:46.957 -> Location A, btn1 = 0 btn1State = 0
16:35:47.059 -> Location A, btn1 = 0 btn1State = 0
16:35:47.162 -> Location A, btn1 = 0 btn1State = 0
16:35:47.265 -> Location A, btn1 = 0 btn1State = 0
16:35:47.366 -> Location A, btn1 = 0 btn1State = 0
16:35:47.401 -> Widget Button V1 changed. Writing 0 to Relay 1 and LED V1, and 1 to LED R1 ...
16:35:47.501 -> Location A, btn1 = 0 btn1State = 0
16:35:47.569 -> Location A, btn1 = 0 btn1State = 0
16:35:47.673 -> Location A, btn1 = 0 btn1State = 0
16:35:47.777 -> Location A, btn1 = 0 btn1State = 0
16:35:47.879 -> Location A, btn1 = 0 btn1State = 0
16:35:47.981 -> Location A, btn1 = 0 btn1State = 0
16:35:48.083 -> Location A, btn1 = 0 btn1State = 0
16:35:48.186 -> Location A, btn1 = 0 btn1State = 0
16:35:48.255 -> Location A, btn1 = 0 btn1State = 0
16:35:48.323 -> Widget Button V1 changed. Writing 1 to Relay 1 and LED V1, and 0 to LED R1 ...
16:35:48.392 -> Location A, btn1 = 0 btn1State = 0
16:35:48.460 -> Location A, btn1 = 0 btn1State = 0
16:35:48.563 -> Location A, btn1 = 0 btn1State = 0
16:35:48.664 -> Location A, btn1 = 0 btn1State = 0
16:35:48.766 -> Location A, btn1 = 0 btn1State = 0
16:35:48.871 -> Location A, btn1 = 0 btn1State = 0
16:35:48.972 -> Location A, btn1 = 0 btn1State = 0
16:35:49.073 -> Location A, btn1 = 0 btn1State = 0
16:35:49.176 -> Location A, btn1 = 0 btn1State = 0
16:35:49.381 -> Location A, btn1 = 0 btn1State = 1
16:35:49.415 -> Location B, btn1 = 27btn1State = 1
16:35:49.449 -> Location C, writing 0 to Relay 1 ...
16:35:49.482 -> Location D, writing 1 to LED V1 and 0 to LED R1 ...
16:35:49.552 -> Location E, writing 1 to Button Widget on pin V1 ...
16:35:49.587 -> Location A, btn1 = 0 btn1State = 0
16:35:49.620 -> Location A, btn1 = 0 btn1State = 0
16:35:49.689 -> Location A, btn1 = 0 btn1State = 0
16:35:49.759 -> Location A, btn1 = 0 btn1State = 0
16:35:49.863 -> Location A, btn1 = 0 btn1State = 0
16:35:49.964 -> Location A, btn1 = 0 btn1State = 0
16:35:50.067 -> Location A, btn1 = 0 btn1State = 0
16:35:50.170 -> Location A, btn1 = 0 btn1State = 0
16:35:50.272 -> Location A, btn1 = 0 btn1State = 0
16:35:50.374 -> Location A, btn1 = 0 btn1State = 0
16:35:50.785 -> Location A, btn1 = 0 btn1State = 1
16:35:50.818 -> Location B, btn1 = 27btn1State = 1
16:35:50.853 -> Location C, writing 1 to Relay 1 ...
16:35:50.887 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
16:35:50.956 -> Location E, writing 0 to Button Widget on pin V1 ...
16:35:50.990 -> Location A, btn1 = 0 btn1State = 0
16:35:51.024 -> Location A, btn1 = 0 btn1State = 0
16:35:51.058 -> Location A, btn1 = 0 btn1State = 0
16:35:51.158 -> Location A, btn1 = 0 btn1State = 0
16:35:51.260 -> Location A, btn1 = 0 btn1State = 0
16:35:51.362 -> Location A, btn1 = 0 btn1State = 0
16:35:51.463 -> Location A, btn1 = 0 btn1State = 0
16:35:51.564 -> Location A, btn1 = 0 btn1State = 0
16:35:51.664 -> Location A, btn1 = 0 btn1State = 0
16:35:51.766 -> Location A, btn1 = 0 btn1State = 0
16:35:51.871 -> Location A, btn1 = 0 btn1State = 0
16:35:51.976 -> Location A, btn1 = 0 btn1State = 0
16:35:52.077 -> Location A, btn1 = 0 btn1State = 0
16:35:52.181 -> Location A, btn1 = 0 btn1State = 0
16:35:52.284 -> Location A, btn1 = 0 btn1State = 0
16:35:52.386 -> Location A, btn1 = 0 btn1State = 0
16:35:52.455 -> Location A, btn1 = 0 btn1State = 0
16:35:52.556 -> Location A, btn1 = 0 btn1State = 0
16:35:52.866 -> Location A, btn1 = 0 btn1State = 1
16:35:52.900 -> Location B, btn1 = 27btn1State = 1
16:35:52.935 -> Location C, writing 0 to Relay 1 ...
16:35:52.969 -> Location D, writing 1 to LED V1 and 0 to LED R1 ...
16:35:53.035 -> Location E, writing 1 to Button Widget on pin V1 ...
16:35:53.105 -> Location A, btn1 = 0 btn1State = 0
16:35:53.139 -> Location A, btn1 = 0 btn1State = 0
16:35:53.172 -> Location A, btn1 = 0 btn1State = 0
16:35:53.276 -> Location A, btn1 = 0 btn1State = 0
16:35:53.377 -> Location A, btn1 = 0 btn1State = 0
16:35:54.396 -> Location A, btn1 = 0 btn1State = 0
16:35:54.463 -> Location A, btn1 = 0 btn1State = 0
16:35:54.565 -> Location A, btn1 = 0 btn1State = 0
16:35:54.666 -> Location A, btn1 = 0 btn1State = 0
16:35:54.770 -> Location A, btn1 = 0 btn1State = 0
16:35:54.872 -> Location A, btn1 = 0 btn1State = 0
16:35:54.975 -> Location A, btn1 = 0 btn1State = 0
16:35:55.078 -> Location A, btn1 = 0 btn1State = 0
16:35:55.179 -> Location A, btn1 = 0 btn1State = 0
16:35:55.280 -> Location A, btn1 = 0 btn1State = 0
16:35:55.384 -> Location A, btn1 = 0 btn1State = 0
16:35:55.486 -> Location A, btn1 = 0 btn1State = 0
16:35:55.588 -> Location A, btn1 = 0 btn1State = 0
16:35:55.656 -> Location A, btn1 = 0 btn1State = 0
16:35:55.723 -> Widget Button V1 changed. Writing 0 to Relay 1 and LED V1, and 1 to LED R1 ...
16:35:55.792 -> Location A, btn1 = 0 btn1State = 0
16:35:55.861 -> Location A, btn1 = 0 btn1State = 0
16:35:55.962 -> Location A, btn1 = 0 btn1State = 0
16:35:56.066 -> Location A, btn1 = 0 btn1State = 0
16:35:56.169 -> Location A, btn1 = 0 btn1State = 0
16:35:56.270 -> Location A, btn1 = 0 btn1State = 0
16:35:56.373 -> Location A, btn1 = 0 btn1State = 0
16:35:56.474 -> Location A, btn1 = 0 btn1State = 0
16:35:56.577 -> Location A, btn1 = 0 btn1State = 0
16:35:56.679 -> Location A, btn1 = 0 btn1State = 0
16:35:56.781 -> Location A, btn1 = 0 btn1State = 0
16:35:56.882 -> Location A, btn1 = 0 btn1State = 0
16:35:56.984 -> Location A, btn1 = 0 btn1State = 0
16:35:57.086 -> Location A, btn1 = 0 btn1State = 0
16:35:57.155 -> Location A, btn1 = 0 btn1State = 0
16:35:57.223 -> Widget Button V1 changed. Writing 1 to Relay 1 and LED V1, and 0 to LED R1 ...
16:35:57.292 -> Location A, btn1 = 0 btn1State = 0
16:35:57.359 -> Location A, btn1 = 0 btn1State = 0
16:35:57.463 -> Location A, btn1 = 0 btn1State = 0
16:35:57.565 -> Location A, btn1 = 0 btn1State = 0
16:35:57.669 -> Location A, btn1 = 0 btn1State = 0
16:35:57.771 -> Location A, btn1 = 0 btn1State = 0
16:35:57.873 -> Location A, btn1 = 0 btn1State = 0
16:35:57.976 -> Location A, btn1 = 0 btn1State = 0
16:35:58.077 -> Location A, btn1 = 0 btn1State = 0
16:35:58.180 -> Location A, btn1 = 0 btn1State = 0
16:35:58.283 -> Location A, btn1 = 0 btn1State = 0
16:35:58.385 -> Location A, btn1 = 0 btn1State = 0
16:35:58.454 -> Location A, btn1 = 0 btn1State = 0
16:35:58.559 -> Location A, btn1 = 0 btn1State = 0
16:35:58.660 -> Location A, btn1 = 0 btn1State = 0
16:35:58.761 -> Location A, btn1 = 0 btn1State = 0
16:35:58.864 -> Location A, btn1 = 0 btn1State = 0
16:35:58.967 -> Location A, btn1 = 0 btn1State = 0
16:35:59.071 -> Location A, btn1 = 0 btn1State = 0
16:35:59.172 -> Location A, btn1 = 0 btn1State = 0
16:35:59.275 -> Location A, btn1 = 0 btn1State = 0
16:35:59.377 -> Location A, btn1 = 0 btn1State = 0
16:35:59.480 -> Location A, btn1 = 0 btn1State = 0
16:35:59.583 -> Location A, btn1 = 0 btn1State = 0
16:35:59.685 -> Location A, btn1 = 0 btn1State = 0
16:35:59.754 -> Location A, btn1 = 0 btn1State = 0
16:35:59.858 -> Location A, btn1 = 0 btn1State = 0

How is your btn1 physical switch wired?

And is it a normally closed or normally open switch?

Pete.

I use these physical button. the vcc and gnd are connected in derivation. And the out connect to esp

image

I do not know,

Do you have a link to a specification, a manufacturer or a reseller?

Do you own a multimeter?

Pete.

here is the link :

With my multimeter, electricity goes on when I press the button. I will say that it is a normally open

When you wrote the pinMode statements that specified the mode for the button pins, you used the INPUT_PULLUP modifier.

This ensures that the pins don’t float at an intermediate voltage in their resting state. Instead up pulls the pins HIGH, using the built-in pullup resistors in the chip.

To trigger a change of state for the pin, it needs to be connected to a physical button that will connect the pin to GND when the button is pressed.

You’ve also written your code so that it looks for the pins to be pulled LOW (the pin is shorted to GND) when the physical button is activated.

So, you need to wire your switches so that one side is connected to your btnpin, and the other to GND. When the switch is pressed the circuit between the pin and GND is completed, when the switch is released the circuit is broken, so that the internal pullup resistors can bring the pin back to HIGH (3.3v).

Pete.

I’m sorry but I don’t understand how to connect.
On my pusher button I have three pins (VCC, OUT, GND)
currently I am connected like this:
VCC = 3.3 volt
OUT = the BTNPIN
GND = the GND

How do I connect:
VCC = ??
OUT = ??
GND = ??

You have the pushbuttons and the multimeter in front of you.

Set the multimeter to continuity mode and work-out which two pins on the button are open when the button is released, and connected together when the button is pressed.
These are the two pins you will be using.
One will connect to the btnpin on the ESP32, the other will connect to GND on the ESP32

No pins on the button will be connected to 3.3 volts

Pete.

I have three pins (vcc, gnd, out).

With continuity mode

I do not press the button:
GND with VCC = no noise
GND with OUT = no noise
VCC with OUT = no noise

I press the button:
GND with VCC = no noise
GND with OUT = no noise
VCC with OUT = noise

So I’ll plug in = the VCC pin to the GND of my ESP, and the OUT pin to my btpin

I make these changes and I give you news.

Hello; I just made the pin changes.

I press the physical button twice
I press once on the buton widget
I press the physical button twice

20:08:23.946 -> Location A, btn1 = 0 btn1State = 1
20:08:23.981 -> Location B, btn1 = 27, btn1State = 1
20:08:24.016 -> Location C, writing 0 to Relay 1 ...
20:08:24.049 -> Location D, writing 1 to LED V1 and 0 to LED R1 ...
20:08:24.116 -> Location E, writing 1 to Button Widget on pin V1 ...
20:08:33.231 -> Location A, btn1 = 0 btn1State = 1
20:08:33.265 -> Location B, btn1 = 27, btn1State = 1
20:08:33.299 -> Location C, writing 1 to Relay 1 ...
20:08:33.367 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
20:08:33.400 -> Location E, writing 0 to Button Widget on pin V1 ...
20:08:48.663 -> Widget Button V1 changed. Writing 1 to Relay 1 and LED V1, and 0 to LED R1 ...
20:08:58.834 -> Location A, btn1 = 0 btn1State = 1
20:08:58.869 -> Location B, btn1 = 27, btn1State = 1
20:08:58.903 -> Location C, writing 0 to Relay 1 ...
20:08:58.938 -> Location D, writing 1 to LED V1 and 0 to LED R1 ...
20:08:59.006 -> Location E, writing 1 to Button Widget on pin V1 ...
20:09:02.046 -> Location A, btn1 = 0 btn1State = 1
20:09:02.080 -> Location B, btn1 = 27, btn1State = 1
20:09:02.114 -> Location C, writing 1 to Relay 1 ...
20:09:02.148 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
20:09:02.216 -> Location E, writing 0 to Button Widget on pin V1 ...
20:09:02.250 -> Location A, btn1 = 0 btn1State = 0

this problem comes randomly.

Here is my last sketch

#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#include <SPI.h>
#include <Wire.h>

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

BlynkTimer timer;

char auth[] = "xxxxxxxxxxxxxxxxxxx";

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

// Set your LED and physical button pins here
const int relais1 = 14;
const int btn1 = 27;
const int ledV1 = 5;
const int ledR1 = 2;


const int relais2 = 32;
const int btn2 = 26;
const int ledV2 = 18;
const int ledR2 = 4;


const int relais3 = 15;
const int btn3 = 25;
const int ledV3 = 19;
const int ledR3 = 16;

const int relais4 = 12;
const int btn4 = 33;
const int ledV4 = 17;
const int ledR4 = 13;

// one wire temperature
#define ONE_WIRE_BUS 23
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int deviceCount = 3;
float tempC;







void temperature();


int relais1Sate = LOW;
int btn1State = HIGH;
int ledV1State = LOW;
int ledR1State = LOW;

int relais2Sate = LOW;
int btn2State = HIGH;
int ledV2State = LOW;
int ledR2State = LOW;

int relais3Sate = LOW;
int btn3State = HIGH;
int ledV3State = LOW;
int ledR3State = LOW;

int relais4Sate = LOW;
int btn4State = HIGH;
int ledV4State = LOW;
int ledR4State = LOW;

int brightness = 50;

int lcd_position[] = {16, 30, 44}; // position temperature sur l'écran



BLYNK_WRITE(V1) {
  relais1Sate = param.asInt();
  Serial.print("Widget Button V1 changed. Writing ");
  Serial.print(relais1Sate);
  Serial.print(" to Relay 1 and LED V1, and ");
  Serial.print(!relais1Sate);
  Serial.println(" to LED R1 ...");

  digitalWrite(relais1, relais1Sate);
  digitalWrite(ledV1, relais1Sate);
  digitalWrite(ledR1, !relais1Sate);



}

BLYNK_WRITE(V2) {
  relais2Sate = param.asInt();
  digitalWrite(relais2, relais2Sate);
  digitalWrite(ledV2, relais2Sate);
  digitalWrite(ledR2, !relais2Sate);


}

BLYNK_WRITE(V3) {
  relais3Sate = param.asInt();
  digitalWrite(relais3, relais3Sate);
  digitalWrite(ledV3, relais3Sate);
  digitalWrite(ledR3, !relais3Sate);


}

BLYNK_WRITE(V4) {
  relais4Sate = param.asInt();
  digitalWrite(relais4, relais4Sate);
  digitalWrite(ledV4, relais4Sate);
  digitalWrite(ledR4, !relais4Sate);


}

void temperature()
{
  display.clearDisplay();
  display.display();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);


  display.setCursor(0, 0);
  display.println("---------------------");
  display.setCursor(0, 6);
  display.print("|    Temperature    |");
  display.setCursor(0, 12);
  display.println("---------------------");

  display.setCursor(0, 16); // position 0
  display.println(" Interieur  |");
  display.print("---------------------");
  display.display();

  display.setCursor(0, 30); // position 1
  display.println(" Exterrieur |");
  display.print("---------------------");
  display.display();

  display.setCursor(0, 44); // position 2
  display.println(" Eau        |");
  display.print("---------------------");
  display.display();




  // Send command to all the sensors for temperature conversion
  sensors.requestTemperatures();

  // Display temperature from each sensor
  for (int i = 0;  i < deviceCount;  i++)
  {

    tempC = sensors.getTempCByIndex(i);
    Blynk.virtualWrite(i + 21, tempC);
    display.setCursor(80, lcd_position[i]);
    display.print(tempC);
    display.display();


  }
}



void checkPhysicalButton1()
{
  if (digitalRead(btn1) == LOW)
  {
    Serial.print("Location A, btn1 = ");
    Serial.print(digitalRead(btn1));
    Serial.print(" btn1State = ");
    Serial.println(btn1State);

    // btnState is used to avoid sequential toggles
    if (btn1State != LOW)
    {
      Serial.print("Location B, btn1 = ");
      Serial.print(btn1);
      Serial.print(", btn1State = ");
      Serial.println(btn1State);

      // Toggle LED state
      relais1Sate = !relais1Sate;

      Serial.print("Location C, writing ");
      Serial.print(relais1Sate);
      Serial.println(" to Relay 1 ...");

      digitalWrite(relais1, relais1Sate);

      ledV1State = !ledV1State;

      Serial.print("Location D, writing ");
      Serial.print(!ledV1State);
      Serial.print(" to LED V1 and ");
      Serial.print(ledV1State);
      Serial.println(" to LED R1 ...");

      digitalWrite(ledV1, !ledV1State);
      digitalWrite(ledR1, ledV1State);

      // Update Button Widget

      Serial.print("Location E, writing ");
      Serial.print(!relais1Sate);
      Serial.println(" to Button Widget on pin V1 ...");

      Blynk.virtualWrite(V1, !relais1Sate);

      btn1State = LOW;
    }
  }
  else
  {
    btn1State = HIGH;
  }






 if (digitalRead(btn2) == LOW)
  {

    // btnState is used to avoid sequential toggles
    if (btn2State != LOW)
    {

      // Toggle LED state
      relais2Sate = !relais2Sate;


      digitalWrite(relais2, relais2Sate);

      ledV2State = !ledV2State;
      digitalWrite(ledV2, !ledV2State);
      digitalWrite(ledR2, ledV2State);

      // Update Button Widget

      Blynk.virtualWrite(V2, !relais2Sate);

      btn2State = LOW;
    }
  }
  else
  {
    btn2State = HIGH;
  }

   if (digitalRead(btn3) == LOW)
  {

    // btnState is used to avoid sequential toggles
    if (btn3State != LOW)
    {

      // Toggle LED state
      relais3Sate = !relais3Sate;


      digitalWrite(relais3, relais3Sate);

      ledV3State = !ledV3State;
      digitalWrite(ledV3, !ledV3State);
      digitalWrite(ledR3, ledV3State);

      // Update Button Widget

      Blynk.virtualWrite(V3, !relais3Sate);

      btn3State = LOW;
    }
  }
  else
  {
    btn3State = HIGH;
  }

    if (digitalRead(btn4) == LOW)
  {

    // btnState is used to avoid sequential toggles
    if (btn4State != LOW)
    {

      // Toggle LED state
      relais4Sate = !relais4Sate;


      digitalWrite(relais4, relais4Sate);

      ledV4State = !ledV4State;
      digitalWrite(ledV4, !ledV4State);
      digitalWrite(ledR4, ledV4State);

      // Update Button Widget

      Blynk.virtualWrite(V4, !relais4Sate);

      btn4State = LOW;
    }
  }
  else
  {
    btn4State = HIGH;
  }



}

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);
  Blynk.syncVirtual(V4);

}

void checkPhysicalButton1();



void setup()
{
  WiFi.begin(ssid, pass);
  //timer.setInterval(3000L, checkBlynk); // check if connected to Blynk server every 3 seconds
  Blynk.config(auth);
  sensors.begin();  // debut de la librairie capteur de température
  // Debug console
  Serial.begin(9600);


  pinMode(relais1, OUTPUT);
  pinMode(btn1, INPUT_PULLUP);
  digitalWrite(relais1, relais1Sate);
  pinMode(ledV1, OUTPUT);
  pinMode(ledR1, OUTPUT);

  pinMode(relais2, OUTPUT);
  pinMode(btn2, INPUT_PULLUP);
  digitalWrite(relais2, relais2Sate);
  pinMode(ledV2, OUTPUT);
  pinMode(ledR2, OUTPUT);

  pinMode(relais3, OUTPUT);
  pinMode(btn3, INPUT_PULLUP);
  digitalWrite(relais3, relais3Sate);
  pinMode(ledV3, OUTPUT);
  pinMode(ledR3, OUTPUT);

  pinMode(relais4, OUTPUT);
  pinMode(btn4, INPUT_PULLUP);
  digitalWrite(relais4, relais4Sate);
  pinMode(ledV4, OUTPUT);
  pinMode(ledR4, OUTPUT);


  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  // Clear the buffer
  display.clearDisplay();
  display.display();


  timer.setInterval(100L, checkPhysicalButton1);

  timer.setInterval(10000L, temperature);


}



void loop()
{

  Blynk.run();
  timer.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

This…

means nothing to anyone.

And, for the third time…

Pete.

here is my code with one pair of physical/widget buttons

#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>



#include <SPI.h>
#include <Wire.h>


BlynkTimer timer;

char auth[] = "xxxxxxxxxxxxxxxxxxxxx";

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

// Set your LED and physical button pins here
const int relais1 = 14;
const int btn1 = 27;
const int ledV1 = 5;
const int ledR1 = 2;

int relais1Sate = LOW;
int btn1State = HIGH;
int ledV1State = LOW;
int ledR1State = LOW;





BLYNK_WRITE(V1) {
  relais1Sate = param.asInt();
  Serial.print("Widget Button V1 changed. Writing ");
  Serial.print(relais1Sate);
  Serial.print(" to Relay 1 and LED V1, and ");
  Serial.print(!relais1Sate);
  Serial.println(" to LED R1 ...");

  digitalWrite(relais1, relais1Sate);
  digitalWrite(ledV1, relais1Sate);
  digitalWrite(ledR1, !relais1Sate);



}





void checkPhysicalButton1()
{
  if (digitalRead(btn1) == LOW)
  {
    Serial.print("Location A, btn1 = ");
    Serial.print(digitalRead(btn1));
    Serial.print(" btn1State = ");
    Serial.println(btn1State);

    // btnState is used to avoid sequential toggles
    if (btn1State != LOW)
    {
      Serial.print("Location B, btn1 = ");
      Serial.print(btn1);
      Serial.print(", btn1State = ");
      Serial.println(btn1State);

      // Toggle LED state
      relais1Sate = !relais1Sate;

      Serial.print("Location C, writing ");
      Serial.print(relais1Sate);
      Serial.println(" to Relay 1 ...");

      digitalWrite(relais1, relais1Sate);

      ledV1State = !ledV1State;

      Serial.print("Location D, writing ");
      Serial.print(!ledV1State);
      Serial.print(" to LED V1 and ");
      Serial.print(ledV1State);
      Serial.println(" to LED R1 ...");

      digitalWrite(ledV1, !ledV1State);
      digitalWrite(ledR1, ledV1State);

      // Update Button Widget

      Serial.print("Location E, writing ");
      Serial.print(!relais1Sate);
      Serial.println(" to Button Widget on pin V1 ...");

      Blynk.virtualWrite(V1, !relais1Sate);

      btn1State = LOW;
    }
  }
  else
  {
    btn1State = HIGH;
  }






 
}

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V1);


}

void checkPhysicalButton1();



void setup()
{
  WiFi.begin(ssid, pass);
  //timer.setInterval(3000L, checkBlynk); // check if connected to Blynk server every 3 seconds
  Blynk.config(auth);

  // Debug console
  Serial.begin(9600);


  pinMode(relais1, OUTPUT);
  pinMode(btn1, INPUT_PULLUP);
  digitalWrite(relais1, relais1Sate);
  pinMode(ledV1, OUTPUT);
  pinMode(ledR1, OUTPUT);

  


  timer.setInterval(100L, checkPhysicalButton1);




}



void loop()
{

  Blynk.run();
  timer.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}

my synchronization / synchronization problem happens randomly. it may be a conection problem. is it possible to write on the serial monitor the quality of connection?

There is no point in posting code without a description of the issue that you are encountering with that code, or without the serial output and a description of the actions (widget/physical button presses etc) that you did to produce that serial output.

This should work…

long rssi = WiFi.RSSI();
Serial.print("rssi = ");
Serial.println(rssi);

Pete.

Here is my problem:
I turn on esp.
I press on the buton widget the change of state is working fine
I press the physical button there is a change of state, but there is a problem with synchronization with application. look at the “location E”

10:05:12.622 -> [136] Connecting to blynk-cloud.com:80
10:05:17.604 -> [5137] Connecting to blynk-cloud.com:80
10:05:18.185 -> [5704] Ready (ping: 306ms).
10:05:18.799 -> Widget Button V1 changed. Writing 1 to Relay 1 and LED V1, and 0 to LED R1 ...
10:05:30.784 -> Widget Button V1 changed. Writing 0 to Relay 1 and LED V1, and 1 to LED R1 ...
10:05:37.842 -> Widget Button V1 changed. Writing 1 to Relay 1 and LED V1, and 0 to LED R1 ...
10:05:42.445 -> Widget Button V1 changed. Writing 0 to Relay 1 and LED V1, and 1 to LED R1 ...
10:05:47.059 -> Widget Button V1 changed. Writing 1 to Relay 1 and LED V1, and 0 to LED R1 ...
10:05:54.905 -> Location A, btn1 = 0 btn1State = 1
10:05:54.940 -> Location B, btn1 = 27, btn1State = 1
10:05:54.975 -> Location C, writing 0 to Relay 1 ...
10:05:55.043 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
10:05:55.077 -> Location E, writing 1 to Button Widget on pin V1 ...
10:05:58.827 -> Location A, btn1 = 0 btn1State = 1
10:05:58.862 -> Location B, btn1 = 27, btn1State = 1
10:05:58.897 -> Location C, writing 1 to Relay 1 ...
10:05:58.931 -> Location D, writing 1 to LED V1 and 0 to LED R1 ...
10:05:59.000 -> Location E, writing 0 to Button Widget on pin V1 ...
10:06:02.999 -> Location A, btn1 = 0 btn1State = 1
10:06:03.033 -> Location B, btn1 = 27, btn1State = 1
10:06:03.101 -> Location C, writing 0 to Relay 1 ...
10:06:03.135 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
10:06:03.169 -> Location E, writing 1 to Button Widget on pin V1 ...
10:06:03.236 -> Location A, btn1 = 0 btn1State = 0

with this code I get the number -76. is it good ?

In that case, you need to remove the NOT (!) operators from this piece of code…

Google is your friend…

Pete.

I deleted the not (!)
The synchronization problem is still there.

When I press the button widget several times and leave it in the ON position, when I press the physical button the synchronization is good

10:39:02.058 -> [134] Connecting to blynk-cloud.com:80
10:39:07.042 -> [5135] Connecting to blynk-cloud.com:80
10:39:07.519 -> [5604] Ready (ping: 310ms).
10:39:07.859 -> Widget Button V1 changed. Writing 1 to Relay 1 and LED V1, and 0 to LED R1 ...
10:39:09.355 -> Widget Button V1 changed. Writing 0 to Relay 1 and LED V1, and 1 to LED R1 ...
10:39:11.195 -> Widget Button V1 changed. Writing 1 to Relay 1 and LED V1, and 0 to LED R1 ...
10:39:17.748 -> Location A, btn1 = 0 btn1State = 1
10:39:17.782 -> Location B, btn1 = 27, btn1State = 1
10:39:17.815 -> Location C, writing 0 to Relay 1 ...
10:39:17.885 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
10:39:17.919 -> Location E, writing 1 to Button Widget on pin V1 ...
10:39:17.986 -> Location A, btn1 = 0 btn1State = 0
10:39:19.246 -> Location A, btn1 = 0 btn1State = 1
10:39:19.280 -> Location B, btn1 = 27, btn1State = 1
10:39:19.314 -> Location C, writing 1 to Relay 1 ...
10:39:19.383 -> Location D, writing 1 to LED V1 and 0 to LED R1 ...
10:39:19.417 -> Location E, writing 0 to Button Widget on pin V1 ...
10:39:19.485 -> Location A, btn1 = 1 btn1State = 0

but if I leave the button widget in the OFF position, when I press the physical button the synchronization is inverted with application

10:40:04.965 -> Widget Button V1 changed. Writing 0 to Relay 1 and LED V1, and 1 to LED R1 ...
10:40:10.249 -> Location A, btn1 = 0 btn1State = 1
10:40:10.282 -> Location B, btn1 = 27, btn1State = 1
10:40:10.316 -> Location C, writing 1 to Relay 1 ...
10:40:10.349 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
10:40:10.417 -> Location E, writing 0 to Button Widget on pin V1 ...
10:40:10.486 -> Location A, btn1 = 0 btn1State = 0
10:40:14.240 -> Location A, btn1 = 0 btn1State = 1
10:40:14.274 -> Location B, btn1 = 27, btn1State = 1
10:40:14.344 -> Location C, writing 0 to Relay 1 ...
10:40:14.378 -> Location D, writing 1 to LED V1 and 0 to LED R1 ...
10:40:14.413 -> Location E, writing 1 to Button Widget on pin V1 ...
10:40:14.482 -> Location A, btn1 = 0 btn1State = 0
10:40:16.634 -> Location A, btn1 = 0 btn1State = 1
10:40:16.703 -> Location B, btn1 = 27, btn1State = 1
10:40:16.736 -> Location C, writing 1 to Relay 1 ...
10:40:16.771 -> Location D, writing 0 to LED V1 and 1 to LED R1 ...
10:40:16.805 -> Location E, writing 0 to Button Widget on pin V1 ...
10:40:16.872 -> Location A, btn1 = 0 btn1State = 0

Can you post a screenshot of how the button widget on V1 is configured in the app?

And can you post the ACTUAL code that produced the serial output in the post above?

Pete.

here is my screenshot

I also do not put a video. the connected popup appears when I turn on my esp. When I press my widget button a diconnected popup appears

Pete.

#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>



#include <SPI.h>
#include <Wire.h>


BlynkTimer timer;

char auth[] = "xxxxxxxxxxxxxxx";

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

// Set your LED and physical button pins here
const int relais1 = 14;
const int btn1 = 27;
const int ledV1 = 5;
const int ledR1 = 2;

int relais1Sate = LOW;
int btn1State = HIGH;
int ledV1State = LOW;
int ledR1State = LOW;





BLYNK_WRITE(V1) {
  relais1Sate = param.asInt();
  Serial.print("Widget Button V1 changed. Writing ");
  Serial.print(relais1Sate);
  Serial.print(" to Relay 1 and LED V1, and ");
  Serial.print(!relais1Sate);
  Serial.println(" to LED R1 ...");

  digitalWrite(relais1, relais1Sate);
  digitalWrite(ledV1, relais1Sate);
  digitalWrite(ledR1, !relais1Sate);



}







void checkPhysicalButton1()
{
  if (digitalRead(btn1) == LOW)
  {
    Serial.print("Location A, btn1 = ");
    Serial.print(digitalRead(btn1));
    Serial.print(" btn1State = ");
    Serial.println(btn1State);

    // btnState is used to avoid sequential toggles
    if (btn1State != LOW)
    {
      Serial.print("Location B, btn1 = ");
      Serial.print(btn1);
      Serial.print(", btn1State = ");
      Serial.println(btn1State);

      // Toggle LED state
      relais1Sate = !relais1Sate;

      Serial.print("Location C, writing ");
      Serial.print(relais1Sate);
      Serial.println(" to Relay 1 ...");

      digitalWrite(relais1, relais1Sate);

      ledV1State = !ledV1State;

      Serial.print("Location D, writing ");
      Serial.print(!ledV1State);
      Serial.print(" to LED V1 and ");
      Serial.print(ledV1State);
      Serial.println(" to LED R1 ...");

      digitalWrite(ledV1, !ledV1State);
      digitalWrite(ledR1, ledV1State);

      // Update Button Widget

      Serial.print("Location E, writing ");
      Serial.print(!relais1Sate);
      Serial.println(" to Button Widget on pin V1 ...");

      Blynk.virtualWrite(V1, relais1Sate);

      btn1State = LOW;
    }
  }
  else
  {
    btn1State = HIGH;
  }






 
}

BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V1);


}

void checkPhysicalButton1();



void setup()
{
  WiFi.begin(ssid, pass);

  Blynk.config(auth);

  // Debug console
  Serial.begin(9600);


  pinMode(relais1, OUTPUT);
  pinMode(btn1, INPUT_PULLUP);
  digitalWrite(relais1, relais1Sate);
  pinMode(ledV1, OUTPUT);
  pinMode(ledR1, OUTPUT);

  


  timer.setInterval(100L, checkPhysicalButton1);




}



void loop()
{


  Blynk.run();
  timer.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}