Get battery voltage

The Picoclick-C3 comes with an optimized battery monitoring feature which won't consume any power while not in use. For comparison: the C3T needs about 3µA of current even if the Picoclick is not in active state.

To read the voltage of the battery you have to change the state of ADC_ENABLE_PIN from high to low after which the voltage can be read for a few milliseconds. After reading the battery voltage it is useful to go back to a high state of that pin in order to read the voltage again afterwards.

The function below reads the analog pin where the ADC is connected to and returns the filtered (sum of 100 divided by 100) battery voltage in volts. In the last row of code the raw analog value will be converted to a voltage value by using a multiplier. If needed a constant linear offset can be added as well.

#define BAT_VOLT_MULTIPLIER   1.43
#define BAT_VOLT_OFFSET       0

float get_battery_voltage(){
  digitalWrite(ADC_ENABLE_PIN, LOW);
  delayMicroseconds(10);
  int sum = 0;
  for(int i=0; i<100; i++){
    sum = sum + analogRead(ADC_PIN);
  }
  float result = sum/100.0;
  digitalWrite(ADC_ENABLE_PIN, HIGH);
  return float(result) * BAT_VOLT_MULTIPLIER + BAT_VOLT_OFFSET;
}

Last updated