element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Just Encase
  • Challenges & Projects
  • Design Challenges
  • Just Encase
  • More
  • Cancel
Just Encase
Blog [Pool Water Monitoring] #9 Arduino MKR 1300 WAN battery monitoring
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Just Encase to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: feiticeir0
  • Date Created: 29 Dec 2021 12:25 AM Date Created
  • Views 1520 views
  • Likes 6 likes
  • Comments 5 comments
  • Arduino MKR 1300 WAN battery monitoring
  • MKR1300
  • Arduino MKR WAN 13000
  • battery voltage reading
  • just_encase
  • just encase
  • battery monitoring
Related
Recommended

[Pool Water Monitoring] #9 Arduino MKR 1300 WAN battery monitoring

feiticeir0
feiticeir0
29 Dec 2021

image

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.

MKR 1300 with batteries

I'm using a alligator clips because the batteries case is for 3 and not 2, so I'm bypassing here ! Slight smile .

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)

MKR 1300 battery reading

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

  • Sign in to reply

Top Comments

  • feiticeir0
    feiticeir0 over 3 years ago in reply to skruglewicz +1
    Hi skruglewicz ! Thank you for your words. I don't think your problem is power related. I had the exact same problem - until I've disabled all the references to the Serial console. See if you have…
  • ralphjy
    ralphjy over 3 years ago in reply to skruglewicz +1
    Steve, The schematic shows that the the batteries are connected in back of the 3.3V regulator as I would have expected. You can't get 5V when running on the 2AA batteries. You could a USB power bank…
  • skruglewicz
    skruglewicz over 3 years ago in reply to ralphjy

    Thank you for the clarification ralphjy

    I have a solar USB power bank that I might try to use in the case.

    Regards

    Stevek skruglewicz

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 3 years ago in reply to skruglewicz

    Steve,

    The schematic shows that the the batteries are connected in back of the 3.3V regulator as I would have expected.  You can't get 5V when running on the 2AA batteries.  You could a USB power bank if you can find one that fits the case.

    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • skruglewicz
    skruglewicz over 3 years ago in reply to feiticeir0

    HI feiticeir0

    Thanks for getting back to me on my problem with the MKR WAN 1300 Battery connector.

    I've already disabled the check for Serial in my code and have run my sketch that sends a counter value being incremented over LoRa to my receiver LoRa as described in my Blog#3. and that works off Battery.

    I'm just assuming it's power, because when I upload my sketch that uses the 5V pin it just doesn't seem to run after I disconnect the USB connector. .It only runs if I have the USB power connected.

    Wondering if the 5V output does not work when the MKR is running off of the 3.3V battery connector?

    Also I'm using a  temp sensor  (ELENKER DS18B20 Temperature Sensor Waterproof Digital Thermal Probe)  I hade on hand,  connected to the MKR 5V pin and pin D2. I could not get it to put out the correct value using the 3V3 and the D4 pin.

    Are you sensors in your design using the 5v pin on the MKR?

    I'm going to move on to running off of USB power for my design and leave the Battery connector for a later time. It's a shame because I was planning on running the sensor module on battery in the enclosures. Oh well, I have to drill a hole in one and attach a cable gland to run power and temp sensor wires through.

    Let me know what you think I'm doing wrong or if  you find that the 5V pin does not give power if the Battery is connected?. I'm kinda running behind here on the implementation of my design.

    Thanks for your insight

    Steve K

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • feiticeir0
    feiticeir0 over 3 years ago in reply to skruglewicz

    Hi skruglewicz! Thank you for your words.

    I don't think your problem is power related. I had the exact same problem - until I've disabled all the references to the Serial console.

    See if you have anything that sends to or starts the serial console. The LoRa examples use and initialize the Serial console - but it is not present when not connected to the computer and it hangs there, waiting for a Serial console to appear.

    Cheers

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • skruglewicz
    skruglewicz over 3 years ago

    Hi feiticeir0 

    Very infesting blog on using batteries with the MKR WAN 1300. I will be sure to check it out to check my batteries for my challenge.

    I've run into an issue trying to get the 3v battery connector to work with a temp sensor described in my 4th blog 

    /challenges-projects/design-challenges/just-encase/b/blog/posts/blog4testing

    I can get the battery working without the USB connected.. I've tried the blink sketch and my unit test sketch for sending LoRa data referred to in my 3rd blog

    /challenges-projects/design-challenges/just-encase/b/blog/posts/blog4testing

    in blog#4 I've been able to get the sender sketch to work with the USB cable connected
    But, when I disconnect the USB cable it stops sensing temperature ? I know this because my LoRa receiver is not getting data.
    Is this because the temp sensor is requiring 5V?
    My guess is that the 5v Pin on the MKR  is not putting out 5v when a 3V battery is connected!

    Now I'm unable to run my sketch on batteries and my design is to run sensors in the enclosure on battery power!!!

    Any idea on what I could do? 

    I do have a Power Supply Module MB 102(5V/3V) (Displayed below).

    Could I power my temp sensor circuit using it and run the yellow wire over to the MKR pin 2?

    image

    Thanks in advance for your insight

    skruglewicz     AKA    Steve K

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube