//Capture full defintion data const int currentPin = 0; const int voltagePin = 1; float referenceVoltage = 5;//50 ohm resistor = float previousCurrent = 0; float minCurrentMeasureable = 0; unsigned long lastMicros =0; int Voltage = 0; float resistorOhms = 10; unsigned long minimumCurrentmilliseconds = 0; int preva = -9999999; int a; void setup() { // put your setup code here, to run once: Serial.begin(250000); analogReference(DEFAULT); referenceVoltage = 5; Voltage = getVoltage(voltagePin); analogReference(INTERNAL); referenceVoltage = 1.1; Serial.println("Internal 1.1V reference"); minCurrentMeasureable = currentFromVoltsAndOhms(divisionsToVoltage(1), resistorOhms); Serial.print("Minimum Current measureable: "); Serial.print(minCurrentMeasureable *1000); Serial.println("mA"); Serial.println("ms\tI(mA)\tmAh"); } void loop() { unsigned long start = micros(); float voltsOnResistor = getVoltage(voltagePin); float current = currentFromVoltsAndOhms(voltsOnResistor, resistorOhms); if(abs(current-previousCurrent) > (minCurrentMeasureable*4))//where the value has changed by more than 10 divisions. {//print it out. Serial.print(millis()); Serial.print("\t"); Serial.print(current*1000); Serial.print("\t"); minimumCurrentmilliseconds += current / minCurrentMeasureable * (float)(micros()-lastMicros)/1000; Serial.println((float)minimumCurrentmilliseconds * minCurrentMeasureable/60/60); previousCurrent= current; lastMicros = micros(); } delayMicroseconds(1000-(micros()-start)); } float currentFromVoltsAndOhms(float Volts, float Ohms) { return Volts/Ohms; } float getVoltage(int analogPin) { int aval = analogRead(analogPin); float voltage = divisionsToVoltage(aval); return voltage; } float divisionsToVoltage(int divisions) { return (float)divisions * (referenceVoltage/1024); }