coulomb counting

hi all

i am trying to det up my arduino to give me an acurate-ish indication as the the SOC of the batteries in my 4wd. i have the shunts that i need to measure the current, but no idea on how to get it to coulomb count. i would like to get a readout of AH/WH in and out of the battery from the alternator and the solar when camping. etc... aswell as what my accessories draw when not charging fridge lights etc...

is there a sensor i can use? everything i have found from scouring the net is to do with low power LiPo batteries.

my car batteries are a 750cca crancker and a 120AH deep cycle.

cheers

Jason

If you have a shunt that allows you to make accurate measurements of the battery current, then the definition of the ampere (one coulomb per second) allows you to keep track of coulombs.

Total coulombs = sum of (amperes * time in seconds) where the time is some suitably short period.

How accurate do you want this to be?

The voltage of a lead acid battery, when the battery has been at rest for a while, is a pretty good indicator of its state of charge, too.

The "sensor you can use" is the analog input of your arduino.

To measure the battery voltage, you can use some large-value resistors to divide the 12 volts by 3 or 4 to get a value you can read with the analog input of the arduino.

To measure the current, there are two methods. You can put the current through a known resistor, and measure the voltage drop that the current causes in the resistor. Or you can buy a gadget which uses the "hall effect" to output a voltage which is proportional to the current. The second method is more foolproof, works in both directions, and you can get the gadget for about $2 ( search "30A current sensor" ) on ebay. You would want to put this in the wiring somewhere where the actual vehicle starting current doesn't go through it.

ok,well i have 2 of these

http://www.ebay.com.au/itm/111040360152?var=410166550832&ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

so my plan is to run

solar---------->small 50A shunt---
|
|
|
|
alternator & accessories----------> Larger 200 A shunt------------------> Battery

my plan is to count the power in an out of the battery, and i just want to know how my solar is performing, so i will seperate that shunt out, biut would like to log its data.

so this will give me an acurate indication of amps into the battery and out when camping etc....

i hope that all makes sense.

also, on the shunts, there is the 3 pin header for vcc,gnd and data out, but there is also another small joint on the other side of the pcb that has sense on it. what would that be for?

and as im assuming that this would use an analog pin, am i correct in guessing that i would also not need a library? because it will just output a voltage reading and i just need to code the ratio into the firmware? correct?

cheers

Jason

I hadn't seen those current sensors before and they look pretty useful.

All you need is an analog input to read them. If your Arduino is 5V and you use 5V as the ADC reference voltage, then the analog output will be 0-1023, corresponding to input voltages of 0-5 V. The 50 amp sensor has a sensitivity of 60 mV/amp (or 3.0 volts output for 50.0 amps), so the process to convert the ADC reading to amps can be outlined as follows.

// convert 50 amp sensor reading into amps
float volts = ((float) adcvalue)*5.0/1023.;
float amps = volts/0.060;

For the 200 amp sensor, the second scale factor would be 0.0266 for 26.6 mV/amp sensitivity.

I would run tests and double check the sensor calibration against a conventional current meter to make sure that the sensor readings and conversion factors all make sense before trusting the setup!

Hi, I think those current pickups are the usual allegro chips but tarted up a bit, certainly looks like a lot more high current track width than on other pick ups I've seen.

Tom.... :slight_smile:

Good eye, Tom:

I couldn't read the markings on the IC without that hint. That must be the ACS758 sensor. The PCB looks nicely made.
Here is the data sheet http://www.allegromicro.com/~/media/Files/Datasheets/ACS758-Datasheet.ashx
Looking at the data sheet, I realized I had misread the ebay advert. The sensitivity of the unidirectional 200 amp sensor is 20 mV/amp, not 26.6

@jason: I hope you got the bidirectional variety rather than the unidirectional. I was assuming unidirectional when I suggested a scaling approach. If bidirectional (which you need for the battery to take into account charge/discharge), the output of the ADC will correspond to about 1/2 of the sensor supply voltage for 0 amps and then increase or decrease from there as the current is positive or negative. Also the bidirectional and unidirectional current sensors have different sensitivities.

