# Measuring battery voltage of my temp sender

I've read a few guides about measuring voltage using the Arduino but slightly confused by it. I followed a guide that said to make a voltage divider so I'm using something like a 400K and 600K resistors.

As I'm measuring a voltage up to 3V on a 3.3V Pro Mini do I actually need the resistors or can I just plug the positive terminal of the battery straight into one of the analog inputs?

Also I've been getting very inconsistent results. Each reading was up to 0.6V different. Made it better by taking multiple readings and using the highest.

Any suggestions for getting more accurate readings?

I followed a guide that said to make a voltage divider so I'm using something like a 400K and 600K resistors.

Would you like to help out by posting links to what to you are referring, there must be 3 million hits if I ask that question.

As I'm measuring a voltage up to 3V on a 3.3V Pro Mini

You write this as if you already are, are you or are you meaning to say 'I wish to measure a voltage up to 3V ...'?

If I assume you want to, then if your Arduino is a 3.3 volt board and your battery voltage is always less than this, then in therory, yes, you can connect the battery to the analog input.

But, I suggest you insert a series resistor to limit any potential current due to fault conditions or if you were to set the analog input incorrectly. An example of the series resistor would be around 10kΩ.

With a battery connected, which I assume to be a nice stable voltage, I will expect your readings to be steady and generally no need for any averaging code.

If you are highlighting problems with your code then why don't you post your code, like expected?

Paul

rockwallaby:
Would you like to help out by posting links to what to you are referring, there must be 3 million hits if I ask that question.

I can’t actually find the site with the instructions I followed. It was showing how to measure battery voltage with a voltage divider. I think it was using a 9V battery.

rockwallaby:
You write this as if you already are, are you or are you meaning to say ‘I wish to measure a voltage up to 3V …’?

Yes, I am currently using the voltage divider method to measure my battery voltage. I am using 2 AA batteries so they won’t be any higher than the 3.3V input to the Pro Mini. Which is why I am wondering if I actually need the voltage divider.

The code I am using for the voltage measurement is:

``````void loop() {
if (counter==8)
{
analogReference(INTERNAL);
int battInt=0;
for (int i=1; i<5; i++)
{
if (tempBat>battInt)
battInt=tempBat;
}
}
``````

The sleep library shuts off the ADC so I think (not sure) I need to set analogReference each time. I am not really sure if that is the best way to be doing it though and can’t remember why I did.

Is the best way to connect the battery to the A0 pin with a series resistor then just use analogRead without setting analogReference to INTERNAL?

ChrisHigs:
I've read a few guides about measuring voltage using the Arduino but slightly confused by it. I followed a guide that said to make a voltage divider so I'm using something like a 400K and 600K resistors.

As I'm measuring a voltage up to 3V on a 3.3V Pro Mini do I actually need the resistors or can I just plug the positive terminal of the battery straight into one of the analog inputs?

You need the resistor divider. 1:2, so you have 1/3 of the 9volt battery on the A-in pin. e.g. 330k/680k or 470k/1Meg.
You can use high values like that, but you also need a capacitor from A-in to ground. Something like 100n.
Because the A/D does not like to sample from a high source impedance. The cap fixes that.
Leo..

I'm actually only using 3V for the battery input with a 3.3V step up regulator. Do I need a voltage divider for that?

Which is why I am wondering if I actually need the voltage divider.

``````analogReference(INTERNAL);
``````

Then you need to read this analogReference, with repsect to what INTERNAL means.

Either you use analog reference set INETRNAL, which is 1.1 volts and use a divider or as most other people do, which is don't use the analogReference and then no need for a divider.

So, important to remember is that your analog input voltage must not exceed the ADC Vref, whether that be because you set to INTERNAL, which you hav eset to 1.1 Volts or the ADC Vref is board voltage, in your case 3.3 Volts.

I surely hope you understand this, if not, you risk damaging your ADC or the whole uC.

Paul

As rockwallaby explained, you don't need a divider (voltage reducer) if the measured voltage does not exceed the reference voltage.
You also do not need a cap if there is a direct connection (or 10k maximum) to the voltage source.
You can't however measure a 3volt battery that way if the battery also supplies the Arduino directly.
Because the Arduino's Aref will drop as the battery voltage drops.
Leo..

Thanks for the help.

I am using 2AAs with a 3.3V step up so I can measure the voltage of the battery directly.

I just checked and the divider is only giving about 0.65V to the analog input so definitely under the 1.1V internal reference.

I think I will change my setup and wire the positive of the battery to the analog pin with a resistor. Would that consume power constantly or just when reading the voltage?

ChrisHigs:
Thanks for the help.

I am using 2AAs with a 3.3V step up so I can measure the voltage of the battery directly.

I just checked and the divider is only giving about 0.65V to the analog input so definitely under the 1.1V internal reference.

I think I will change my setup and wire the positive of the battery to the analog pin with a resistor. Would that consume power constantly or just when reading the voltage?

A resistor divider uses some power, because it's permanently connected between +batt and ground.
How much depends on the resistor values.
There is very little current flowing into the A-in pin.

You can connect the 2AA batteries directly to the A-in pin if you use the standard Aref in your code, but I advice to put a 10k resistor between +batt and A-in pin. Just in case.
If you use a switch for the batteries, connect the 10k resistor on the Arduino supply side.
You want to avoid battery power on the pin of a non working Arduino. Hence the 10k (protection) resistor.
That resistor value could be as high as 1Megohm, or even more, but then the cap from A-in to ground has to be used again.
This gives the A/D something "solid" to take a sample from.
Leo..

ChrisHigs wrote:

I think I will change my setup and wire the positive of the battery to the analog pin with a resistor. Would that consume power constantly or just when reading the voltage?

If you are referring to a series resistor, then no, it will consume less power, but the difference will be so small.

If you are referring to a resistor divider network, then yes as Wawa says.

You only need the resistor divider newtork if you are wanting to use the analogReference(INTERNAL) where your maximum input volts can only be 1.1 volts.

If you leave analogReference as default, then you can measure up to the Vcc supply of the board, which in your case is 3.3 volts. In this situation you do not need a resistor divider network as you are only meauring an input voltage of some battery of around 3 volts which is less than the Arduino power supply of 3.3 volts.
With this situation it is still a good idea to use a series resistor of around 10kΩ before your analog input pin to reduce any potential fault current.

Please note that the series resistor is not the same as the resistor divider network, they are two different things.

Paul

Thanks.
I've cut the resistor going to ground and just using the 370k resistor to the analog pin now. And removed the inthermal analog reference.

Would the high value resistors without a capacitor give the inaccurate readings? So far with the 370k the readings are within 0.15V so I'm happy with that.

I've cut the resistor going to ground and just using the 370k resistor to the analog pin now.

Way too high, why not do as I suggest and use a 10KΩ?

The input impedance of the ADC needs to be resepected and that is not that high.
You will get a reading with so high a series values, but it is not the best or the done thing.

If you are happy with ±4% good, I wouldn't.

Paul

Yes, I will get around to putting in a 10kΩ resistor when I next get my soldering iron out. It was easier for now just to cut the other resistor out of the circuit. it would be nice to have it reading it more accurately.

Thanks.