# How do I measure current with a microcontroller

OK, having given myself a crash course in op amps, I think I've got it figured out.

I am looking to build an in circuit battery monitor, and I wish to measure the current being drawn from each individual cell in a series-parallel battery pack.

I think the circuit below will do all I want it to do, and I now think I've got the resistor values right to give me the correct gain. And I think I've got the right bias voltage to force the output positive over the desired range of -2.5 to +7.5 Amps.

I have been informed that I was nearly correct. 4 diodes in series gives me a handy two point FOUR volt reference, and as much current as I care to waste in the power shunt resistor, to supply the microcontroller, as well as provide an offset bias for the voltage sense module. A hefty cap holds enough charge to drive the microcontroller during its wake time as well as the IR-llLED derived opto-Xceiver, to allow me to maximise the value of the power shunt resistor. Hopefully 1mA continuous should be enough.

What I need is for AN1-7 to read across the range of -2.5 to +7.5 (Amperes through shunts/fuses @ 10 mA/div) and An0 to read actual voltage across the range of 2.8 V to 4.4 V. @ <2 mV/div.

Unless I am completely mistaken this (slightly modified, and broken into its functional blocks) circuit should let me monitor the precise health and charge status of every individual cell in a battery pack, identifying those not delivering their fair share of the load, and/or which self-discharge, dragging down cells connected in parallel.

By keeping a record of each cell's performance over multiple charge and discharge cycles, the right software would be able to maintain a charge map of the battery and recommend cell swaps to keep the battery perfectly in balance, whenever cells drift out of spec, or when a dud cell is replaced.

Big question, do I have it right, or have I made some fundamentally stupid error?

simulate this circuit – Schematic created using CircuitLab

• This monitoring of the individual currents of (groups of) cells seems overly complex to me. Why would you not just connect all cells or paralleled cells in series and only measure the voltages across those cells. That is much easier and will also allow you to monitor the cell's health. As long as the cells are identical and balanced and they are loaded by the same current, that should do the trick. It's what is used in many devices. If you need to tap-off certain voltages from within the pack I would not do so but use a DCDC converter to make that voltage so that the power comes from all cells May 21 '16 at 9:58
• The idea is to be able to see a single cell on its way out, May 21 '16 at 11:01
• use Analog multiplexers for reducing number of pins needed May 21 '16 at 11:10
• @FakeMoustache The "tapping" is simply the nature of the beast. It allows absolute measurement to be taken from each cell rather than relative to battery ground. Better granularity, and one set of component values fits all. May 21 '16 at 11:30
• @ElectronS but significantly adds to the complexity for just one more pin. If necessary, voltage sense can be farmed off to a separate board with only one analogue multiplexer at the expense of slightly more complex code in the master controller. May 21 '16 at 11:56

• Aware of that, but due to the nature of this beast, I can't use a common supply. I should have mentioned, component cost is a very large concern. If I can manage good enough with 50 cents worth of decent precision components, rather than $2, and the same saving at$1 to $4 per sense circuit, calibrate and compensate for errors in the software of the ludicrously overpowered for the task 2$ CPU why the hell not? $15 beats the hell out of$40. I'll be needing at least 10 of these boards, so my prices will be even better. Perhaps as little as \$10 per board. A mosfet and a bit of jiggery (cont) May 24 '16 at 16:27