amp | watt hour meter


i've built voltage , current monitor using acs715 pololu. i'm calculating hours using millis, , total amp hours consumed. millis unsigned long, i'd see hours in operation in format 1.25 hours, not jumps 0 - 1 - 2 etc. photo's, schematics etc. posted @ http://tech.groups.yahoo.com/group/arduinohome/.

code: [select]
/* sketch describes how connect acs715 current sense carrier
(http://www.pololu.com/catalog/product/1186) arduino,
and read current flowing through sensor.



vcc on carrier board arduino +5v
gnd on carrier board arduino gnd
out on carrier board arduino a0

insert power lugs loads positive lead circuit,
arrow on carrier board points load, other lug connects
power supply positive

*/
int batmonpin = a4;    // input pin voltage divider
int batval = 0;       // variable a/d value
float pinvoltage = 0; // variable hold calculated voltage
float batteryvoltage = 0;
float ratio = 3.2;  // change match measured ration of circuit
int analoginpin = a0;  // analog input pin carrier board out connected to
int sensorvalue = 0;        // value read carrier board
int outputvalue = 0;        // output in milliamps
unsigned long time = 0;
int sample = 0;
float totalamps = 0.0;
float averageamps = 0.0;
unsigned long hours = 0;
float amphours = 0.0;

void setup() {
 // initialize serial communications @ 9600 bps:
 serial.begin(9600);
}

void loop() {
 
 // increment sample counter
 
 sample = ++sample;
 
 time = millis();
 
 
 
 // read analog in value:
 sensorvalue = analogread(analoginpin);            
 // convert milli amps
 outputvalue = (((long)sensorvalue * 5000 / 1024) - 500 ) * 1000 / 133;  
 
/* sensor outputs 100 @ rest.
analog read produces value of 0-1023, equating 0v 5v.
"((long)sensorvalue * 5000 / 1024)" voltage on sensor's output in millivolts.
there's 500mv offset subtract.
the unit produces 133mv per amp of current, so
divide 0.133 convert mv ma
         
*/

 
 batval = analogread(batmonpin);    // read voltage on divider
 pinvoltage = batval * 0.00488;      
/*  calculate voltage on a/d pin
a reading of 1 a/d = 0.0048mv
if multiply a/d reading 0.00488
we voltage on pin.   */  

 batteryvoltage = pinvoltage * ratio;    //  use ratio calculated voltage divider
                                         //  to calculate battery voltage
                                         
                                           // print results serial monitor:
 serial.print("voltage = " );                      
 serial.print(batteryvoltage);      
 serial.print("\t current (ma) = ");      
 serial.print(outputvalue);  
 serial.print("\t power (watts) = ");  
 float amps = outputvalue / 1000.0;
 float watts = amps * batteryvoltage;
 serial.print(watts);  
 
 
 totalamps = totalamps + amps;
 
 averageamps = totalamps / sample;
 
 hours = time/3600000;
 
 amphours = averageamps * hours;



 serial.print("\t time (hours) = ");
 serial.print(hours);
 
 serial.print("\t energy (ah) = ");
 serial.println(amphours);
 
 
 // wait 10 milliseconds before next loop
 // analog-to-digital converter settle
 // after last reading:
 delay(10);                    
}

quote
but i'd see hours in operation in format 1.25 hours, not jumps 0 - 1 - 2 etc.

it's code. free that. don't need our permission.


Arduino Forum > Using Arduino > Programming Questions > amp | watt hour meter


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial