ESP32 V3 read battery voltage

How do you read the battery voltage for the new ESP32 V3 boards? Any suggestions are welcome.

1 Like

WiFi_Kit_series/AnalogRead.ino at master · Heltec-Aaron-Lee/WiFi_Kit_series (

I have seen this code to read analog signals. But which pin is connected to the battery? Pin 1?

Yes, indeed, GPIO1 is ADC pin

Good day

Do you know, how can i detect if the board is powered normal/ with the battery?


@mechanix your best bet is to do a bit of a guess on the battery voltage: a normal battery never goes above 4.2 or 4.3 volts, so if you read more than that, it’ll likely be due to USB power. On USB, I usually read about 4.8 volts.

I do have a piece of code somewhere that can detect whether the board is connected to a USB host (such as a computer or laptop), but it fails to register if it is connected to e.g. a powerbank or simply a USB wall adapter. So that’s not really useful for this.

Hello and many thanks for your reply!

That is what i am trying to have - a signal, when the power is disconnected. Basically, I want to store some variables in flash memory when the power goes out. I want to power it with onboard 5V pin, but i can also use usb port. So far i found only an idea with simple voltage divider (2 resistors) - to lower voltage under 3V and measure it on a pin. Can you advise?


The easiest should be the following:

  • always read the battery voltage
  • if the battery voltage < 4.3 Volts, then you are on battery power
  • if the battery voltage > 4.3 Volts, then the battery is charging due to some power source (USB or 5V)

Since the battery voltage pin already has a built-in voltage divider, you shouldn’t require any modifications or additions.

Good day.

I need to save the variables in the exact moment when the power goes off. The voltage at battery goes down, but not that fast. I think measuring this 5V pin can solve my issue.

Thank you for the time and help!