Measuring VIN voltage


#1

Hello,

I’m using batteries to power my Duo-based devices. I’d like to measure VIN voltage Duo gets from the battery.

This would enable me to get current battery charge level so that it can be sent via ie Particle cloud or similar method over an internet connection. Could you please help me with this and point me in the right direction? I’m sure there are some Duo users out there that use batteries with their boards :slight_smile:

Any help will be greatly appreciated!


#2

Hi @maiku,

Since there is no circuit/component on-board to measure the battery level, you have to build external hardware to cooperate with software to measure the level:

Connect two 100K resistors in serial between the VIN and GND: VIN <-> R1 <-> R2 <-> GND. Then route an analog pin to the node between R1 and R2 to sample the voltage Vnode. The VIN voltage should be equal to 2*Vnode. If you adopt different R1 and R2, you should calculate the VIN voltage using different ratio.

Also you have to know the Charging/Discharging voltage curve of the battery, so that you can map the battery voltage to battery level 0% to 100%.

Kind regards,
guohui