CR2032 Battery Monitoring using ESP32

esp32Steve
Posts: 3
Joined: Tue Feb 13, 2024 5:52 pm

CR2032 Battery Monitoring using ESP32

Postby esp32Steve » Tue Feb 13, 2024 6:05 pm

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?

MicroController
Posts: 1552
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: CR2032 Battery Monitoring using ESP32

Postby MicroController » Wed Feb 14, 2024 12:08 pm

Will the ESP be connected to the battery while not powered?

esp32Steve
Posts: 3
Joined: Tue Feb 13, 2024 5:52 pm

Re: CR2032 Battery Monitoring using ESP32

Postby esp32Steve » Wed Feb 14, 2024 3:51 pm

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.

MicroController
Posts: 1552
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: CR2032 Battery Monitoring using ESP32

Postby MicroController » Thu Feb 15, 2024 9:10 am

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.

esp32Steve
Posts: 3
Joined: Tue Feb 13, 2024 5:52 pm

Re: CR2032 Battery Monitoring using ESP32

Postby esp32Steve » Thu Feb 15, 2024 6:41 pm

hmm, thats interesting. So I guess I use a MOSFET to be safe both ways (when powered or not)?

MicroController
Posts: 1552
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: CR2032 Battery Monitoring using ESP32

Postby MicroController » Fri Feb 16, 2024 10:32 am

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.

Who is online

Users browsing this forum: No registered users and 98 guests