My code works for this: spenningLiPo = (float)(analogRead(LiPoPin)) / 4095 * 2 * 3.30 * 1.10;
I will try to ad the f's but my question is that I want to improve accuracy and my formula above is not good enough.
So question is to get some help/input to make a more accurate reading/calculation, I tried the code from G6EJD, but it gives not correct reading, and I cant find my "mistake".
It's 4AM, so my earlier syntax might be off, but all those constants need to be written in a way that the compiler treats them as floating point. If not, the data will be off since 1.10 is quite different from 1.
Yes.
Since your voltage divider cuts the voltage in half, then just multiply batLipo by 2.0.
You may want to take several readings and then take the average value
The pin of a 3.3volt processor can't take more than 3.3volt, so you do need a voltage divider. 1k:1k is a drain on the battery though. I would use something like 220k:100k, with a 100n cap from pin to ground.
Leo..
@jim-p
110k:330k gets you more A/D values, but I picked a 100k:220k ratio to keep battery voltage more in the linear region of the A/D. Not that it makes much difference.
Leo..
Actually @Wawa is right about keeping it in the linear region. When the battery voltage is at 3.7V, you want the input to the ADC to be less than 2450mV
So now I suggest making R1 = 162K and R2 = 301K. The ratio is now 0.65
This will give the best accuracy when you are trying to determine if the battery is near the end of it's capacity
My system is to run 365 days a year (bee hive monitoring), and I use superCap (5V5 / 10F) due to cold winter, and LiPo as backup. Also uses solar to charge.
(i have never used a superC so Im a bit on deep water).
To control charging I read all voltages and tempereatur to determine charging priority.
One cycle of system is around 2 sec, and then go to sleep for a time X (1/2 h/ 2h, 18/h), max power in one cycle is 200mA (lora).
So a combo of voltages and temp I will decide witch bat to a) use b) charge.
This logic is not fished, and I find it challenging. I expect I will send some question's on this forum when I have my new HW ( version with super cap is only schematic by now) and struggle to find best optimization.