Incorrect reading of Battery voltage from PowerSheild [solved]

Started by Squeeker, January 22, 2017, 11:07:05 AM

Squeeker

This is my first post!

I received my Moteino (LoRa95 R4) and PowerShield(R3), as well as the WeatherShield, and am quite pleased with them. I have been able to get everything working so far except reading the battery voltage from the PowerShield.
From what I've read on the blog, the battery voltage is read from Analog pin 7. I have connected the PowerShield to the Moteino (without the WeatherShield) and have plugged a LiPo battery into it. I then connected the serial Tx, Rx and Gnd to appropriate pins, and am successfully reading the output from the com port.
The voltage reading on the battery is 4.1v, and the voltage reading on pin A7 is 2.15v.
However the values returned from analogRead(A7) are between 879 and 880. I would have expected less than half of that, if my maths on the voltage divider circuit are correct (Code attached).
What am I doing wrong?

perky

I think your reading of 880 is correct. The resistor divider is vbatt->470k->1M->GND, which gives a divide ratio of 1000/1470, or 0.68. So with Vin of 4.1V you would expect to see 2.79V on pin A7. Now, if you assume 3.3V reference that's 2.79/3.3, or 0.85. Your read value of 880 gives a ratio of 880/1024, or 0.86. practically the same.

So, the problem is probably because you're measuring the pin voltage on A7 with a meter or probe that isn't high enough impedance, remember there's a 470k resistor in the way. If for example you used a scope probe it'll have a 1M impedance to ground, and that would pull your measured voltage down (in fact it would be like having 470k pull-up and two 1M resistors in parallel for the pull-down, which is a 0.49 ratio, so 4.1V would put 2.10V on A7, about what you're measuring).

You can check this, do an analogRead(A7) with and without your probe attached, I suspect you'll get two different readings.
Mark.

Squeeker

My mistake, I thought the analogRead was equal increments between 0 and 5v, not 3.3v. ( https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage ).
So, the calculation would be:

vA7 = 0.68 * vBatt
AnalogRead = vA7/3.3 * 1023
vA7 = 3.3 * AnalogRead / 1023
Thus
VBatt = (3.3 * AnalogRead) / 0.68 / 1023
          = 3.3 * 880 / 0.68 / 1023
          = 4.17!

Thanks Mark!

perky

OK, glad you sorted it. BTW I'm still not sure why you were reading 2.15V on A7 as that should have been 2.79V, unless you really were measuring with a 1M scope probe or 1M input impedance meter ;)
Mark.

Squeeker

Was reading with digital multimeter, not sure of internal impedance - flying blind...