Esp8266 keeps disconnect with wifi and reconnects back as loop

i cant rectify this error i have tried multiple way but i dont know to clear kindly guide

here is my code

#include <LiquidCrystal_I2C.h>

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

#include <DHT.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

char auth[] = "VMC281MzkiQa3OxZ62U-56i";//Enter your Auth token

char ssid[] = "D-Link-vimal";//Enter your WIFI name

char pass[] = "ypkrex8dxx";//Enter your WIFI password

DHT dht(D4, DHT11); //(sensor pin,sensor type)

BlynkTimer timer;

bool pirbutton = 0;

#define Buzzer 10

#define MQ2 A0

#define flame D0

#define PIR D3

#define trig D5

#define echo D6

#define relay1 D7

#define relay2 D8

BLYNK_WRITE(V0) {

  pirbutton = param.asInt();

}

void setup() {

  Serial.begin(9600);

  lcd.init();

  lcd.backlight();

  pinMode(Buzzer, OUTPUT);

  pinMode(flame, INPUT);

  pinMode(PIR, INPUT);

  pinMode(trig, OUTPUT);

  pinMode(echo, INPUT);

  pinMode(relay1, OUTPUT);

  pinMode(relay2, OUTPUT);

  digitalWrite(relay1, HIGH);

  digitalWrite(relay2, HIGH);

  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);

  dht.begin();

  lcd.setCursor(0, 0);

  lcd.print("  Initializing  ");

  for (int a = 5; a <= 10; a++)

  {

    lcd.setCursor(a, 1);

    lcd.print(".");

    delay(500);

  }

  lcd.clear();

  timer.setInterval(100L, gassensor);

  timer.setInterval(100L, DHT11sensor);

  timer.setInterval(100L, flamesensor);

  timer.setInterval(100L, pirsensor);

  timer.setInterval(100L, ultrasonic);

  return;

}

//mq sensor

void gassensor()

{

  int value = analogRead(MQ2);

  Serial.println(value);

  value = map(value, 0, 1024, 0, 100);

  if (value <= 35)

  {

    digitalWrite(Buzzer, LOW);

  } else if (value > 35)

  {

    Blynk.logEvent("GAS DEDECTOR","Warning! Gas leak detected");

    digitalWrite(Buzzer, HIGH);

  }

  Blynk.virtualWrite(V1, value);

  lcd.setCursor(9, 0);

  lcd.print("G :");

  lcd.print(value);

  lcd.print("  ");

}

//Get the DHT11 sensor values

void DHT11sensor() {

  float h = dht.readHumidity();

  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {

    Serial.println("Failed to read from DHT sensor!");

    return;

  }

  Blynk.virtualWrite(V2, t);

  Blynk.virtualWrite(V3, h);

  lcd.setCursor(0, 0);

  lcd.print("T :");

  lcd.print(t);

  lcd.setCursor(0, 1);

  lcd.print("H :");

  lcd.print(h);

}

//flame sensor

void flamesensor()

{

  bool value = digitalRead(flame );

  if (value == 1)

  {

    digitalWrite(Buzzer, LOW);

  } else if (value == 0)

  {

    Blynk.logEvent("FIRE", "Warning! Fire was detected");

    digitalWrite(Buzzer, HIGH);

  }

}

//pir sensor

void pirsensor()

{

  bool value = digitalRead(PIR);

  if (pirbutton == 1)

  {

    if (value == 0)

    {

      digitalWrite(Buzzer, LOW);

    } else if (value == 1)

    {

      Blynk.logEvent("CHECK", "Warning! Please check your security system");

      digitalWrite(Buzzer, HIGH);

    }

  }

}

//ultrasonic sensor

void ultrasonic() {

  digitalWrite(trig, LOW);

  delayMicroseconds(4);

  digitalWrite(trig, HIGH);

  delayMicroseconds(10);

  digitalWrite(trig, LOW);

  long t = pulseIn(echo, HIGH);

  long cm = t / 29 / 2;

  Blynk.virtualWrite(V4, cm);

  lcd.setCursor(9, 1);

  lcd.print("W :");

  lcd.print(cm);

  lcd.print("  ");

}

void loop() {

  Blynk.run();

  timer.run();

}

@vimalbethuraj Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

I am very new this community, thanks for your polite guidance.
is there any thing else that has to be changed…?

and it keeps disconnect and reconnect in short loop manner
in blynk platform it shows online and offline very frequently
There fore i can’t able to see the results which is in platform

Your sketch is missing the three lines of configuration data from the web console Device > Device Info screen.
You should copy/paste these at the top of your sketch, delete this line…

then replace this line…

with…

Blynk.config(BLYNK_AUTH_TOKEN)

You also have some very odd stuff in your sketch, like this 'return` at the end of your void setup…

A two and a half second delay AFTER you’ve connected to Blynk…

and five timers that are all trying to run at exactly the same time…

even though your MCU isn’t capable of multi-tasking.

I would replace this with a timer that calls a single function that either performs these tasks sequentially, or calls the five functions sequentially.

