Food Living Outside Play Technology Workshop DIY Amp Hour Meter - Arduino by sspence on May 9, 2012 Table of Contents DIY Amp Hour Meter - Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Intro: DIY Amp Hour Meter - Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 1: Voltage Divider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 2: Current Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Step 3: Math Alert! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Step 4: Serial Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Step 5: LCD Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Step 6: Followup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 http://www.instructables.com/id/DIY-Amp-Hour-Meter-Arduino/ Author:sspence author's website Professionally, I'm an IT Engineer (Executive Level) and Electronics Tech. Philosophically, I'm a Green Conservative, and probably would have been a hippie in the 60's if I had been old enough. I live off grid, with Solar (PV), Wind, and veggie oil fueled diesel generator power. Intro: DIY Amp Hour Meter - Arduino For my off-grid Ham Radio and Solar projects, I needed a way to measure volts, amps, watts, amp hours and watt hours. There's a couple of commercial products that can do this, but not with the flexibility I wanted. I designed a Arduino micro-controller based solution that is very extensible. Right now it monitors the above values of attached gear, and I'm thinking about adding web monitoring and a sd card for data collection. Well, let's get started. Step 1: Voltage Divider The Arduino can accept up to 5v on a analog input. Our battery voltage can range as high as 16vdc in certain charge cycles, so we designed a voltage divider that would provide 5v at 16v battery voltage, and less at various lower voltages. See http://en.wikipedia.org/wiki/Voltage_divider to determine the right values for your application. The code to read that value is as follows: 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 More details at http://arduinotronics.blogspot.com/2012/04/voltage-monitor.html http://www.instructables.com/id/DIY-Amp-Hour-Meter-Arduino/ Step 2: Current Monitoring The next step is to track the current being consumed by a load, or produced by a source. We are using a ACS715 Hall Effect sensor to track the current being passed. // read the analog in value: sensorValue = analogRead(analogInPin); // convert to milli amps outputValue = (((long)sensorValue * 5000 / 1024) - 500 ) * 1000 / 133; amps = (float) outputValue / 1000; More details at http://arduinotronics.blogspot.com/2012/04/monitoring-power-consumption-with.html Step 3: Math Alert! To calculate watt (volts * amps), amp hours (amps * hours), and watt hours (watts * hours) requires tracking the time component, and performing a bit of math: float watts = amps * batteryVoltage; sample = sample + 1; msec = millis(); time = (float) msec / 1000.0; totalCharge = totalCharge + amps; averageAmps = totalCharge / sample; ampSeconds = averageAmps*time; ampHours = ampSeconds/3600; wattHours = batteryVoltage * ampHours; Step 4: Serial Output We can now output the results of the calculations to the serial port using the following code: Serial.print("Volts = " ); Serial.print(batteryVoltage); Serial.print("\t Current (amps) = "); Serial.print(amps); Serial.print("\t Power (Watts) = "); Serial.print(watts); Serial.print("\t Time (hours) = "); Serial.print(time/3600); Serial.print("\t Amp Hours (ah) = "); Serial.print(ampHours); Serial.print("\t Watt Hours (wh) = "); Serial.println(wattHours); http://www.instructables.com/id/DIY-Amp-Hour-Meter-Arduino/ Step 5: LCD Display Keeping a computer connected all the time is inconvenient, so I added a lcd display to the project. lcd.setCursor(0,0); lcd.print(batteryVoltage); lcd.print(" V "); lcd.print(amps); lcd.print(" A "); lcd.setCursor(0,1); lcd.print(watts); lcd.print(" W "); lcd.print(time/3600); lcd.print(" H "); lcd.setCursor(0,2); lcd.print(ampHours); lcd.print(" Ah "); lcd.print(wattHours); lcd.print(" Wh "); Step 6: Followup All the code, schematics, and photo's along with discussion is available at http://tech.groups.yahoo.com/group/arduinohome/files/volt%20amp%20watt%20hour%20meter/ Related Instructables Solar powered Reverse Trike by farrukh khan Laptop Battery Analyzer /Recycler by splats 14 amp hour / 140 watt hour lithium ion battery by Noblenutria The mexican... Watt ? ? Calculate Watts on motors with Amp and Volt readings. by Rafael61 http://www.instructables.com/id/DIY-Amp-Hour-Meter-Arduino/ L.O.G.Kill A Watt by msuzuki777 Arduino EV J1772 Charging Station by flyguy161