How to make your own coulomb counter (Amp*hours [Ahr] meter, or Watts*hours [Whr] energy meter) with an Arduino
Quick summary:
Jump straight down to the "Full coulomb counter example in code" section if you just want the final answer.
Details
A. Making the coulomb counter as good as possible
ExtraB. Extra: when is trapezoidal integration most beneficial?
You might call the following list my "5 hypotheses about the benefits of trapezoidal integration".
- The time sampling rate is super low.
- The rate of change of readings (ie: their derivative, or slope) is super high.
- The readings consistently have a rising slope (rectangular integration _under_estimates the area in this case) OR a consistently falling slope (rectangular integration _over_estimates in this case).
- When you care about real-time readings in this instant, not just overall trends or averages. This is because trapezoidal integration instantly removes overestimation and underestimation error which can accumulate over short periods but then "de-accumulates", or is negated, over long periods, when the opposite slope occurs in the data.
- [This may apply only when there is jitter in the sample rate--see @Edgar Bonet's comment here] When the readings consistently rise at a different rate than thethey fall, as this results in asymmetric accumulation of error. This means that the rectangular integration error accumulated by the values rising distance
delta_y
will NOT be fully negated by error in the opposite direction when the values fall distancedelta_y
. Therefore, even over long periods, rather than seeing the error negated, it will accumulate more and more over time. [Note: I'd need to analytically/numerically play with this hypothesis for a while to prove it conclusively to myself, but I'm pretty sure it is correct].