How to measure battery level on ESP32 with 18650 lipo battery holder

Paolo_esp32
Posts: 1
Joined: Thu Oct 11, 2018 5:11 am

How to measure battery level on ESP32 with 18650 lipo battery holder

Postby Paolo_esp32 » Thu Oct 11, 2018 9:32 am

Hi all
I'm in a project based on an Esp32 with 18650 battery holder like https://www.diymore.cc/collections/wifi ... rduino-lua.

I need to read which is the current Lipo Battery level, but I'm not able to get the right pin to read the value.

I have my board connected to wifi.

I try by reading all pins at 10bits by :

Code: Select all

int pinCount = 18;  int ADCpins[] = {0,2,4,12,13,14,15,25,26,27,32,33,34,35,36,37,38,39}; // these are the ADC pins
float ADC_divider = 250/30;  // voltage divider proportions - hypothetical so far :-)
for (int thisPin = 0; thisPin < pinCount; thisPin++) {

    
    Serial.print(thisPin, DEC);     
    Serial.print(" = ");     
    Serial.print(ADCpins[thisPin], DEC);     
    Serial.print(" => ");


    adcAttachPin(ADCpins[thisPin]);
   adcStart(ADCpins[thisPin]);
   analogReadResolution(10); // Default of 12 is not very linear. Recommended to use 10 or 11 depending on needed resolution.
   analogSetAttenuation(ADC_6db); // Default is 11db which is very noisy. Recommended to use 2.5 or 6.
   int v = analogRead(ADCpins[thisPin]);

    Serial.print(" AdC= ");
    Serial.print(v);
    VBAT = (127.0f/100.0f) * 3.30f * float(v) / 1024.0f;  // LiPo battery  
    Serial.print("  Vbat = "); 
    Serial.print(VBAT); 
    Serial.println(" Volts");    
    
    delay(500);
    

  }
And I get
[Count]=[Pin] => AdC =[readAnalog() value] Vbat = [calculated voltage level]

Code: Select all

0 = 0 =>  AdC= 1023  Vbat = 4.19 Volts
1 = 2 =>  AdC= 1023  Vbat = 4.19 Volts
2 = 4 =>  AdC= 1023  Vbat = 4.19 Volts
3 = 12 =>  AdC= 1023  Vbat = 4.19 Volts
4 = 13 =>  AdC= 1023  Vbat = 4.19 Volts
5 = 14 =>  AdC= 1023  Vbat = 4.19 Volts
6 = 15 =>  AdC= 1023  Vbat = 4.19 Volts
7 = 25 =>  AdC= 1023  Vbat = 4.19 Volts
8 = 26 =>  AdC= 1023  Vbat = 4.19 Volts
9 = 27 =>  AdC= 1023  Vbat = 4.19 Volts
10 = 32 =>  AdC= 244  Vbat = 1.00 Volts
11 = 33 =>  AdC= 171  Vbat = 0.70 Volts
12 = 34 =>  AdC= 15  Vbat = 0.06 Volts
13 = 35 =>  AdC= 0  Vbat = 0.00 Volts
14 = 36 =>  AdC= 0  Vbat = 0.00 Volts
15 = 37 =>  AdC= 0  Vbat = 0.00 Volts
16 = 38 =>  AdC= 0  Vbat = 0.00 Volts
17 = 39 =>  AdC= 0  Vbat = 0.00 Volts
In my understanding on the board should be available a couple of 100K resistors connected to the battery. In between these two resistors, should be present a wire to one of ADCs of ESP32.
Even if I try to measure each single pins, I was not able to find 1.5V on one of them ADC.

In theory, due the fact I'm using wifi, I should use only ADC1 (32 to 39), but I do not see any values around 500 (as readAnalog) on my outputs.
What I've missed?

thanks a lot to all.

Return to “Hardware”

Who is online

Users browsing this forum: No registered users and 9 guests