I'm trying to read the voltage of the supplying lipo. I don't have great knowledge about electrics and this stuff... so be kind, if this is just stupid
I'm reading constant +5v (1024) on pin A0 ...
So how do I do this properly?
My issue is, i have no clue about, what you just said to me . Do you have a reference example, or could draw what you meant please? I would be sooo thankful
There is an optional 1.1V reference (so 1.1V or higher reads 1023). It's not "perfect" (I think there's a +/-0.1V tolerance) but it's super stable so you can adjust your software to calibrate-out any errors if you want more accuracy.
A voltage divider is simply 2 resistors that you can use to knock-down the 5V to around 1V, allowing you to measure the 5V with the 1.1V reference. Typically the resistors should add-up to about 10K. Lower resistance increases the current (wasting battery life) and higher values are more prone to noise pick-up.
Of course you'll have to modify your formula, taking the 1.1V reference and the voltage divider into account.
Or there is a way to do it entirely in software - There is a way to measure the 1.1V internal reference using Vcc as the reference. If Vcc (5V) is off, the reference measurement will be off and that error/difference can be used to calculate the actual Vcc. (Again you may have to calibrate in case the 1.1V reference isn't perfect.)
Thank you for your support and the great explanation!!
While I tested a voltage divider I recognized that on the Lipo charger the battery in/out and the normal in/out pins are just connected -
So the Arduino voltage was always the same as the battery voltage. Therefore, it always got 1023 while comparing...
You are reading 1023 because you are comparing the voltage on A0 with Vcc (the DEFAULT reference).
You cant directly use the INTERNAL reference because Vcc > Vref (1.1V)
If you remove the battery connection to A0
(its not safe to connect a battery directly to an input pin)
you can measure Vcc indirectly using the "secret voltmeter" - you will find the code here
However I should point out
The voltage of a single LiPo cell ... varies from about 4.2 V (fully charged) to about 2.7–3.0 V (fully discharged), where the nominal voltage is 3.6 or 3.7 volts
and is not ideally suited to powering an arduino directly.