system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: How do electronics with battery indicators "know" how much battery they have left?

My phone has a battery icon that shows a visual representation and a percentage of battery remaining. How does it tell how full the battery is?
gpt
Batteries voltage changes slightly as they discharge. A simple way is just to measure this voltage (like a battery tester). Smarter batteries, like laptop batteries, have micro-controllers built into them that allow the device to communicate with the battery. Charge is measured in Coulombs and battery capacity can be measured by counting Coulombs. Amps, are just the number of Coulombs per second flowing, so smarter batteries can measure the current flowing out of a device and integrate this to get the amount of charge flowing into or out of a battery. Current is usually measured with a small resistor and a voltage meter using Ohm's law (Voltage = Current \* resistance)

Smart batteries will also report battery degradation over time etc, so a 100% charge on an old battery might only be 80% of the original capacity.

&#x200B;

Better ELI5:

&#x200B;

A Coulomb (charge) counter would act like a water meter that can measure water flowing into or out of a storage tank. By keeping track of the net water in the tank, and you know the total size of the tank, you know the percentage.

&#x200B;

A more simple method is to measure voltage. This would be like capping the spigot on a tank with a PSI gauge and reading how much pressure was at the bottom of the tank and therefore you can calculate the water depth and estimate the remaining capacity.

&#x200B;