LowPowerLab Forum

Hardware support => Moteino M0 => Topic started by: kwalkerk on August 28, 2018, 09:53:35 AM

Title: Battery Monitor
Post by: kwalkerk on August 28, 2018, 09:53:35 AM
Does the M0 have a pin I can use for a battery monitor similar to pin A7 on regular Motion?

Thanks
Title: Re: Battery Monitor
Post by: Felix on August 28, 2018, 11:02:21 AM
Yes, please see schematic, it's on A5, marked "Vmon" on silkscreen.
Title: Re: Battery Monitor
Post by: mbutki on August 31, 2019, 09:59:46 PM
For anyone wondering, here's the formula for using A5 on the Moteino M0.

analogRead(A5) * 2 * 3.3 / 1024

The Moteino M0 uses two 1M resistors, so the output voltage of the voltage divider is just half the input. The first thing we do then is to multiply it by 2 to get back to the original voltage.

3.3v is the reference voltage. It's the max value that A5 is expecting.

We divide by 1024 (2^10) because by default the ADC is doing a 10 bit conversion. This was a little confusing for me at first, since the Moteino M0 page lists the ADC as 12 bit, which would be 4096 (2^12). With a little google-ing, it looks like 10 bit is the default, but can be changed to 12 bit if desired.

When I use this with USB power I get 4.8v, which is pretty close to 5v, and with my 3.7v LiPo battery I get 4.24v, which sounds about right for fully charged.