checking battery voltage


I am developing a birth alert for horses with a Funnel board and a 3 axis sensor. The board is fed with a LiPo pack and works great. But one thing bothers me...the power supply itself.

How can i make a sensor with this setup to check the state off the LiPo. I suppose i can't check it's own powersupply (ground loop or something like that).

Does anybody have a clue how to do that (optocoupler???)

Thanks for al the idea's :)



you can read the battery level through a voltage divider. If you are using a two cell pack (7.4 volts nominal) than you can use two equal value resistors – anything from 1k to 10k would work.

I posted some more information including a sketch here:

Thanks ;D for the answer. That helps a lot...but, can the arduino measure it's own supply? Wil that work good?

I don't need a voltage diveder because the batt is only 1 below 5 Volt.



Sorry, I am not familiar with the funnel board so can’t say more about the best way of connecting it up. Does the funnel board use a regulator to drop the battery voltage?

either way, you would probably still use a voltage divider. If it has a regulator you can use the default voltage reference (probably 3.3 volts) If it doesn’t you would need to use the internal reference (see this page for how to change the reference:

The code in the sketch and the resistor values may need to be altered depending on how its connected, but the principle is the same, analogRead can monitor a battery voltage as long is the value fed to the pin is less than the voltage reference being used.

The funnel is the same as the lilipad.

So what you are saing is that the voltage provided to the analog port must be less than the reference voltage. And than i can measure the batt. voltage? The easy way is indeed with a voltage diveder. I wil try it for sure :)




Just to underline the point, you need a voltage reference that is independent of the supply voltage.

Often the reference voltage is taken from directly the Vcc or voltage that powers the chip. If you do this as the voltage drops so does the reference and so you keep reading the same thing.

You can derive the reference from the Vcc as long as you use something like a zenner diode or a voltage reference chip. Alternatively the internal reference of the ATmega chip is independent of the Vcc as well. is the bottleneck. So using the default aref isn't rigth is this situation. But the avc is 3.3v...regulated. The lipo is 3.7V so 3.3V wil be steady until a certain point (i think). When the lipo is to low on voltage ..the software must have already detected the alarm voltage ..

Or is it safer to use the 1.1V internal ref. and make a voltage divider which divide it to to rigth voltage??



Or is it safer to use the 1.1V internal ref. and make a voltage divider which divide it to to rigth voltage??

Yes that's what I would do.

quick calculation..

inputvoltage max 4.2 volt.. Ref voltage 1.1 Volt. A resistor 39K and 10K must give a good divider...(correct me if i am wrong please)



I would use 3k and 1k

If you use the internal 1.1 volt regulator then you need to divide the voltage by four. This will drop the maximum lipo cell voltage of 4.2 volts down to 1.05 volts. Using 3k ohm and 1k ohm resistors would do this.

Here is a floating point version of the code assuming that the battery voltage has been divided by 4 through as above.

int val = analogRead(batteryPin); // read the value from the sensor float volts = (val / 255 ) * 1.1 ; // calculate the actual voltage

OK...that is clear ;).

But...what with the used 3-axis sensor. This one uses the analog ports to give the position of the board. Those wil give a wrong valeu if i use the 1.1 V internal ref isn't it??

You can scale the readings so they are correct but this will lose some precision. How accurate do you need the readings?

You could switch references depending on what you are reading, but make sure you read the processor data sheet about settling time after switching references.

You can also switch references depending on what you are reading, but be careful to read the section on allowing settling time when references are changed.


What do you mean scale the reading. The precision is not that point. I measure values between 490 < x <580. If x is between those valeus everything is ok otherwise…alarm.

You mean…when reading the 3axis…use default…when reading the batt…use internal. Wouldn’t the uP not be harmed when the input voltage is higher than then ref voltage (always below 5V)?




I was talking about the 3 axis readings - you can divide them as well.

Do you know the part number of the regulator on your board. If the drop-out is low enough you may get away with using the 3.3v reference.

Wouldn't the uP not be harmed when the input voltage is higher than then ref voltage (always below 5V)

No it doesn't do any harm if the voltage is above the reference but below the supply. It's just that you will always measure the maximum.

Ah! Mike beat me to it. Or you could, as pointed out, just divide down the analogue outputs of the accelerometer so you wouldn't have to switch references.

(I prefer switching the references, 'cos software is cheap, but adding six resistors costs money and means I have to heat-up my soldering iron ;D )

Wouldn't the uP not be harmed when the input voltage is higher than then ref voltage (always below 5V)

And remember that your supply voltage is 3.3 volts so your analog inputs need to be well below 5 volts.

@mem The 3-axis uses the 3.3v it would not be over this voltage.

I think i am going to use the trick from AWOL.. it is indeed the easiest way...and cheap :).

I am going home now and will try it later this evening...thanks very much...i wil give the outcome as soon as possible ;D