Batterylife of D32 with Plantsensor and 700mAh Battery

Haldi4803
Posts: 9
Joined: Thu Nov 21, 2019 1:09 am

Batterylife of D32 with Plantsensor and 700mAh Battery

Postby Haldi4803 » Thu Nov 21, 2019 2:46 am

Introduction:
Howdy,

I've finished my Plantsensor with a Lolin D32 a Soil Moisture Sensore v2.0 and a 700mAh Battery. Now that it works i've wanted to share some results :)

Image
(Yes... that Cable from vBat to GPIO33 doesn't exist anymore... first time with a ESP32 board and i hear about the G35 pin for Battery voltage later on...)

Code:
The Code is rather simple:
  • Read Battery and Sensor Voltage
  • If the battery isn't below 3.3V Keep going, else go into deep sleep permanently
  • Connect to WiFi and send the Data via UDP to my Influx Database
  • Go back to Sleep

Code: Select all

#include "WiFi.h"
#include "AsyncUDP.h"

const char * ssid = "***";
const char * password = "***";

AsyncUDP udp;
float asoilmoist=analogRead(32);//global variable to store exponential smoothed soil moisture reading
float avbat=analogRead(35)/4096.0*7.445;//global variable to store Battery Voltage
#define uS_TO_S_FACTOR 1000000ULL  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 60         /* Time ESP32 will go to sleep (in seconds) */

RTC_DATA_ATTR int battCount = 0; //Save BatteryCounter in RTC Memory not wiping it in Sleep


void setup()
{
    //Serial.begin(115200); //Serial Print Deactivated if not needed

    if (avbat < 3.3)  //BATTERY Low Voltage Check
    {
      while (battCount < 5) { //Check Z Times within normal Interval if Battery is Below Y
      battCount++;
      //Serial.println((String)"Batterie unter 3,3V"); //Debug Only
      //Serial.println((String)"Bat="+avbat); //Debug Only  
      //Serial.println((String)"BattCount="+battCount); //Debug Only
      esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); //Go to Sleep for Time X  
      esp_deep_sleep_start(); //GOING into sleep!     
      }
    esp_deep_sleep_start(); //GOING into sleep without Timer, Never waking up!   
    }
    
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    if (WiFi.waitForConnectResult() != WL_CONNECTED) {
        //Serial.println("WiFi Failed");
        while(1) {
            delay(1000);
        }
    }
    if(udp.connect(IPAddress(192,168,1,2), 8089)) //{//Open UDP to Target
    //Serial.println("UDP connected");}// Debug Only
    delay(50); //Needed cause sometimes no Delay = can't send UDP packages fast enough
    //Serial.println((String)"Pflanze1 Erdfeuchte="+asoilmoist); //Debug Only
    //Serial.println((String)"Pflanze1 Batterie="+avbat); //Debug Only
    udp.print((String)"Pflanze1 Erdfeuchte="+asoilmoist);
    udp.print((String)"Pflanze1 Batterie="+avbat);    
    delay(50); //Not really sure if needed....
    esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); //Go to Sleep for Time X  
    esp_deep_sleep_start(); //GOING into sleep!   
    
}

void loop()
{

}


Batterylife with 60 seconds interval:

Aaaand right to the point... with a wakeup every 60 seconds we get a batterylife of roughly 4 days.
Image


Batterylife with 600 seconds interval: (update1)
So.... I've switched to a 10 minutes aka 600 seconds interval on the wakeups... yet batterylife did not become much better.
After 4 days i'm already down to 3.63V. That's definitly better... but no by the expected factor 10x (or realisticly factor 6-8x)
Image


Batterylife with 60 seconds and Offline Sensor: (update 1+2)
Not sure how much i can trust these cheap Voltmeters from china, especially on extremely low currents (it does show 0.05A when nothing is connected at all....) But according to this the sensor draws 260mA at ALL times.
Image
So i've made a small modification and plugged the Sensor to Pin27 instead of 3.3V Power source.
When the Sensor is powered up it needs 300~400ms before the reading becomes stable. Luckily thats about the time it needs for the decive to boot up and connect to the WiFi :) No additional delay needed! (New Code in Post 2)
Batterylife Chart will be update here after..... however long the battery runs now! I hope a few weeks at last.
(update 2)
The battery lasted from 25th Nov 01:00 to 5th Dec 06:00 that would be 10 Days and 5 Hours, or 245 Hours.
Image
Sadly it crashed 3 Times during that time. Might be because of some Software error, or what seems more reasonable because of a circuit shortcut. I did use it outdoor and it was between -5°C and +15°C Weather. No waterproof box yet. Everytime i pressed the Restart button it came back online with way lower battery. Chances are it WAS bootlooping during that time.
So i'm gonna test it again this time indoors. and see if it happens again and is software related, or hardware because of the temperature/thaw.
(update 2b)
I've redone the test with 60sec interval this time indoors. Still one crash happening, but only one and not multiples. Batterylife was now around 13 days
Image
Might have been me pushing/touching the sensor which cause this to happen. Now i got a new waterproof case and set the timing to 600 second, lets see what's happening now.