If this doesn’t fix your issue then post your revised sketch and your serial output.
When you do this, DO NOT post a screenshot of your serial monitor.
Copy the text text from the serial monitor and paste it between triple backticks.

Pete.

Also, you will run-iun to issues with these commands…

The way your code is written you could easily log two events per second (with the 500ms timers) and possibly 6 events per second.

There is a limit of 100 events per 24 hour period, so you could exceed this in 33 seconds with your current code.

Pete.

yeah, i changed to the needs still its being in same issue like disconnect and reconnect

code ref

/*Full home automation system using the nodemcu and Blynk app
 * https://srituhobby.com
 */

#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

char auth[] = "VMC281Mz1ChrTLy8xkiQa3OxZ62U-56i";//Enter your Auth token
char ssid[] = "D-Link-vimal";//Enter your WIFI name
char pass[] = "ypkrex8dxx";//Enter your WIFI password

DHT dht(D4, DHT11); //(sensor pin,sensor type)
BlynkTimer timer;
bool pirbutton = 0;

#define Buzzer 10
#define MQ2 A0
#define flame D0
#define PIR D3
#define trig D5
#define echo D6
#define relay1 D7
#define relay2 D8

BLYNK_WRITE(V0) {
  pirbutton = param.asInt();
}

void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();

  pinMode(Buzzer, OUTPUT);
  pinMode(flame, INPUT);
  pinMode(PIR, INPUT);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);

  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  Blynk.begin(auth, ssid, pass);
  dht.begin();

  lcd.setCursor(0, 0);
  lcd.print("  Initializing  ");
  for (int a = 5; a <= 10; a++) 
  {
    lcd.setCursor(a, 1);
    lcd.print(".");
    delay(500);
  }
  lcd.clear();

  timer.setInterval(100L, gassensor);
  timer.setInterval(200L, DHT11sensor);
  timer.setInterval(300L, flamesensor);
  timer.setInterval(400L, pirsensor);
  timer.setInterval(500L, ultrasonic);
  
}
//mq sensor
void gassensor() 
{
  int value = analogRead(MQ2);
  Serial.println(value);
  value = map(value, 0, 1024, 0, 100);
  if (value <= 35) 
  {
    digitalWrite(Buzzer, LOW);
  } else if (value > 35) 
  {
    Blynk.logEvent("GAS DEDECTOR","Warning! Gas leak detected");
    digitalWrite(Buzzer, HIGH);
  }
  Blynk.virtualWrite(V1, value);
  lcd.setCursor(9, 0);
  lcd.print("G :");
  lcd.print(value);
  lcd.print("  ");
}
//Get the DHT11 sensor values
void DHT11sensor() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Blynk.virtualWrite(V2, t);
  Blynk.virtualWrite(V3, h);

  lcd.setCursor(0, 0);
  lcd.print("T :");
  lcd.print(t);

  lcd.setCursor(0, 1);
  lcd.print("H :");
  lcd.print(h);
}
//flame sensor
void flamesensor() 
{
  bool value = digitalRead(flame );
  if (value == 1) 
  {
    digitalWrite(Buzzer, LOW);
  } else if (value == 0) 
  {
    Blynk.logEvent("FIRE", "Warning! Fire was detected");
    digitalWrite(Buzzer, HIGH);
  }
}
//pir sensor
void pirsensor() 
{
  bool value = digitalRead(PIR);
  if (pirbutton == 1) 
  {
    if (value == 0) 
    {
      digitalWrite(Buzzer, LOW);
    } else if (value == 1) 
    {
      Blynk.logEvent("CHECK", "Warning! Please check your security system");
      digitalWrite(Buzzer, HIGH);
    }
  }
}
//ultrasonic sensor
void ultrasonic() {
  digitalWrite(trig, LOW);
  delayMicroseconds(4);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  long t = pulseIn(echo, HIGH);
  long cm = t / 29 / 2;
  Blynk.virtualWrite(V4, cm);
  lcd.setCursor(9, 1);
  lcd.print("W :");
  lcd.print(cm);
  lcd.print("  ");
}


void loop() {
  Blynk.run();
  timer.run();
}

here the serial monitor shows

[10972] Connected to WiFi
[10972] IP: 192.168.1.29
[10972] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.2.0 on ESP8266

 #StandWithUkraine    https://bit.ly/swua
[10970] Connected to WiFi
[10971] IP: 192.168.1.29
[10971] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.2.0 on ESP8266

 #StandWithUkraine    https://bit.ly/swua
[11099] Connecting to blynk.cloud:80
[11323] Ready (ping: 68ms).
H���!9�D����	�[1141] Connecting to D-Link-vimal

still disconnects from wifi

what can i do for this, can you assist me with this code

I’m not sure what this is meant to mean, but you’ve ignored most of my suggestions.
Any reason for that?

Pete.

I have tried this too but this is the actual code


#include <LiquidCrystal_I2C.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

char auth[] = "tiMY12sK15MYJpQVS49larATTXB35U02";//Enter your Auth token
char ssid[] = "Dialog 4G 025";//Enter your WIFI name
char pass[] = "b2016ee3";//Enter your WIFI password

