Problems waking up from Deep Sleep using Blynk

Hi. Very new to Arduino & coding so please bare with me.

I have built a Water level monitoring system for use with my outside water tanks. It uses an ultrasonic detector and a Wemos Mini D1 for wifi communication. I have added a DeepSleep function to save battery power. The current code sets DeepSleep for 2 minutes and all works well however if I try and extend the DeepSleep time beyond 2 minutes, it seems the Wemos Mini D1 doesn't want to wake up. I have tried three, five, ten minutes but the system remains offline. Anything up. to 2 minutes works great. What am I doing wrong?

Code listed below (apologies if it is clunky).

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "XXXXXXXXXXXXXX"
#define BLYNK_DEVICE_NAME "House Water tank"
#define BLYNK_AUTH_TOKEN "XXXXXXXXXXXXXXXXX"

// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define trig D5   // Trig pin
#define echo D6 
char auth[] = BLYNK_AUTH_TOKEN;
int depth = 247.5;      //depthof tank
int r = 175.0;           // radius of tank in cm
int volume;                // capacity in liters

unsigned int raw=0;
float volt=0.0;
float bat_percentage=0.0;
int analogInPin  = A0; 

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

BlynkTimer timer;
 
void waterlevel()
{
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  
  digitalWrite(trig, LOW);
  long t = pulseIn(echo, HIGH);
  long cm = t / 29 / 2;
  Serial.println(cm);
  long level= depth-cm;
  if (level<0)
  level=0;
  long vol = level;
  Serial.println(level);
  level = map(level,0,depth-27.5,0,100);
  Blynk.virtualWrite(V0, level);
    long v = ((3.14*(r*r))*(vol)); // formula to calculate volume in cubic cm
  long volume = v/1000; // final capacity in liters
   Serial.println(volume);
   
   Blynk.virtualWrite(V1, volume);
  delay(200);
  
  raw = analogRead(A0);
  
volt=raw/1023.0;
volt=volt*4.2;
 Serial.println(volt);


     
     Blynk.virtualWrite(V2, volt);
  delay(200);

  ESP.deepSleep(120e6);

}

Thanks in advance.

That code doesn't compile, so it's not complete. The problem is most often in that part of the code people are hiding from us.

Sorry my bad. Here is teh full code.

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID "XXXXXXXXXXXXXX"
#define BLYNK_DEVICE_NAME "House Water tank"
#define BLYNK_AUTH_TOKEN "XXXXXXXXXXXXXXXXXXXXXXXXX"

// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define trig D5   // Trig pin
#define echo D6 
char auth[] = BLYNK_AUTH_TOKEN;
int depth = 240.0;      //depthof tank
int r = 175.0;           // radius of tank in cm
int volume;                // capacity in liters

unsigned int raw=0;
float volt=0.0;
float bat_percentage=0.0;
int analogInPin  = A0; 

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

BlynkTimer timer;
 
void waterlevel()
{
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  
  digitalWrite(trig, LOW);
  long t = pulseIn(echo, HIGH);
  long cm = t / 29 / 2;
  Serial.println(cm);
  long level= depth-cm;
  if (level<0)
  level=0;
  long vol = level;
  Serial.println(level);
  level = map(level,0,depth,0,90);
  Blynk.virtualWrite(V0, level);
    long v = ((3.14*(r*r))*(vol)); // formula to calculate volume in cubic cm
  long volume = v/1000; // final capacity in liters
   Serial.println(volume);
   
   Blynk.virtualWrite(V1, volume);
  delay(200);
  
  raw = analogRead(A0);
  
volt=raw/1023.0;
volt=volt*4.2;
 Serial.println(volt);


     
     Blynk.virtualWrite(V2, volt);
  delay(200);

  ESP.deepSleep(120e6);

}


void setup()
{
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(A0, INPUT);
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(10L, waterlevel);

  
}

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




  }

Might be obvious but did you connect GPIO16 to RESET?

Wait, did you try to properly set deep sleep like so?

    esp_sleep_enable_timer_wakeup( 60000000 ); // set timer to wake up once a minute 60000000uS
    esp_deep_sleep_start();

Can you properly line out your code (in IDE hit ctrl-T)?
Only one statement is dependent on your if()?
Or should there be a block of code {} there?
You realize a long is an integer? And that you loose precision upon division?

That's for an ESP32, I think. The OP is using an ESP8266.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.