Page 1 of 1

CR2032 Battery Monitoring using ESP32

Posted: Tue Feb 13, 2024 6:05 pm
by esp32Steve
I have the following circuit which seems to work. My question is whats the resistive load/drain on the battery, if any, that I should consider using mofsets and resistors so they battery lasts a long time.

+BAT -> A0 of ESP32. Common Grounds.

Code: Select all

const int analogPin = A0;

void setup() {
   Serial.begin(115200);
   
   //only measure during bootup, works for our use case
   int batteryValue = analogRead(analogPin);
   float batteryVoltage = batteryValue * (3.3 / 4095.0); // Convert ADC value to voltage
   Serial.print("Battery Voltage: ");
   Serial.println(batteryVoltage);
   // Configure analog pin as input with no pull-up or pull-down -- will this do it to essentially disconnect the battery from ESP32?
   pinMode(analogPin, INPUT);
}

void loop() {
  // Additional code here...
  delay(30000); // Just for demonstration, adjust as needed
}
My multimeter (I don't have high end sophisticated ones) shows 0uA consumption possibly because the consumption is in nA. The ESP32 is USB 5v powered. The battery, I would like to last a couple of years (non-voltage-measuring usage of battery will make it approximately last 2 years); and I want to make sure the drain, if any, when not measuring the voltage does not reduce the battery life to mere months.

Any thoughts?

Re: CR2032 Battery Monitoring using ESP32

Posted: Wed Feb 14, 2024 12:08 pm
by MicroController
Will the ESP be connected to the battery while not powered?

Re: CR2032 Battery Monitoring using ESP32

Posted: Wed Feb 14, 2024 3:51 pm
by esp32Steve
When the device is not powered the only connection to ESP is +BAT to the A0 pin of ESP32 (and common ground). The battery powers another clock like chip with minute draw.

Re: CR2032 Battery Monitoring using ESP32

Posted: Thu Feb 15, 2024 9:10 am
by MicroController
That may be a problem. When provided a voltage higher than its supply voltage (= 0V when not powered) on an IO pin, the ESP may in effect try to draw power via the IO pin.

Re: CR2032 Battery Monitoring using ESP32

Posted: Thu Feb 15, 2024 6:41 pm
by esp32Steve
hmm, thats interesting. So I guess I use a MOSFET to be safe both ways (when powered or not)?

Re: CR2032 Battery Monitoring using ESP32

Posted: Fri Feb 16, 2024 10:32 am
by MicroController
I guess you'll need a P-channel MOSFET to control Vbat+ into the ESP, plus an N-channel MOSFET to control the gate of the P-channel from an 'active-high' IO pin or the ESP's 3.3V supply.
Or, if possible, you can control only the GND between the ESP and the battery with an N-channel FET.