Understanding battery example

Probably (I’m sure) my question is so easy and I’m a beginner.

I’m starting with Sodaq one V3 and the first thing that I want to know is the value of the battery. For this purpose I use the code of the example,

#define ADC_AREF 3.3f
// #define BATVOLT_R1 2.0f // One v1
// #define BATVOLT_R2 2.0f // One v1
#define BATVOLT_R1 4.7f // One v2 and v3
#define BATVOLT_R2 10.0f // One v2 and v3
#define BATVOLT_PIN BAT_VOLT

void setup() {
  // put your setup code here, to run once:
  SerialUSB.begin(57600);

  while(!SerialUSB){
    //wait for Serial Monitor to be opened
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  SerialUSB.println(getBatteryVoltage());

  delay(1000);
}

uint16_t getBatteryVoltage()
{
    uint16_t voltage = (uint16_t)((ADC_AREF / 1.023) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * (float)analogRead(BATVOLT_PIN));

    return voltage;
}

My output is something like this:
4201
4196
4201
4201
4201
4201
4201
4196

I understand that values are the current current in mA (the Sodaq is connected with the usb to my computer). But what is the maximum value I can reach? I want to know it, because I want to convert it to a percentage from 0 to 100.

Sorry for this low level question, thank very much.

Hi @mmr689,

4200 will be the reading when the battery is fully charged.
A reading of 3500 will be the lowest voltage by the board. (the battery is not empty)
When the voltage will be lower than 3500 the board doesn’t get enough voltage to be turned on.

So I recommend to use 0-100 from 3500-4200

Best regards,
Jan

1 Like