Charging:

Using my USB Powermonitor which i use for Testing my Smartphones charching capabilities i've plugged the D32 board and measured the Current / Voltage flowing trough during charging.
(And Yes... that was BEFORE i added the shutoff below 3.3V Battery.... i was really expecting the Board or battery to do that itself -.- )

The Battery Voltage measured via ESP32 every 60 seconds:
Image

The Voltage and Current flowing trough the Powermonitor:
Image

To fully charge the 700mAh Battery with a Lolin D32 Board it takes 130 Minutes or 2 Hours 10 Minutes.
The current rarely goes over 0.5A, just sometimes peaks to 0.6A so should still easily be powered by a PC USB Port.


Powerdrain on USB:

Because i was already at it i've checked the Power drain on the USB Port when the battery is fully charged.
Image

We can see a constant 9mA Powerdrain and every minute there is a peak to ca 120mA.
Because i wasn't able to properly measure that i've unplugged the Board (as seen on Minute 291 ) and switched from 1Hz Logging to 3Hz in the Powermeter. (after that the Scaling on the Time axis isn't correct anymore. But we can now properly see the peaks.

Code: Select all

90
1094
1392
90
90
258
1356
822
90
90
460
1218
340
90
90
303
1192
679
91
90
108
535
1110
137
91
90
899
1352
90
90
424
1336
227
90
Still not accurate enough to get a proper reading on powerusage during the active time.... but we get a gist of what's going on.
For proper values we'd need to measure on the battery power anyway.... but it gives a bigger overview and shows it's doing its working properly every 60 seconds.


Package Loss over UDP:

UDP might not guarantee a sent package....
In these 5950 sent dataoints i've had 69 Datapoints which were further away than 60 seconds.
When manualy checking the Timestamp of these values, most of them were 61 Seconds apart...
2019-11-16T20:09:59.616177733Z
2019-11-16T20:11:00.154275455Z

Rarely i found a truly lost package:
2019-11-17T08:02:17.486018286Z
2019-11-17T08:04:19.338263371Z

2019-11-17T17:38:33.964403765Z
2019-11-17T17:40:35.220358754Z

Removing all timing errors we're down to 23 Lost packages from a total of 5950 that would be 0.387% Package loss.
I can live with that. Also what i found was that rarely 1 package is lost, mostly it's 3-5 packages lost in a 5-15 minutes timeframe. Which points to WiFi interference. It's not like these Datapoints are extremely important, if one is missing who cares. Better the devices goes faster back into sleep and doesn't need to wait for a receive confirmation.

(Update1:)
In this 4 days i've received 580 packages, and only 1 has been lost! Thats 0.17% which is an improvement over the last run.


ToDo & Issues:

When using the Voltmeter i saw that the Plant Sensor is under voltage even when the ESP32 is in Deepsleep.
Not entirely sure how much current the board draws, but might there be some way to turn of 3.3V circuit on the ESP32 when the board enters DeepSleep?


Currently the ESP32 enters DeepSleep mode with RTC memory active when BatteryVoltage is below 3.3V for 5 ticks. Might change that to deeper sleep.
Also... what happens when i plug the Charger then? It starts Charging, but does the Board quit Deepsleep? haven't tried that yet, probably have to press the reset button after i've charged the battery.
(Update1:) Wiped Counter before going into endless Deepsleep. So next time it wakes up from whatever source it starts counting to 5 again before it goes back into eternal sleep.


Thanks for reading:
This is my 2nd ESP Project, the first was some ESP8266 ESP01 Modules with DHT22 and a 5V Powersupply for a total of 5$ per piece, because the Deepsleep wasn't that easy to use with the connect on the extra pins on the ESP01 board, they don't use it ^^
Last edited by Haldi4803 on Sat Dec 28, 2019 4:18 pm, edited 3 times in total.

Haldi4803
Posts: 9
Joined: Thu Nov 21, 2019 1:09 am

Re: Batterylife of D32 with Plantsensor and 700mAh Battery

Postby Haldi4803 » Mon Nov 25, 2019 1:01 am

Update 1:
Batterylife with 600 sec aka 10 Minute interval is only abysmal better than 60 seconds. This points to Issues with Standby and not Active time.
Removed the 3.3V from the Sensor and plugged it in pin27. Now i have to turn on Pin27 whenever the ESP leaves Deepsleep. No more useless current draw from Analog sensors during deep sleep!
The Analog Sensor needs about 300~400ms warmup before it becomes stable and delivers continous similar values. Luckily thats about the time it needs to start and connect WiFi :) no additional Delay needed.

New Code:

Code: Select all

#include "WiFi.h"
#include "AsyncUDP.h"
#define uS_TO_S_FACTOR 1000000ULL  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 60         /* Time ESP32 will go to sleep (in seconds) */
RTC_DATA_ATTR int battCount = 0; //Save BatteryCounter in RTC Memory not wiping it in Sleep

const char * ssid = "******";
const char * password = "******";

AsyncUDP udp;

