I have a battery powered ESP32, and I want to measure battery voltage to know when it’s time to change or recharge it. I thought connecting the positive lead of the battery to one of the pins and doing the following would work, but it always returns the same number 3.16V. What am I doing wrong?
How long have you kept the battery connected to see if it’s not going down? What voltage is battery? Is it a 4.2V battery. You will need a voltage divider with a multiplication factor or will damage esp32. I think ESP32 can only measure up to 3V or so.
It’s a 3.2V battery and it never changed all the way until the battery died. I forgot to mention, that when powered via USB the measurement seems to work (and also has small fluctuations whereas when battery powered it’s literally the same number all the time).
It feels like it’s measuring voltage compared to the power source, and as a result always returns the same number even as the power source voltage changes. Is that just my imagination?
I suspect your 3.2V isn’t enough voltage or perhaps current to run an ESP32 to do it’s primary function and measure the battery voltage. When you run a good 5V via usb it all works well. Different ESP32 boards will have different needs. A more bare board may need less power and battery will last longer. Something based on esp8266
The chip runs just fine for much more power hungry functions, like wifi, so I don’t think that’s it. And I do need an ESP32 board (because I need to be able to wake it up when a reed switch closes or opens), otherwise I’d measure VCC instead, which definitely works correctly on the 8266.
If you don’t put the ESP to deep sleep does it read the correct voltage? Are you using mqtt? Perhaps if this is the case then it fails to send voltage and HA just reports the only value it had from the very first time.
No and no. Googling this issue I see other people encountering a similar problem with no resolution. I’m going to switch to a lolin32 board shortly (currently running dev board without the regulator) - here’s to hoping the problem magically goes away then.
Hi, did you get anywhere with this?
I am trying to figure out the same thing - I have wamos s2 mini board (esphome board: lolin_s2_mini) and all I am getting from adc is one value.
Hi, I had the same problem receiving the same voltage value regardless of actual voltage changes. Surprisingly what helped me was when I moved the input GND connection to a different GND pin on ESP32-Cam (I did not need camera functionality and did not have another board at the moment, so I just soldered the + voltage input wire directly onto GPIO36 and the minus wire to GND in the same row on ESP32-Cam and it started to measure correctly right away).
I might add that the ESPHome documentation states that “the usable ADC range was from ~0.075V to ~3.12V (with the attenuation: auto setting)”.
If your battery is above 3.12V, it could be capping/limiting to that. So you may have to divide (resistor/voltage divider) the battery voltage before the ADC input. For example, to divide into half: