rlogiacco / BatterySense

Arduino library to monitor battery consumption
GNU Lesser General Public License v3.0
402 stars 75 forks source link

Arduino MKR WiFi 1010 Battery Level #29

Closed philipdbrown closed 4 years ago

philipdbrown commented 4 years ago

Hey, Thanks for this library. However, I'm having issues obtaining the battery level. It always reads 100. I have a Li-Po 3.7v 1000mAh battery connected to the Arduino through the on-board JST connector. Any ideas on what issues I may be having? Thanks in advance.

Battery battery = Battery(3000, 4200, ADC_BATTERY);
...
battery.begin(3300, 1.47);
...
battery.level()
rlogiacco commented 4 years ago

Sorry mate, that's a question for the Arduino forum, and I advise to:

None of us has a crystal ball :wink:

If you get a solution and you wish to share it here I'll update the issue label from invalid to question.

tangram67 commented 3 years ago

Although this thread is closed I will comment the request. Maybe the answer is helpful: The level is read to 100% because the MKR analog input uses an internal reference voltage at 2.23 Volt by default. The voltage of the battery is much higher, so you should use the 3.3 Volt on the AREF pin. Tthe rest is scaled by the resistors of the voltage divider on the MKR board, so check your divider value to fit to your board. Also set the reference voltage to external source:

  // Set ADC parameters
  analogReference(AR_EXTERNAL);
  analogReadResolution(10);

Have not tested this, but should work.

rlogiacco commented 3 years ago

Tanks a million mate for your answer: definitely I didn't know about the different reference. I would like to add another option for those who might incur into the same issue: use the internal reference but use a voltage divider to get into the correct range.

tangram67 commented 3 years ago

Great idea to use this as an option! Here is an example for a Arduino MKR NB 1500: The on-board the divider is 1.275 (the resistors are 1.2M and 0.33M). So the analog input range is 3.3 V (AREF) * 1.275 = 4.2 Volt and that fits to the max. loading voltage of a Lithium battery ;-)