Arduino Forum

Topics => Science and Measurement => Topic started by: JArias on Jan 26, 2019, 11:42 pm

Title: Make Arduino Measure Its Own Voltage From Vin
Post by: JArias on Jan 26, 2019, 11:42 pm
Hello, I am doing an Arduino project using Arduino Mega and a 5V cellphone powerbank. I need to make the Arduino measure its Vin voltage in order to print the powerbank's battery percentage. How can I do this? How should the circuit and code be? I have read about voltage dividers but I don't know what they are or how to build them. Please help me.

Thank you very much.
Title: Re: Make Arduino Measure Its Own Voltage From Vin
Post by: jremington on Jan 27, 2019, 12:54 am
See https://forum.arduino.cc/index.php?topic=435065.0 (https://forum.arduino.cc/index.php?topic=435065.0) and http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/ (http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/)
Title: Re: Make Arduino Measure Its Own Voltage From Vin
Post by: wvmarle on Jan 27, 2019, 01:00 pm
The output of a 5V power bank will be 5V regardless of battery level, until the battery is empty.
Title: Re: Make Arduino Measure Its Own Voltage From Vin
Post by: JArias on Jan 27, 2019, 04:31 pm
Thank you very much
Title: Re: Make Arduino Measure Its Own Voltage From Vin
Post by: MarkT on Mar 01, 2019, 08:23 pm
powerbanks internally have a 3.7V lithium battery and 5V boost converter.  The state of charge is
indicated by a row of LEDs.  If you want more sophisticated you may have to roll your own...
Title: Re: Make Arduino Measure Its Own Voltage From Vin
Post by: Idahowalker on Mar 01, 2019, 11:42 pm
Just for your own reference here is a link to getting the values for a divider:

http://www.ohmslawcalculator.com/voltage-divider-calculator (http://www.ohmslawcalculator.com/voltage-divider-calculator)
Title: Re: Make Arduino Measure Its Own Voltage From Vin
Post by: freaklabs on Mar 20, 2019, 03:10 pm
You would actually need a voltage reference that is independent of the power supply you are trying to measure. You can't measure a power supply when it's also the reference. Hence you would need a voltage reference and a voltage divider with the power supply voltage at the top. the divider output would then go into the ADC and the ADC should be configured to use the external voltage reference. In this way, you can measure your battery voltage.
Title: Re: Make Arduino Measure Its Own Voltage From Vin
Post by: wvmarle on Mar 20, 2019, 06:09 pm
Isn't it great that Atmel has thought of that and provides us with the fixed 1.1V reference (https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/)?
Title: Re: Make Arduino Measure Its Own Voltage From Vin
Post by: zoomx on Mar 21, 2019, 11:59 am
Take care that is not always exactly 1.1V, you should measure it.
Title: Re: Make Arduino Measure Its Own Voltage From Vin
Post by: freaklabs on Mar 23, 2019, 02:51 am
Actually that's true. I forgot about the bandgap reference internally in the AVR chip. This can also be used. As mentioned, it's not as accurate as a precision reference, but if you're just measuring battery voltage, it can probably give you the voltage with around tens of mV precision.
Title: Re: Make Arduino Measure Its Own Voltage From Vin
Post by: wvmarle on Mar 23, 2019, 03:44 am
It's stable - you just have to measure the actual voltage once (for each individual chip), and then you can use that number.