0

ESP32 Feather V2 Batt Monitor wrong voltage
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ESP32 Feather V2 Batt Monitor wrong voltage

by djoob on Mon Jul 04, 2022 12:25 am

I must have my math wrong. I cannot figure out how to read the battery voltage on the ESP32 Feather V2 board.

Code: Select all | TOGGLE FULL SIZE
#define BAT_MON 35
float measuredvbat = 0;

void setup() {
  Serial.begin(115200);
  pinMode(BAT_MON, INPUT);
}

void loop() {
  measuredvbat = analogRead(BAT_MON);
  measuredvbat *= 2;    // we divided by 2, so multiply back
  measuredvbat *= 3.3;  // Multiply by 3.3V, our reference voltage
  measuredvbat /= 4096; // convert to voltage
  Serial.print("VBat: " );
  Serial.println(measuredvbat);
  delay(1000);
}


Serial output says. VBat: 3.84 however a multimeter shows the battery voltage is 4.2v

The schematic shows a voltage divider that should divide the voltage in half.

Image

I've tried several variations found online with no luck getting the correct voltage.

djoob
 
Posts: 3
Joined: Mon Jul 04, 2022 12:04 am

Re: ESP32 Feather V2 Batt Monitor wrong voltage

by adafruit_support_mike on Tue Jul 05, 2022 9:27 pm

The code looks right. What output are you getting?

adafruit_support_mike
 
Posts: 64984
Joined: Thu Feb 11, 2010 2:51 pm

Re: ESP32 Feather V2 Batt Monitor wrong voltage

by djoob on Tue Jul 05, 2022 9:40 pm

Serial output says:
VBat: 3.84

However, a multimeter shows the battery voltage is 4.2v

djoob
 
Posts: 3
Joined: Mon Jul 04, 2022 12:04 am

Re: ESP32 Feather V2 Batt Monitor wrong voltage

by adafruit_support_mike on Wed Jul 06, 2022 5:45 pm

There we go..

The ESP32's ADC has a 3.6V reference. Try using that value instead of 3.3V:

Code: Select all | TOGGLE FULL SIZE
  measuredvbat *= 3.6;  // Multiply by 3.6V, our reference voltage

adafruit_support_mike
 
Posts: 64984
Joined: Thu Feb 11, 2010 2:51 pm

Re: ESP32 Feather V2 Batt Monitor wrong voltage

by djoob on Wed Jul 06, 2022 6:05 pm

AH. Thank you!

djoob
 
Posts: 3
Joined: Mon Jul 04, 2022 12:04 am

Please be positive and constructive with your questions and comments.