void setup()
{
    //Serial.begin(115200); //Serial Print Deactivated if not needed
    pinMode(27, OUTPUT); // Use GPIO27 as Powersource instead of direct 3.3V
    digitalWrite(27, HIGH); // Set 3.3V on GPIO27 so sensor turns on
    //delay(500); //Sensor warmup/powerup break period (Unneeded due to 300~400ms from Boot to WiFi ready)
    //float asoilmoist=analogRead(32); //Can't stay here, has to go down directly before sending due to sensor warm up.
    float avbat=analogRead(35)/4096.0*7.445;//global variable to store Battery Voltage
   
    if (avbat < 3.4)  //BATTERY Low Voltage Check
    {
      while (battCount < 5) { //Check Z Times within normal Interval if Battery is Below Y
      battCount++;
      //Serial.println((String)"Batterie unter 3,3V"); //Debug Only
      //Serial.println((String)"Bat="+avbat); //Debug Only  
      //Serial.println((String)"BattCount="+battCount); //Debug Only
      esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); //Go to Sleep for Time X  
      esp_deep_sleep_start(); //GOING into sleep!     
      }
    battCount = 0; //wiper timer before going into deepsleep.
    esp_deep_sleep_start(); //GOING into sleep without Timer, Never waking up!   
    }
    
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    if (WiFi.waitForConnectResult() != WL_CONNECTED) {
        //Serial.println("WiFi Failed");
        while(1) {
            delay(1000);
        }
    }
    if(udp.connect(IPAddress(192,168,1,2), 8089)) //{   //Open UDP to Target
    //Serial.println("UDP connected");}// Debug Only
    delay(50); //Needed cause sometimes no Delay = can't send UDP packages fast enough
    float asoilmoist=analogRead(32);//global variable to store exponential smoothed soil moisture reading
    //Serial.println((String)"Pflanze1 Erdfeuchte="+asoilmoist); //Debug Only
    //Serial.println((String)"Pflanze1 Batterie="+avbat); //Debug Only
    udp.print((String)"Pflanze1 Erdfeuchte="+asoilmoist);
    udp.print((String)"Pflanze1 Batterie="+avbat);    
    delay(50); //Not really sure if needed....
    esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); //Go to Sleep for Time X  
    esp_deep_sleep_start(); //GOING into sleep!   
    
}

void loop(){}

Haldi4803
Posts: 9
Joined: Thu Nov 21, 2019 1:09 am

Re: Batterylife of D32 with Plantsensor and 700mAh Battery

Postby Haldi4803 » Thu Dec 05, 2019 9:08 pm

Batterylife with 60 seconds and Offline Sensor: (update 1+2)
Not sure how much i can trust these cheap Voltmeters from china, especially on extremely low currents (it does show 0.05A when nothing is connected at all....) But according to this the sensor draws 260mA at ALL times.
Image
So i've made a small modification and plugged the Sensor to Pin27 instead of 3.3V Power source.
When the Sensor is powered up it needs 300~400ms before the reading becomes stable. Luckily thats about the time it needs for the decive to boot up and connect to the WiFi :) No additional delay needed! (New Code in Post 2)
Batterylife Chart will be update here after..... however long the battery runs now! I hope a few weeks at last.
(update 2)
The battery lasted from 25th Nov 01:00 to 5th Dec 06:00 that would be 10 Days and 5 Hours, or 245 Hours.
Image
Sadly it crashed 3 Times during that time. Might be because of some Software error, or what seems more reasonable because of a circuit shortcut. I did use it outdoor and it was between -5°C and +15°C Weather. No waterproof box yet. Everytime i pressed the Restart button it came back online with way lower battery. Chances are it WAS bootlooping during that time.
So i'm gonna test it again this time indoors. and see if it happens again and is software related, or hardware because of the temperature/thaw.



Sidenote:
The Sensor did NOT restart WHILE it was charging. I did not unplug it.... i pressed reset button to get it working.
So either the reset of the counter doesn't work or it only starts when charging is finished.

edo76mal
Posts: 9
Joined: Wed May 11, 2022 10:17 am

Re: Batterylife of D32 with Plantsensor and 700mAh Battery

Postby edo76mal » Fri May 20, 2022 1:22 pm

Hi.

Have you tested your project using battery during charge? I mean: our project consists in gps sensor with esp32_wroom, and we need to use them for long time and without fix power sources, so we may use the system connected to a powerbank. The question is: we can use a powerbank connected to the system in double use, i.e to charge battery and to power the esp32?

Best regards, Edoardo

Haldi4803
Posts: 9
Joined: Thu Nov 21, 2019 1:09 am

Re: Batterylife of D32 with Plantsensor and 700mAh Battery

Postby Haldi4803 » Sun May 22, 2022 1:27 pm

edo76mal wrote:
Fri May 20, 2022 1:22 pm
we can use a powerbank connected to the system in double use, i.e to charge battery and to power the esp32?
Yes, if you use a Powerbank and connect it via USB to the ESP32, it will power the ESP32 and charge the LiPo Battery at the same time.
At least on the Lolin D32.
You can see that on the first picture, where USB power is used to power the device and charge the battery.

Who is online

Users browsing this forum: No registered users and 8 guests