Hello all again. Hope everyone is safe and well.
One of the necessities of this project, is remote monitoring. In most cases, the Arduino MKR 1300 WAN will not be connected to mains power or USB. Fortunately, the MKR 1300 WAN can be powered by 2 AA batteries and it does provide the means to monitor it's voltage.
For it, we're going to use the ADC_BATTERY pin from arduino_pins.h and do some calculations for it to be the most accurate possible.
Analog Reference
The analogReference function will set the reference voltage when reading an analog value from a battery. For the MKR 1300, we can use the value AR_INTERVAL1V0, meaning 1v reference.
This will allow the reading to be the most accurate possible.
The code will use the value from the full voltage from both batteries (use a multimeter or voltmeter) to give a better value of current conditions.
Code
This code can be seen here, in the Arduino forums.
#include <pins_arduino.h> /* * Battery volage full 2x AA batteries */ float battery_voltage = 3.202; // use multimeter void setup() { // put your setup code here, to run once: Serial.begin(115200); } void loop() { analogReadResolution(10); analogReference(AR_INTERNAL1V0); // put your main code here, to run repeatedly: int batteryLevel = analogRead(ADC_BATTERY); float voltage = batteryLevel * (battery_voltage / 1023.0); Serial.print("Voltage: "); Serial.println(voltage); float battery_percentage = ((voltage * 100) / battery_voltage); Serial.print("Batery Percentage: "); Serial.print(battery_percentage); Serial.println("%"); delay(5000); }
Upload the code to the Arduino and start measuring.
I'm using a alligator clips because the batteries case is for 3 and not 2, so I'm bypassing here ! .
The LED is on because the Arduino it's also connected through USB - so I (and you) can see the measurements - hence the light is on.
According to the documentation (few people (myself included) reads that on the first times) - My last blog entry mentions this - when powered by batteries, there's no LED on to save on battery ! Clever girls and boys from Arduino.
Here is the battery readings for my both AA (full charge)
And here it is, a way to measure your Arduino juice.
Happy holidays and an excellent New Year of 2022
References
https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/
https://forum.arduino.cc/t/reading-the-battery-voltage-of-the-supply-battery/546518/11
Top Comments