Voltage calculation on MKR1010 using Lipo battery 3.7V

Hi Guys,

I'm a newbie here :slight_smile:
I saw this code on this page:

void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(ADC_BATTERY);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 4.3V):
  float voltage = sensorValue * (4.3 / 1023.0);
  // print out the value you read:
  Serial.print(voltage);
  Serial.println("V");
}

I would like to know if I should change the 4.3 value to 3.7 'coz im using 3.7V battery?

Thanks in advance!

For accurate results you should replace 4.3 with whatever voltage is actually being used as the ADC reference.

If that is the battery, then it is not the nominal voltage of 3.7V. A LiPo battery will have voltage somewhere between about 4.2 and 3.0 V, depending on its state of charge, as you can measure with your multimeter.

Another, minor issue: the correct divisor is 1024, not 1023.

Cypher01:
I would like to know if I should change the 4.3 value to 3.7 'coz im using 3.7V battery?

To get it fairly accurate I'd set it to about 3.85V. As already said the actual voltage of a battery will vary with the state of charge but provided you are recharging your battery reasonably often it will probably spend most of it's life somewhere around 3.7-4.0V so I reckon 3.85V is a reasonable compromise.

Steve

Opened for https://forum.arduino.cc/index.php?action=profile;u=402451

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.