MKR Zero Read Battery Voltage

See how much battery you have left!

Dec 6, 2016

25422 views

9 respects

Components and supplies

1

Arduino MKR Zero

1

LiPo Battery

Apps and platforms

1

Arduino IDE

1

Arduino Web Editor

Project description

Code

Downloadable files

MKRZERO Read Battery Voltage schematic

MKRZERO Read Battery Voltage schematic

MKRZERO Read Battery Voltage schematic

MKRZERO Read Battery Voltage schematic

Comments

Only logged in users can leave comments

andreas_waldherr

4 years ago

Hi Arduino_Genuino & mstcgn, thanks for sharing - exactly what I am searching for!!! I used it with my MKR WAN 1310 (LoRa) controllers. This MKR variant does not have the ADC_BATTERY assignment and the voltage divider in place. The SAMD21 pin PB09 is needed to control the LoRa chip. I just build the voltage divider and used a other free analog pin (A1 in my case). Works great too... +------------ VBATT (+3,7V) | R = 330k | +------------ A1 | R = 1200k | +------------ GND Andreas

Anonymous user

5 years ago

Thanks for sharing. Seems to work well with the MKR GSM 1400.

Anonymous user

5 years ago

For the MKR series, the internal reference voltage for the measurement is set to 3.3V by default. It can be additionally set again in setup(): void setup() { ... analogReference(AR_DEFAULT); // 3.3V ... } See https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/ Thus the measuring range goes from 0 (0V) to 1023 (3.3V). In front of the analog input is a voltage divider consisting of two resistors, 1.2 MOhm and 330 kOhm (=0.33 MOhm). Therefore I calculate the voltage as follows: float batteryLevel = analogRead(ADC_BATTERY) * 3.3f / 1023.0f / 1.2f * (1.2f+0.33f);

Anonymous user

5 years ago

Works fine also with MKRNB 1500 for measuring LiPo battery voltage. For getting accurate readings, I had to put a small multiplier (measured / AnalogReading = correction). ``` float voltage = (sensorValue * (4.3 / 1023.0))*0.969543; //0.969543 is here for compensating difference between measured and AnalogRead value

Anonymous user

6 years ago

Sorry, on my MKR GSM 1400 this code allways display 4.3v. Can someone help me? I need to sense my LIPO. I tried with other battery in storage level off charge (3.84v) and the same happened

Anonymous user

6 years ago

I have concerns about this project correctness. Can someone address my concerns. ``` // read the input on analog pin 0: ``` Is this code comment correct? According to MKR Zero schematic it is BP09. Also next statement uses ADC_BATTERY. ``` // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 4.3V): ``` Why maximum voltage 4,3 V is used? According to SAMD21 data sheet 37.10.4 Analog-to-Digital (ADC) characteristics maximum can be +VREF/GAIN. Why there is no physical connection for VREFA or VREFB. Where the reference voltage comes from? There is also physical voltage divider in MKR Zero board before PB09. How this example addresses it?

Anonymous user

6 years ago

I have a Arduino MKR 1400 gsm. Would this code work for my GSM board?

Anonymous user

2 years ago

Yes, just tested it with MKR GSM 1400 and it works.