ESP8266 keep disconnecting from WiFi

Hi, I found out that my ESP8266 keep disconnected from Wifi after a few minutes can reconnect back. This only happen when I power the ESP8266 from an external power source but did not happen when I power it from the microUSB port. I think it is related to deep sleep mode?

I tried using command WiFi.setSleepMode(WIFI_NONE_SLEEP); which I found out from other forum but it just keep happening or am I using it wrongly?

How can I keep my ESP8266 connected to WiFi all the time as I will have to control and observe my relay on Blynk apps?

Here is my code where I put WiFi.setSleepMode(WIFI_NONE_SLEEP);

Apologize as I am new to Arduino and ESP8266!

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

WidgetLED led1(V2);


 
char auth[] = "";//Enter your Auth token
char ssid[] = "";//Enter your WIFI name
char pass[] = "";//Enter your WIFI password
 
BlynkTimer timer;
bool pinValue = 0;

long duration;
int distance; 
int lvlmin = 5;

 
#define trig D7
#define echo D8
#define relay D5
 
void setup() {
  WiFi.setSleepMode(WIFI_NONE_SLEEP);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(relay, OUTPUT);
  Wire.begin(D2, D1);
  lcd.init();
  lcd.backlight();
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1L, Wlevel);
  digitalWrite(relay, HIGH);
 
}

BLYNK_CONNECTED(){
  Blynk.syncAll();
  }
 
BLYNK_WRITE(V0) {
  pinValue = param.asInt();
}
 
void loop() {
  Blynk.run();
  timer.run();
}

void Wlevel(){
  {
  digitalWrite(trig, LOW);
  delayMicroseconds(4);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  distance = duration * 0.034 / 2;
 
  Blynk.virtualWrite(V1, distance);
  Serial.println(distance);
  }
  

 if (pinValue == 1)
    {
       if (distance >= lvlmin)
       {
          digitalWrite(relay, LOW);
          led1.on();
          lcd.setCursor(0,0);
          lcd.print("Water Lvl:");
          lcd.print(distance);
          lcd.print("cm");
          lcd.setCursor(0,1);
          lcd.print("Pump: ON  (AUTO)");
          
       } 
       
       else
       {
          digitalWrite(relay, HIGH);
          Blynk.notify("Hey! Tank is full!");
          led1.off(); 
          lcd.setCursor(0, 0);
          lcd.print("Water Lvl:");
          lcd.print(distance);
          lcd.print(" cm");
          lcd.setCursor(0,1);
          lcd.print("Pump: OFF (AUTO)");
          
       }
    }
   else
    {
      digitalWrite(relay, HIGH);
      lcd.setCursor(0,0);
      lcd.print("System is OFF   ");
      lcd.setCursor(0,1);
      lcd.print("Check Blynk     ");
      led1.off();
    }

   }

Please share some details on this power source. The problem may be there, because when using WiFi, power consumption of the ESP8266 rises sharply. Your power supply may not keep up. Especially notorious are small power supplies based on a linear regulator with insufficient cooling; they heat up, switch off in thermal protection causing the microcontroller to switch off, then the regulator cools down a bit and the cycle repeats.

HI there,

I connect a MB102 5V output to the board. I used my phone adaptor for the input and the adapter is rated 9V.

Thank you

Which connects to a 12V adapter? That's exactly the kind of problem I described.

Get yourself a better power supply, this one sucks.

Edit: it's not so much that it sucks, but it just isn't up to the task of powering somewhat larger devices. This module houses two AMS1117 regulators, which are nice little devices - but emphasis on 'little'. If you feed them 12V in and ask them to give 5V out, and then start drawing 500mA (which an ESP processor may do during WiFi), the 1117 is going to dissipate 12 - 5 = 7 * .5 = 3.5W. It'll get hot! Even if power consumption remains at the 170mA level that I think is specified for the ESP8266 WiFi, it's still 7 * .15 = 1.05W which is way above the limit of an SMD AMS1117 without additional cooling measures.

1 Like

I wonder how can I solve this problem? As you said, I need a better external power supply but what what kind of external power supply would do the job ? Thank you!

What if I connect 5V supply to the MB102 and then output 5V to the board, would it be better?

Hi @clement_2001,

The breadboard power supply will not work with 5V input. If you have a 5V input, just attach it to the ESP. 500mA or more is a comfortable power supply for the ESP.

1 Like

If you have a 5V supply going into the MB102, why even have the MB102 in the first place...?

What you need is either a buck step-down converter to take the 12V (or whatever it is) from your adapter down to 5V, or get yourself a little 5V power supply that plugs directly into a wall socket...like a USB charger. They're omnipresent and often rated up to 2A or thereabouts; plenty for an ESP8266 with a handful of sensors attached to it, for instance.

2 Likes

I have an old DC adapter rated at 5V 500mA, would it able to drive the ESP8266, LCD display, 5v relay module, Ultrasonic sensor?

I am so curious why this does not happen when I am powering it using the microUSB on the board?

It depends on what you have the USB plugged into for powering it via USB. That DC adapter might work ok.

@clement_2001, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project :wink: See About the Installation & Troubleshooting category.

Thanks for using code tags in your first post.

Maybe just; it'll be on the edge. You can try though.

Simply put: your computer has a much more efficient way of making 5VDC from 115/230VAC than the MB102.