DHT dht(D4, DHT11); //(sensor pin,sensor type)
BlynkTimer timer;
bool pirbutton = 0;

#define Buzzer 10
#define MQ2 A0
#define flame D0
#define PIR D3
#define trig D5
#define echo D6
#define relay1 D7
#define relay2 D8

BLYNK_WRITE(V0) {
  pirbutton = param.asInt();
}

void setup() {
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  pinMode(Buzzer, OUTPUT);
  pinMode(flame, INPUT);
  pinMode(PIR, INPUT);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  Blynk.begin(auth, ssid, pass);
  dht.begin();
  timer.setInterval(100L, gassensor);
  timer.setInterval(100L, DHT11sensor);
  timer.setInterval(100L, flamesensor);
  timer.setInterval(100L, pirsensor);
  timer.setInterval(100L, ultrasonic);
}

void gassensor() {
  int value = analogRead(MQ2);
  Serial.println(value);
  value = map(value, 0, 1024, 0, 100);
  if (value <= 35) {
    digitalWrite(Buzzer, LOW);
  } else if (value > 35) {
    Blynk.notify("Warning! Gas leak detected");
    digitalWrite(Buzzer, HIGH);
  }
  Blynk.virtualWrite(V1, value);
  lcd.setCursor(9, 0);
  lcd.print("G :");
  lcd.print(value);
  lcd.print("  ");
}

void DHT11sensor() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  Blynk.virtualWrite(V2, t);
  Blynk.virtualWrite(V3, h);

  lcd.setCursor(0, 0);
  lcd.print("T :");
  lcd.print(t);

  lcd.setCursor(0, 1);
  lcd.print("H :");
  lcd.print(h);
}

void flamesensor() {
  bool value = digitalRead(flame );
  if (value == 1) {
    digitalWrite(Buzzer, LOW);
  } else if (value == 0) {
    Blynk.notify("Warning! Fire was detected");
    digitalWrite(Buzzer, HIGH);
  }
}
void pirsensor() {
  bool value = digitalRead(PIR);
  if (pirbutton == 1) {
    if (value == 0) {
      digitalWrite(Buzzer, LOW);
    } else if (value == 1) {
      Blynk.notify("Warning! Please check your security system");
      digitalWrite(Buzzer, HIGH);
    }
  }
}

void ultrasonic() {
  digitalWrite(trig, LOW);
  delayMicroseconds(4);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  long t = pulseIn(echo, HIGH);
  long cm = t / 29 / 2;
  Blynk.virtualWrite(V4, cm);
  lcd.setCursor(9, 1);
  lcd.print("W :");
  lcd.print(cm);
  lcd.print("  ");
}


void loop() {
  Blynk.run();
  timer.run();
}

but it show the error

WARNING: library LiquidCrystal I2C claims to run on avr architecture(s) and may be incompatible with your current board which runs on esp8266 architecture(s).
C:\Users\vimal\AppData\Local\Temp\Temp1_sketch_feb26a-20230430T081059Z-001.zip\sketch_feb26a\sketch_feb26a.ino: In function 'void gassensor()':
C:\Users\vimal\AppData\Local\Temp\Temp1_sketch_feb26a-20230430T081059Z-001.zip\sketch_feb26a\sketch_feb26a.ino:62:11: error: 'class BlynkWifi' has no member named 'notify'
   62 |     Blynk.notify("Warning! Gas leak detected");
      |           ^~~~~~
C:\Users\vimal\AppData\Local\Temp\Temp1_sketch_feb26a-20230430T081059Z-001.zip\sketch_feb26a\sketch_feb26a.ino: In function 'void flamesensor()':
C:\Users\vimal\AppData\Local\Temp\Temp1_sketch_feb26a-20230430T081059Z-001.zip\sketch_feb26a\sketch_feb26a.ino:98:11: error: 'class BlynkWifi' has no member named 'notify'
   98 |     Blynk.notify("Warning! Fire was detected");
      |           ^~~~~~
C:\Users\vimal\AppData\Local\Temp\Temp1_sketch_feb26a-20230430T081059Z-001.zip\sketch_feb26a\sketch_feb26a.ino: In function 'void pirsensor()':
C:\Users\vimal\AppData\Local\Temp\Temp1_sketch_feb26a-20230430T081059Z-001.zip\sketch_feb26a\sketch_feb26a.ino:108:13: error: 'class BlynkWifi' has no member named 'notify'
  108 |       Blynk.notify("Warning! Please check your security system");
      |             ^~~~~~

exit status 1

Compilation error: 'class BlynkWifi' has no member named 'notify'

Nope, actually i dont yet to know where to change kindly assist me with full code
which helps me with go further

So you want me to write your code for you?
That isn’t going to happen.

Pete.

No iam not meant like that, where u could assist with my errors

just kindly refer this

Dht11 needs more than 1 second…
I’d increase all timers by 2000

thank you so much, i will try this

I’d suggest that you try re-reading posts #5 and #6

Pete.