Battery Voltage Measurements using ADC

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Battery Voltage Measurements using ADC

Postby Ritesh » Tue Dec 20, 2016 5:54 pm

Hi,

I have started to work on ESP32 chip and in that we have one requirement in which whole system will be operating over battery connected with VDD1 and VDD2 pins which are external power source.

So, how to meause battery voltage over ADC interface?

Let me know if anyone has measures it using ADC reading API and it will be great if provide any sample for that.
  • Also what should be reference voltage that I need to consider for that?

    And what are the voltage deviders I need to put for that if my battery input will be 4.2 V?

    And how to check battery charging status and power good status in some intervals? Any APIs or examples based on ADC readings?
Let me know if anyone has any clue of information for that
Regards,
Ritesh Prajapati

onehorse
Posts: 70
Joined: Mon Feb 15, 2016 1:35 am

Re: Battery Voltage Measurements using ADC

Postby onehorse » Tue Dec 20, 2016 6:26 pm

I use a 27 kOhm + 100 kOhm voltage divider to bring the 4.2 V maximum of a single cell LiPo battery down to 3.3 V, which is the reference voltage (AFAIK) of the ESP32 board I am using. I have the voltage divider connected to pin 34, and I read the pin as follows:

Code: Select all

    float VBAT = (127.0f/100.0f) * 3.30f * float(analogRead(34)) / 4096.0f;  // LiPo battery
    Serial.print("Battery Voltage = "); Serial.print(VBAT, 2); Serial.println(" V");    
The ADC is 12-bit which is why the 3.3/4096 (ref voltage/max counts) conversion factor is in there. When the analog read returns 0, the battery voltage is 0, and when it returns 4095, the battery voltage is 4.2 V. The response of the ESP32 ADCs is apparently non-linear so you will have to calibrate the response and correct for maximum accuracy.

Ritesh
Posts: 1365
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: Battery Voltage Measurements using ADC

Postby Ritesh » Tue Dec 20, 2016 6:48 pm

Hi,

Thanks for quick reply...I think there are total 2 ADC ino ESP32 but I am not sure both are 12 bit or not. So, you have used ADC 1 channel. Correct?

Also just for confirmation that all above readings and calculation is based on 4.2 voltage to convert it into 3.3 required voltage. Correct?

Let me correct if I am wrong at any place.
Regards,
Ritesh Prajapati

Who is online

Users browsing this forum: No registered users and 65 guests