how to make a low level indicator for the arduino powered battery?

I would like to know if I must use- the method of the Voltage divider!

or maybe there is a better and an economic way to measure my buttery to be known when the power supply to the arduino is too low ?

I saw the article below (*) and my second question is for what this method uses ?
I'm not a pro and I probably didn't understand a few Terms of it like what is the vcc against vin ..
a little Terminology could be help to understand for what does this method use !

(*) the article :

"Another option is to use the Arduino's internal 1.1V bandgap voltage reference to determine the value of VCC without the use of any additional external parts as detailed at these two links:

http://jeelabs.org/2012/05/04/measuring-vcc-via-the-bandgap/

http://forum.arduino.cc/index.php?topic=88935.0

lots of thanks in advance !

Fundamentally you need to understand that the "bandgap" reference is a fixed voltage reference regardless of input voltage or environment changes.

If you connect your analog pin to the source voltage of your battery then the Arduino is using the source voltage as reference to measure against.
Imagine your battery is a glass of water that's full, then whilst you empty the glass you then also replace it with a smaller one - so it seems that it stays full!

VCC is the source input voltage - your battery in this case.

By using the bandgap reference that is always 1.1V, you can calculate the VCC because the reference measured value changes with respect to VCC - i.e. you've got two glasses of water now so when one glass gets smaller you can compare it.

Measuring the bandgap voltage means manually adjusting the ADC read, as you can't directly set it through the analogRead() function. This is why there is a bitset() function also.

You can then use the readout of that pin to calculate your battery voltage.
VCC = 1100 / AnalogReadout * 1023

thank you a lot !!

Unfortunately I just not sure that I understand correctly . I understand that I should not connect my battery voltage to an analog pin or any other place but only to the v-in of the arduino power of course . and the absolute measurement of the battery voltage is obtained thanks to the "bandgap" reference 1.1v which is stable in any case so it gives us a reference !

but i thought that the "battery voltage" v-in or v-ss (still don't understand the difference between those 2 words )that is being measured ( respect to the 1.1 v bandgap reference ) is the battery voltage that is created after it passed trough the regulator to become a stable 5V no matter what is the real voltage of the battery so in that case we dont measures the real battery sours ??

more than this ! if it does make an analysis between the 1.1 and the real battery sourse ,so the battery sours is about 6 volts when its full, and I understand that the arduino can stand only 5V ,so i don't understand how the arduino can make analysis to a voltage that is more than 5 V ?

Sorry to trouble.. :slight_smile:

Let's start all over.

What battery do you want to measure. A 9volt battery or e.g. a 3.7volt LiPo battery.

A 9volt battery is higher than Arduino's 5volt supply, even when almost flat.
Arduino can measure that voltage directly with a 1:1 voltage divider, using the normal 5volt Aref.

There are some gremlins when you measure a battery that is lower than 5volt, and the battery is powering the Arduino directly.
The normal reference voltage is the supply voltage, so when the battery voltage drops, Aref also drops.
Therefore you will always measure the same digital value.

The solution is to use a lower Aref. Lower than the battery voltage.
Arduino has a very stable 1.1volt Aref build in.

You always have to use voltage dividers to lower the battery voltage to the maximum voltage the analogue input can take.
Leo..

Leo , I would like to thank you again for your rapid answers!

can you direct me to a site or a photo that shows a sketch and description of how to make this operation to a 6 volt battery sours with a 5v arduino ?

my aim is to know when the sours drops before it cause a failure to the arduino!

An Arduino won't "fail" from a low voltage.
At some point it just stops working.
That might be ~4volt (5volt battery) for a 5volt Arduino.

Remember that the Arduino supply is always ~1volt lower than the battery voltage, because of the regulator.
Therefore a 6volt battery is a bad choise. There is hardly any room for error.
e.g. four rechargeable NiMH AA batteries produce 4x1.2volt when 50% charge is left.
That's 4.8volt -1volt for the regulator = 3.8volt for the Arduino. :frowning:
You could connect the battery straight onto the 5volt line, at some risk.
If the battery voltage is higher than 6volt, it could damage the Arduino.

The parts you have to use to measure the battery voltage depend on the type of Arduino and the type of battery.
I will assume a 5volt Arduino and 4xAA batteries (not rechargeables).

Make a 1:5 voltage divider with two resistors in series. e.g a 10k and a 47k.
10k from analogue pin to ground, and 47k from analogue pin to +battery.
That will divide the battery voltage by six. So ~1volt on the analogue pin.
Read the value of the analogue pin with 1.1volt ref enabled.

Leo..

thanks man !