Onboard Battery Level of this ESP32? Voltage divider / Battery level

Hi all I’m trying to understand if there is a simple way in Esphome to measure the level of the integrated 1860 battery on this thing?

image

https://www.aliexpress.com/item/32991132248.html?spm=a2g0s.9042311.0.0.27424c4dIBpxCQ

I understand it’s trivial with an ESP8266 but maybe not an Esp32? (From ESP8266 Measuring VCC and this.) “On the ESP8266 you can even measure the voltage the chip is getting”.

Can anyone help me clarify or point me in the right direction if there is a very simple way? I dunno what I’m doing….

Maybe I need to do a voltage divider wiring thingy to an analog input? But I was hoping it might be easier?

This was helpful and has a pin schema (translates pretty well from Russian). I think what I bought might be a Wemos TTGO ESP-WROOM-32 rip-off?

1 Like

Hello @Mahko_Mahko

this has been already done here :slight_smile: : https://community.home-assistant.io/t/measuring-vin-not-vcc-on-a-nodemcu/142062

use a voltage divider on VIN with 2 resistor and read with an analog pin

Enjoy

1 Like

Thanks for the quick response Oliver!

I guess I was hoping there might be a way without any additional hardware/wiring given the battery is integrated?

Or am I dreaming:) ?

1 Like

yes you dreaming looool

ha ha thanks for confirming:)

1 Like

While I abandoned the original project, I got back to this for another project and thought I’d drop some more details here as the info I found was a little scattered and confusing for a newbie…

Based on:

  1. This article: ESP8266 battery level meter | ezContents blog,

  2. This thread: ESPHome Battery Level Sensor,

  3. These objectives and resistors I had:

  4. Some help/checks from @ssieb over on Discord,

  5. This board/schema

  6. The ESPHome docs: Analog To Digital Sensor — ESPHome

  7. This wiring

  8. And this ESPHome config:

sensor:
  - platform: adc
    id: solar_plant_batt_voltage 
    pin: GPIO32
    attenuation: auto
    name: ${friendly_name} Battery Voltage
    update_interval: 1s
    accuracy_decimals: 1
    filters:
    #use moving median to smooth spikes
      - median:
          window_size: 10
          send_every: 10
          send_first_at: 10
      - delta: 0.1 #Only send values to HA if they change 
      - throttle: 30s #Limit values sent to Ha
#Convert the Voltage to a battery  level (%)
  - platform: copy
    source_id: solar_plant_batt_voltage
    id: solar_plant_batt_level
    icon: "mdi:battery"
    name: ${friendly_name} Battery Level
    unit_of_measurement: '%'
    accuracy_decimals: 1
    filters:
      - calibrate_linear:
      # Map from voltage to Battery level
          - 0.41 -> 0
          - 3.1 -> 100
      #Handle/cap boundaries
      - lambda: |
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);
      - delta: 0.5 #Only send values to HA if they change 
      - throttle: 30s #Limit values sent to Ha

I’m not really 100% if both of the black wires are required?
Only one ground is required.

8 Likes

You only need one of them.

1 Like

3.0 volts is 0%
3.3 volts is 100%
ESP stops working correctly if the voltage is less than 3.0 volts

1 Like

I seem to have corrected that later in my final config. Thanks for pointing that out.