So, something like:

// convert 50 amp bidirectional sensor reading into amps
float volts = ((float) adcvalue)*5.0/1023.;
float amps = (volts-2.5)/0.040;  //will probably have to adjust the 2.5 offset value for 0 amps

The problem with using a shunt resistor, is that setting it up to tolerate a large starting current ( for a car or boat engine ), also also being able to detect small currents, like when you leave the radio on when the motor is off, is quite difficult.

hi all

well, i have finaly received my arduino nano, and i have gotten my temp and press. sensor to work aswell as voltage through a voltage divider (5K pot), and now im up to the shunt part. but im lost. i have powered it off the 5V ref pin (measures 4.55V - powered by usb), and i have a light that draws ~6A for testing. so, by my theory, shouldnt i see ~0.24V on the output pin of the shunt? i have tested it with my meter, and i get 2.33v with the unplugged, and 2.42 with it on.

i havent even gotten to the coding part yet.

im lost.

please help.

Cheers

Jason

So if 6 Amps is flowing through your current shunt or sensor, and the sensitivity is supposedly 20 mV/Amp, then you expect an output voltage of about 120 mV ( 0.12 volts ). Which is approximately what you are seeing.

What you perhaps didn't realise, is that when there is no current, the voltage output is supposed to be half of the supply voltage . So 2.5 V for a 5 volt supply. If the current is +6 amps, you will get 2.62 volts on your analog input. If the current is -6 amps, you will get 2.38 volts on your analog input. In either case, a six amp current will change the voltage by 6 x 20 mV = 0.12 volts in either the positive or negative direction from the no-current voltage which is 2.5 V.

Hmmm. Ok i will look tomorrow. But the specs are 40mv/a @ 5.0v, and 26mv/a @ 3.3v.

And yes, rereading the description, it stated zerocurrent output is vcc/2.

But still, with 4.55v giving 2.3v with zero load, at 6a shouldnt i get around +/- 240ma dwpending on direction? So 2.54 / 2.06v?

Cheers

Jason

240 mV at 6 amps, not ma. Otherwise that looks about right.

jremington:
Good eye, Tom:

I couldn't read the markings on the IC without that hint. That must be the ACS758 sensor. The PCB looks nicely made.
Here is the data sheet http://www.allegromicro.com/~/media/Files/Datasheets/ACS758-Datasheet.ashx
Looking at the data sheet, I realized I had misread the ebay advert. The sensitivity of the unidirectional 200 amp sensor is 20 mV/amp, not 26.6

@jason: I hope you got the bidirectional variety rather than the unidirectional. I was assuming unidirectional when I suggested a scaling approach. If bidirectional (which you need for the battery to take into account charge/discharge), the output of the ADC will correspond to about 1/2 of the sensor supply voltage for 0 amps and then increase or decrease from there as the current is positive or negative. Also the bidirectional and unidirectional current sensors have different sensitivities.

So, something like:

// convert 50 amp bidirectional sensor reading into amps

float volts = ((float) adcvalue)*5.0/1023.;
float amps = (volts-2.5)/0.040;  //will probably have to adjust the 2.5 offset value for 0 amps

hm ok, well i have tried your code, and modified it slightly to suit me, but i just cans seem to get it to read correctly.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {
   // convert 50 amp bidirectional sensor reading into amps
  int sensorValue = analogRead (A1);
  float voltage = ((float) sensorValue)*5.0/1023;
  float amps = (voltage-2.558)/0.040;  //will probably have to adjust the 2.5 offset value for 0 amps
  Serial.print (amps);
  Serial.println ("A");

  delay (1000);

}

am i correct that the 2.5 value is just the assumed vcc/2 of the vref pin? as it should be 5v, but mine is only 4.91 so 4.91/2=2.455V

