So I've got a AttoPilot 180A sensor (this one) - SparkFun Page
After some messing around I was able to come up with this code...
int VRaw;
float VFinal;
const int buttonPin = 2;
int buttonState = 0;
void setup() {
Serial.begin(9600);
previousReading = 0.00;
totalCount = 0;
pinMode(buttonPin, INPUT_PULLUP);
}
void getVoltage() {
totalCount = totalCount + 1;
float currentData;
currentData = 50.00;
for (int counter = 0; counter <= 200; counter++) {
VRaw = analogRead(A0);
VFinal = VRaw/14.38;
if (VFinal <= currentData) {
currentData = VFinal;
}
}
for (int counter = 0; counter <= 200; counter++) {
VRaw = analogRead(A0);
VFinal = VRaw/14.38;
if (VFinal > currentData) {
currentData = VFinal;
}
}
for (int counter = 0; counter <= 200; counter++) {
VRaw = analogRead(A0);
VFinal = VRaw/14.38;
if (VFinal > currentData) {
currentData = VFinal;
}
}
Serial.print("Volts = ");
Serial.print(currentData);
Serial.println();
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
getVoltage();
}
delay(100);
}
Now this works fine and is accurate (Tested against a Fluke 78 Multimeter) when I am reading a 12V Cordless drill battery. I get the exact same readings.
But if I put the leads on a regular old 9V battery my arduino kicks out different readings than the Fluke does.
12V Readings:
Arduino: 12.87v
Fluke: 12.87v
9V Readings:
Arduino: 9.46v
Fluke: 9.56v
Any ideas why this is?