After deliberating to find a better/more consistent method to read voltage and current, I decided to rewrite the calculations for the voltage and current using double type instead of integer type. Maybe I was losing accuracy/consistency there. So below is what I came up with:

```
double tempCalculate ;
double tempAnalogValue ;
//Save actual Vcc read when compared to on board 1.1V reference
ActualVoltage = (double)readVcc() / 1000;
CurrentTime = millis();
//Read battery voltage. Need to rescale this according to actual sensor used
tempAnalogValue = analogRead(VoltageSensor);
//calculate the voltage from the pin
tempCalculate = (tempAnalogValue / 1023) * ActualVoltage;
//calculate the voltage of the 12V source through the voltage divider
// and prepare to convert back to integer (*100)
tempCalculate = tempCalculate * 27.25 / 5 * 100;
BatteryVoltage = (int)tempCalculate;
//Read in Current. Need to rescale this according to actual sensor used
tempAnalogValue = analogRead(CurrentSensor);
//calculate the voltage from the pin
tempCalculate = (tempAnalogValue / 1023) * ActualVoltage;
//calculate amperage from 40mV/A with a 2.5V center
// and prepare to convert back to integer (*10)
tempCalculate = (tempCalculate - 2.5) / .04 * 10;
BatteryCurrent = (int)tempCalculate;
//Offset current and voltage value according to user definition
BatteryVoltage = BatteryVoltage + VoltageOffset;
BatteryCurrent = BatteryCurrent + AmpOffset;
```

After running this, it still appears that there is drift as the test goes on, so I don't seem to nail down the current and voltage as I thought I could.

Rework on Voltage measurements:

Maybe the voltage divider calculation needs to be more accurate in the scale. Possibly causing a scaled shift as the voltage goes through different values. Or the 1.1V reference is not as accurate as it needs to be.

Rework on Current measurements:

Maybe the robotshop current sensor is not as accurate as I had envisioned. Possibly look into tapping into the shunt ammeter and pipe that information over to the UNO. Or the 1.1V reference is not as accurate as it needs to be.

To shift to a different voltage reference instead of the internal 1.1V reference will just be a matter of adding a chip to the protoshield. This at least would remove the doubt of the 1.1V reference.

## Discussions

## Become a Hackaday.io Member

Create an account to leave a comment. Already have an account? Log In.