i have tried to modify the 2.5 value, and to get my sensor as close to "zero" as possible, (i could only get it as close as -0.04A) i ended
up with 2.558. when i tried the 2.455 i ended up with 2.53A with no load on the serial output.

but, my output with my 6A load is 2.4A (this is back to the 2.558 value in the code), which is the MV/A offset for the 6A load. i just cant get it to read 6A. i have tried to move the 0.040 around, and i get readings that are wrong.

im sure that the code is correct, just i think that the math is wrong somewhere. i just cant see where. as in my mind, the sequence of flow of the math is correct, but even with a calculator, i dont get a reading thats even close to whats been reported.

or is there something super simple that i am overlooking?

cheers

Jason

Hi, Jason, can I suggest you get the sketch to serial print the sensor value as well as your calculated amps.
Can you give us values for noload, and a couple of other currents thought the sensor and their sensor values.
I think the problem is in the 0.04 value.

Tom.... 8)

TomGeorge:
Hi, Jason, can I suggest you get the sketch to serial print the sensor value as well as your calculated amps.
Can you give us values for noload, and a couple of other currents thought the sensor and their sensor values.
I think the problem is in the 0.04 value.

Tom.... 8)

sure mate.

the serial output is prety boring.

-0.04A
-0.04A
-0.04A
-0.04A
-0.04A
-0.04A
-0.04A
-0.04A
2.40A
2.40A
2.40A
2.40A
2.40A
2.40A
2.40A
2.40A
-0.04A
-0.04A
-0.04A
-0.04A
-0.04A
-0.04A
2.40A
2.40A
2.40A
2.40A
2.40A
-0.04A
-0.04A
-0.04A
-0.04A
-0.04A
-0.04A

obviously the 2.4 is with the light connected, and the 0.04 is disconected.

i also think that the error is in the 0.040 value. but the sensors accuracy @5V is 40mV.

cheers

Jason

Hi, Jason, i want a print of the sensorValue for no load and for your load which I think is 6Amps.
Have you measured the current to make sure it is 6Amp.
I don't want your calculated value.

Tom..... 8)

hmmmm so remove the equation from the code and re-run it, is that what you are after? and yes, the load is 6A, i have measured it with my meter.

// convert 50 amp bidirectional sensor reading into amps
  int sensorValue = analogRead (A1);
  float voltage = ((float) sensorValue)*5.0/1023;
  float amps = (voltage-2.558)/0.040;  //will probably have to adjust the 2.5 offset value for 0 amps
  Serial.print (voltage);
  Serial.println ("");

  delay (1000);

returns with

2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.65
2.65
2.65
2.65
2.65
2.66
2.65
2.65
2.65
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56
2.56

i think thats what your after.

Hi, sorry I need

Serial.print (sensorValue);

You don't need to remove anything just change the Serial.print.
for noload and your 6A load.
What I am trying to do is find out what the RAW data from the AtoD is producing for noload and 6A load, that way we can workout an equation that will work.
How accurate is the 6A, have you measured it with a meter or is that what is written on the load?
Tom...... 8)

ah. i get it.

523A
523A
523A
523A
523A
523A
523A
523A
523A
523A
523A
523A
523A
546A
543A
543A
543A
543A
543A
543A
543A
543A
543A
543A
543A
543A
523A
523A
523A
523A
523A
523A
523A

ignore the "A" after the numbers. i didnt remove that from the code.

voltages at the A1 pin are 2.52 and 2.62 respectivley. yes, i have re-checked the light, and it draws 6A. that is confirmed

Hi, jason.
Try this as your conversion equation.

float amps = ((float) sensorVoltage*0.3)-156.9;

This a straight conversion equation, the output of the sensor should be linear, so follow y=mx+c.
Using your figures this equation should give you what you need.

If you wish to tweek the equation, the -156.9 adusts the zero load offset.
the 0.3 is the gain of the system for setting the span of the reading.
You will have a resolution of 0.3A.

Try it and see...Tom.... 8) (gunna be 35DegC here today..)