# Battery Level SAMD21proRF

**URL:** <https://community.sparkfun.com/t/battery-level-samd21prorf/36299>\
**Category:** LoRa (Long Range)\
**Created:** [February 6, 2019, 7:17am UTC](https://community.sparkfun.com/t/battery-level-samd21prorf/36299 "2019-02-06T07:17:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![awootton](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@awootton](https://community.sparkfun.com/u/awootton)\
**Post date:** [February 6, 2019, 7:17am UTC](https://community.sparkfun.com/t/battery-level-samd21prorf/36299/1 "2019-02-06T07:17:36Z")

</div>

I’d like to take (and send) battery readings. I can do this with Sodaq boards because they have a voltage divider on the Lipo charge circuit. Here’s the code to read it (NB: pin A6):

```auto
#define ADC_AREF 3.3
#define BATVOLTPIN A6
#define BATVOLT_R1 4.7
#define BATVOLT_R2 10

float getRealBatteryVoltage() {
  uint16_t batteryVoltage = analogRead(BATVOLTPIN);
  return (ADC_AREF / 1023.0) * (BATVOLT_R1 + BATVOLT_R2) / BATVOLT_R2 * batteryVoltage;
}

```

So my question is can I do this with the Sparkfun board? Looking at the schematic I see there is a divider with VBATT\_LVL marked and as far as I can see this is on A5. So can I use the same code (changing to A5 of course)?

---

<div class="post-metadata">

**Author:** ![ds18s20](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/ds18s20/32/2901_2.png) [@ds18s20](https://community.sparkfun.com/u/ds18s20)\
**Post date:** [December 24, 2020, 10:54pm UTC](https://community.sparkfun.com/t/battery-level-samd21prorf/36299/2 "2020-12-24T22:54:40Z")

</div>

Wondering the same? Did A5 work for you?

---

<div class="post-metadata">

**Author:** ![ds18s20](https://yyz1.discourse-cdn.com/sparkfun/user_avatar/community.sparkfun.com/ds18s20/32/2901_2.png) [@ds18s20](https://community.sparkfun.com/u/ds18s20)\
**Post date:** [December 26, 2020, 4:10pm UTC](https://community.sparkfun.com/t/battery-level-samd21prorf/36299/3 "2020-12-26T16:10:30Z")

</div>

> awootton:  
> Although it seems like this board has major ADC accuracy bug with Arduino…
> 
> [https://www.omzlo.com/articles/your-ard … you-notice](https://www.omzlo.com/articles/your-arduino-samd21-adc-is-wrong-did-you-notice)
