Portable Battery State Of Charge Monitoring

Hello,

I am working on a project which uses a constant current sink to draw current from a battery until it reaches a certain voltage, both the amount of current to be drawn and threshold voltage can be input by user via txt file (duty.txt) in memory card, and the value of current and voltage will be logged in memory card.

I have tested the circuit externally (with out arduino) and it works fine, the current can be calculated from the voltage across sense resistor depending on the duty cycle applied to the filter.

i would love to get some suggestions or advice

I need to plot the state of charge or remaining capacity of battery as it discharges using the data logged, and log the data until it reaches cutoff voltage.

The Code so far is as following.

REMOVED

Just connect arduino ground to other ground, put voltage 2 resistor divider and bring its output to analog input of arduino. For current sensing, connect upper side of 1 OHm resistor to analog input via 10k resistor (safety). Where PWM is coming from? If it from same arduino, than probably, you don't have to measure current, as it will be proportional to PWM duty cycle.

Magician: Just connect arduino ground to other ground, put voltage 2 resistor divider and bring its output to analog input of arduino. For current sensing, connect upper side of 1 OHm resistor to analog input via 10k resistor (safety). Where PWM is coming from? If it from same arduino, than probably, you don't have to measure current, as it will be proportional to PWM duty cycle.

Thnks for the feedback, Yes the PWM is coming from pin 11 of Arduino, but i do need to measure the current to log the variation in current when battery is discharged, or to find the rated current that can be drawn from the battery! e.g if i apply 100% Duty cycle to draw 5Amps and the battery is capable of providing only 1.5Amps

If battery "sink" under load (high current) you will know about it from voltage sensor. How you powered up OPA? You circuit would have non-linear behavior when voltage drops below MOSFET's Vgs + OPA output saturation (LM324 isn't rail-to-rail).

Its powered by 5volt supply and negative pin grounded !

MOSFET is rated :

12 A, 60 V. RDS(ON) = 0.18 ? @ VGS = 5 V

at 5V, I'd suggest to power OPA from 12V source, otherwise current settings would only slightly affect whatever current will flow based on a temperature of surrounding air.

Will 9V Battery work fine to power OPA ?

It May works, though reliable current range up to 2.5 A or so ( 9 - 5 (mosfet) - 1.5(opa)). Other option is decrease current sensing R to 0.1 OHm, setting voltage divider on PWM 1:10 as well. It would relax voltage demands from OPA output.

Thnx alot