Skip to content

SARA AFF - Battery

Charging the battery

The battery can be charged by a connected USB cable and/or by the solar input.
It is possible to connect a USB charger and a solar panel.

The solar input is 5V. You can connect any other 5V device to charge the battery.

The change LED will lit when the battery is charged.
The LED will be off when the battery is full.

Reading the battery voltage

#define ADC_AREF 3.3f
#define BATVOLT_R1 4.7f
#define BATVOLT_R2 10.0f
#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;
}