Measuring the amount of charge in batteries with Arduino

li-on/lithium batteries charge stays roughly the same until the battery is nearly completed.

While true for Nimh and nicads, I disagree on this about Li cells. A fully charged Li cell will have a 4.2vdc voltage and pretty linearly decrease to around 3.0vdc for fully discharged. So in the case of Li cells, terminal voltage is a decent relative indicator of state of charge. To have a truly accurate state of charge measurement one needs to measure current being delivered to the load and integrate the value over time until it matches MAH rating of the cell.

Lefty