I've built a voltage and current monitor using a ACS715 from Pololu. I'm calculating hours using millis, and total amp hours consumed. millis is a unsigned long, but I'd like to see hours in operation in a format like 1.25 hours, not jumps from 0 - 1 - 2 etc. Photo's, schematics etc. posted at http://tech.groups.yahoo.com/group/arduinohome/.

/* sensor outputs about 100 at rest. Analog read produces a value of 0-1023, equating to 0v to 5v."((long)sensorValue * 5000 / 1024)" is the voltage on the sensor's output in millivolts.There's a 500mv offset to subtract. The unit produces 133mv per amp of current, sodivide by 0.133 to convert mv to ma

*/

batVal = analogRead(batMonPin); // read the voltage on the divider pinVoltage = batVal * 0.00488; /* Calculate the voltage on the A/D pinA reading of 1 for the A/D = 0.0048mVif we multiply the A/D reading by 0.00488 then we get the voltage on the pin. */

batteryVoltage = pinVoltage * ratio; // Use the ratio calculated for the voltage divider // to calculate the battery voltage

You have hour as an integer, so storing 1.25 in that is not going to work. You want some resolution on time that is less than 1 hour. You need to define what that resolution is. If it is 1/4 hour, then you need to keep track of minutes, not hours. When you need to know how much time has elapsed, you divide minutes by 60 to get hours. You then subtract 60 times the number of hours to get the remainder. Multiply that value by 4 to get quarter hours.

If the time that you have measured is 78 minutes, that's 1 hour and 18 minutes, or 1 hour, 1 quarter hour and 3 minutes. Ignore the minutes. You can decide to round or truncate as you see fit. You might want 85 minutes to be 1 hour and 1 quarter hour or 1 hour and 2 quarter hours.

Oops, that was not being less helpful. I'll try harder in the future.

Quote

even a suggestion on some other improvement would have been more appropriate.

You asked a specific question. "Can I do this?" I answered that question. You did not ask how to do it, or for a review of the code, so I didn't answer those unasked questions.

Start by converting the time into minutes. Divide by 60 to get the hours.Modulus divide by 60 to get the minutes.The total time (as a float) would be hours plus (type casted to float) minutes divided by 60.

I'd calculate the charge more directly - at each sample point multiply the current by the time since the last sample, this gives an estimate of the charge that has flowed in this sample period. Add that to the totalCharge variable (you wrongly call this totalAmps).

The ampere-hours value is totalCharge/3600.0 since 1Ah = 3600C.

[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

/* sensor outputs about 100 at rest. Analog read produces a value of 0-1023, equating to 0v to 5v."((long)sensorValue * 5000 / 1024)" is the voltage on the sensor's output in millivolts.There's a 500mv offset to subtract. The unit produces 133mv per amp of current, sodivide by 0.133 to convert mv to ma

*/

batVal = analogRead(batMonPin); // read the voltage on the divider pinVoltage = batVal * 0.00488; // Calculate the voltage on the A/D pin // A reading of 1 for the A/D = 0.0048mV // if we multiply the A/D reading by 0.00488 then // we get the voltage on the pin.

batteryVoltage = pinVoltage * ratio; // Use the ratio calculated for the voltage divider // to calculate the battery voltage

/* sensor outputs about 100 at rest. Analog read produces a value of 0-1023, equating to 0v to 5v."((long)sensorValue * 5000 / 1024)" is the voltage on the sensor's output in millivolts.There's a 500mv offset to subtract. The unit produces 133mv per amp of current, sodivide by 0.133 to convert mv to ma

*/

batVal = analogRead(batMonPin); // read the voltage on the divider pinVoltage = batVal * 0.00488; // Calculate the voltage on the A/D pin // A reading of 1 for the A/D = 0.0048mV // if we multiply the A/D reading by 0.00488 then // we get the voltage on the pin.

batteryVoltage = pinVoltage * ratio; // Use the ratio calculated for the voltage divider // to calculate the battery voltage

I just received the ACS714 bidirectional hall effect sensor from Pololu. I'll be modifying the project to watch ah in and ah out, with a peukert calculation, for estimated capacity remaining.

I'm adding a low voltage disconnect circuit with a hybrid relay (eliminates MOSFET heating and relay arcing) to protect the battery from excessive discharge. When sketch starts, the MOSFET is enabled, then the relay. Upon voltage drop below predermined value, the relay drops, then the MOSFET. Use a SSR for an AC Load. Full instructable at http://www.instructables.com/id/DIY-Amp-Hour-Meter-Arduino/.