Read External Battery Voltage

I'm trying to read the battery voltage supplying power to my ESP32 board.

I will be powering it with 4AA NiMH batteries. I've read using a typical voltage divider can be expensive in terms of current consumption, so I found the following solution:

Has anyone used this strategy before? If so, is it worth doing as opposed to a typical voltage divider? Thanks.

On my esp8266 based Wemos mini, I use an external 180K resistor to alter the voltage divider built into the board, which consists of 100K and 220K. This gives a total resistance of 500K, which should consume around 10uA.

If you try 390K and 100K, I think this will work ok.

is it worth doing as opposed to a typical voltage divider?

It is only worth it if your application spends a lot of time in sleep mode.

Thank you for the feedback!

It is only worth it if your application spends a lot of time in sleep mode.

Some context... I am using one of these Adafruit TPL5110 Low Power Timer Breakout : ID 3435 : $4.95 : Adafruit Industries, Unique & fun DIY electronics and kits to wake the board up every 10 minutes. Once the board is awake and if it has something to do, it will turn on a switch. Once the switch is on, the MCU will go to sleep (ESP32 sleep) every 1 minute until it's finished.

I will only grab the battery voltage when the TPL wakes the board up.

I definitely like the idea of having a separate switching battery voltage reader since I have a few other boards that perform similar functions, and I have the spare pins on the MCU; however, I wasn't sure of the drawbacks of this approach.

If you try 390K and 100K, I think this will work ok.

Are there any drawbacks to using such high resistance?

Are there any drawbacks to using such high resistance?

Not for using a single analogue input. Do you make other analogue measurements on other channels?

Not for using a single analogue input. Do you make other analogue measurements on other channels?

Yes. On one of my boards I do use 3 other pins for analog input. The workflow would be:

  1. Switch on the voltage reader, grab the reading, then switch off (I'm not sure that switching off is necessary for that circuit, but that's a different question)

  2. Grab the analog reading off of the other 3 pins one at a time. There are 3 soil moisture sensors that are all powered via the same bus (3.3V out).

Do you think that will be an issue?

Do you think that will be an issue?

Yes if you use high value resistors. Read the battery input twice and put a small delay between them, use only the second reading.

Thanks all.

czu001:
2) Grab the analog reading off of the other 3 pins one at a time. There are 3 soil moisture sensors that are all powered via the same bus (3.3V out).

My home-made soil moisture sensors, which are very crude, but seem to work well enough, are made from pairs of 4" galvanised nails and terminal blocks. When the soil is dry, the resistance is several mega-ohms and almost no current flows. But after watering, the resistance is only a few tens of kilo-ohms, and current can be several hundred micro-amps. This is not good for battery life and not good for avoiding corrosion of the sensors (nails). To avoid these problems I use an output pin to source current/voltage for the sensors, instead of wiring them directly to 3.3V. Switch the pin to OUTPUT & HIGH just before taking the measurements and immediately back to INPUT afterwards. This technique would not be suitable for a portable moisture sensor, but for fixed-position, undisturbed sensors, it seems to work OK. Each sensor needs to be individually calibrated and not disturbed afterwards. This sounds difficult, but if you attach a button to the esp labelled "calibrate", and press this when the soil becomes just a little too dry, you can get your sketch to measure the readings for each sensor at that moment and save them (in EEPROM or SPIFFS) for later use.

Thanks for the feedback PaulRB. I will definitely try powering the soil moisture sensors via GPIO instead of the 3.3V out. I also like your idea of switching the GPIO between INPUT and OUTPUT instead of using an extra pin. I'm using some sensors I found online. They are good quality and at a decent price.

This technique would not be suitable for a portable moisture sensor

Can you explain why? Is it specific to your setup (using galvanized nails)?

I also like your idea of switching the GPIO between INPUT and OUTPUT instead of using an extra pin.

Not sure what you mean. The GPIO is an extra pin.

My simple sensors would not be suitable as portable soil moisture sensor because if you measure using dc resistance alone, no two bits of soil are quite the same. So your readings are not consistent or repeatable. Professionally designed soil moisture sensors measure capacitance of the soil using a relatively high frequency AC signal.

The extra pin meaning one pin for output and another for input.

Yes, a digital output to power the sensor and an analog input to make the reading.

If you had multiple sensors, you would need an analog input for each sensor, but you could power all of them with a single digital output.

You do need to calculate how much current the ESP32 is using whilst its awake.

Typically and ESP32 will draw 50mA when running, so if after every minutes wakeup, it runs for just a couple of seconds, then the average current is 1.7mA.

So saving a few uA here and there is unlikley to make a significant difference to battery life.

It is possible to get an ESP32 down to 8uA sleep current and you can use its own internal timer to wake it up. Unfortunatly the way most ESP32 boards are designed prevents such a miserly performance.

srnet:
Typically and ESP32 will draw 50mA when running, so if after every minutes wakeup, it runs for just a couple of seconds, then the average current is 1.7mA.

I think the OP intends to wake the esp every 10 mins in general. Waking every 1 min will only happen in particular (undisclosed) circumstances. So the average "waking" current draw will be 170uA, plus the "sleeping" current draw (which depends on the board used, but is likely to be around as much again, as a minimum, possibly much more).

I don't know much about the esp32, but if it were an esp8266, I would suggest making use of the various low power modes. The esp8266 can be made to wake into either "normal" mode (typically consuming ~80mA) or into "modem sleep" mode (typically ~20mA). If it is required to wake after 1 min, monitor some input and carry out some action that does not require WiFi access, then this should take a fraction of a second, consuming 20mA. If WiFi access is then needed, it can be switched on, data sent/received and switched off again before sleeping.

I read a review of the sleep mode power usage of a number of esp32 boards by "the guy with the Swiss accent" a while ago. Most of them were very poor in this respect. My Wemos mini modules consume around 180uA in deep sleep, which is good for a development board, much better than the NodeMCU boards for example, but still significantly higher than a bare esp8266 module.

PaulRB:
I read a review of the sleep mode power usage of a number of esp32 boards by "the guy with the Swiss accent" a while ago. Most of them were very poor in this respect. My Wemos mini modules consume around 180uA in deep sleep, which is good for a development board, much better than the NodeMCU boards for example, but still significantly higher than a bare esp8266 module.

Indeed, most all ESP32 boards have a high 'sleep' current, into the mA in some cases.

If you go bare bones ESP32 the sleep current is only 8uA.