Stalker 2.3 & Battery voltage on A7.

I’m trying to read the battery voltage on pin A7, but the highest the value ever goes when the charger hardware reports the battery is fully charged is 212 of 1023. If I hook A0 to v3.3, the analog reading 1023 of a possible 1023.

Is there some scaling going on here with a resistor that I should be taking into account, or am I doing this wrong entirely?

The code I am using (based on the ReadAnalogVoltage demo):

[code]void loop() {
int sensorValue = analogRead(A0);
float voltage = sensorValue * (3.3 / 1023.0);
float percent = sensorValue * (100.0 / 1023.0);
Serial.print("A0 “);
Serial.print(sensorValue);
Serial.print(”/1023 “);
Serial.print(percent);
Serial.print(”% ");
Serial.print(voltage);
Serial.print("v ");

sensorValue = analogRead(A7);
voltage = sensorValue * (3.3 / 1023.0);
percent = sensorValue * (100.0 / 1023.0);
Serial.print(“A7 “);
Serial.print(sensorValue);
Serial.print(”/1023 “);
Serial.print(percent);
Serial.print(”% “);
Serial.print(voltage);
Serial.println(“v”);
Serial.println(””);

delay(10000);
}[/code]

If you take a look at the schematic there a voltage divider with two resistors: 10M and 2M, and in the middle is connected the A0 pin. If you’re using default analog reference, it means that your 212 measure corresponds to: (3,3/1023)*212 *(12/2) = 4.1V (the 12/2 factor is the voltage divider you’ve to undone in your calculation).

If you want/need more accurate reading of the voltage, I recommend you to change the analogReference to INTERNAL and do the previous math with 1,1 volts instead of 3,3 :slight_smile:

Thank you, it’s working great now.

with analogReference(INTERNAL); in the setup(), my code now reads:

[code]void loop() {

float voltage;
float percent;
int sensorValue;

sensorValue = analogRead(A7);
voltage = sensorValue * (1.1 / 1023)* (10+2)/2;
percent = voltage/3.7*100.0;

Serial.print("A");
Serial.print(A7-A0);
Serial.print(" ");
Serial.print(sensorValue);
Serial.print("/1023  ");
Serial.print(percent);
Serial.print("%  ");
Serial.print(voltage);
Serial.print("v   ");
Serial.println();

delay(10000);

}[/code]

With this done, I have moved on to proper sleep modes now. Starting with the watchdog timer.