Hi all,
I'm aiming to d-i-y a battery discharge alarm that will be 'matched' to 3 identical 12V Lead Acid Gel traction batteries, used with an electric outboard.
The quick overview is that it will monitor the battery terminal voltage and current and using the resultant of both, trigger an audible alarm that relates to 50% depth of discharge (or thereabouts).
At the moment I have it working on an Arduino Nano feeding a 2 x 16 LCD via I2C interface (to reduce the wiring).
By copying, pasting and tweaking stuff I've found online, I've just about got it reading and displaying the Volts, the current and calculating and displaying the Watts and have a field for Wh but not sure if I can implement Wh just using the Nanos internal timer?
I might not bother with displaying Wh but display the current low voltage threshold (which will vary, see later) or maybe display both alternately (as they are really just 'background' information).
Because of Peukerts Law, where it says the capacity of a (Lead acid) battery will very dependant on the load / current drawn, it is my thought to continuously calculate that based on a predetermined scale (hopefully supplied by the battery manufacturer) and the WiKi page on it gives us some basic rules and values to work from:
So, (Q1) given the right input values (instantaneous current and volts), the variables for that particular battery and the Peukert's Law formula, should I be able to do what I want?
I'm not particularly looking for lab precision here, just reasonably repeatable results that I can cross reverence against other / external meters to confirm it is all at least reasonably representative.
I'm still waiting for some of the bits (batteries and the Hall-effect current sensor) before I can do any real tests but as a starter, one of the things I'm struggling with is getting the Watts value to display properly?
e.g. The volts displays will be to 1 decimal place and typically always between say 11.0 and 13.8V ( just / always two integers), making it easy to display as the display control is only the position of the first character.
The Amps should be between 0.0 and 30.0 and I have been able to use an IF / ELSE to move the screen print position to adjust between 1.5 and
25.0 A. (1 or 2 integers).The Watts and Wh though will go between 0 and say 360 (W, for the motor) or 0 - 180 Wh for the battery, both being 3 integers. It's that bit I can't seem to get right so would like help with please?
Just to give you the examples, the first bit works (probably more by luck than judgment (ignore comment wraps):
// Read and display Current (col / row) readAmps = analogRead(ampsInput); delay(5); float amps = readAmps * (50.0 / 1023.0); //this maps the measured voltage from 0 to 50V (read as Amps) lcd.setCursor(0,1); // first col, second row lcd.print(" "); // clear the previous value as it could have a different number on integers if (amps < 10) { lcd.setCursor(1,1); // to cope with 0.0 to 9.9, space display out by one } else { lcd.setCursor(0,1); // to cope with 10.0 to 99.9 } lcd.print(amps,1);
So far, so good?
However, I can't seem to get this one right and I think it's to do with the IF, ELSE IF, ELSE rules. Changing the second else if to just else (as I believe it should be) it then won't compile. ;-(
// Calculate and display Watts lcd.setCursor(8,0); lcd.print(" "); float watts = (volts * amps); if (watts < 10) { lcd.setCursor(10,0); lcd.print(watts,1); // displays calculated watts to one decimal place } else if (watts >= 10) { lcd.setCursor(9,0); lcd.print(watts,1); } else if (watts >= 100) { lcd.setCursor(8,0); lcd.print(watts,1); }
Anything over 100 seems to be 1 character too many to the right so I think I have the logic wrong somewhere. ;-(
The 16x2 display should look like this:
12.5 V 187.5 W 15.0 A WhWhat I'm getting is this:
12.5 V 187.5W 15.0 A WhAt the moment all the analogue inputs are just open / floating so it's just displaying random noise but that is good enough to test the display. Shorting either input to ground correctly displays 0.0 for volts and amps (and watts etc) and to 5V displays 15V, 50A and 750W. ;-)
So, (Q2) could someone familiar with Arduino coding help me on this and any other further hiccups I get please?
Cheers, T i m