NodeMCU continously disconnecting

Hello,
I have NodeMCU which is connected to 16x2 LCD and a DHT11 sensor. My project is that the DHT11 data is displayed on LCD screen as well as on Blynk app and I have some trigers added into it for some special cases such as high temp etc. I have my local server setup.

After flashing the NodeMCU with my code, the NodeMCU connects to server then after few seconds disconnects and again connects. To debug the issue I connected my NodeMCU to my PC without sensor and LCD, but still the same problem was there, as i thought it could be low power problem. I tried the blink example, it worked fine.

The code of my project is:-

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
char auth[] = "XXXXXXXXXXXXXXXXXX";
char ssid[] = "ssid";
char pass[] = "password";

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

#define DHTPIN 8          
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

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

  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  
  if (isnan(h) || isnan(t)) {
    digitalWrite(4, HIGH);
    lcd.setCursor(0,0);
    lcd.print(F("Failed to read !!"));
    lcd.setCursor(0,1);
    lcd.print(F("               "));     // Spaces to make 2nd line clear of lcd
    return;
  }

  if (t > 30) {
    digitalWrite(5, HIGH);             
    lcd.setCursor(13,1);
    lcd.print(F(" * "));
  }

  else {
    digitalWrite(5, LOW);
    lcd.setCursor(14,1);
    lcd.print(F(" "));
  }

  digitalWrite(4, LOW);
  lcd.setCursor(0,0);
  lcd.print(F("Humidity: "));
  lcd.print(h, 0);
  lcd.print(F(" %"));
  lcd.setCursor(0,1);
  lcd.print(F("Temp: "));
  lcd.print(t, 2);
  lcd.print(F(" C"));

  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, IPAddress(35,154,12,218), 8080);    //Local server IP
  lcd.begin(16,2);
  dht.begin();
  timer.setInterval(2000L, sendSensor);
}

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

At 115200 baud rate in serial monitor i get following message

ets Jan  8 2013,rst cause:4, boot mode:(3,6)
wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
vbb28d4a3
~ld

This says something in your sketch is locking up the loop and thus causing the ESPs “Watch Dog Timer” to timeout and reset.

Pepper your sketch with further Serial prints to allow your “overview” of your sketches step by step progress. Blynk also has a Debug option that might help.

http://docs.blynk.cc/#blynk-firmware-debugging-define-blynk_debug

1 Like

This is probably your issue. Research what pins you can use on a NodeMCU (ESP8266)

3 Likes

Thank You @Toro_Blanco, I got my mistake. Actually I wrote this code for arduino then later changed it for NodeMCU but forgot to change the DHT pin.