Reading voltage from battery with Analog inputs?-possible?

Hello
I'm using Pro-Ethernet and I connect him to a battery
I need to know what is the status of the battery ?
is it possible?
I want to define the area is 15V-13.5V , and every step is 0.3V
15V-14.7V :100%
14.69-14.4:80%
14.39-14.1:60%
.
.
.

How do I connect the battery to the analog inputs in order to get this data?

Thanks ,

You use a potential divider, sized such that the maximum voltage on the input gives you 5V at the output which you connect to the analogue in of the arduino.

and

dividing 15V in 0.3V steps are 50 steps:
ADC provides 1023 steps

--> a simple voltage divider to reduce 0..15V to 0..5V should be sufficient.

47k + 22k resistors should not take too much current (0.2 mA) and reduce the 15V to about 4.7 V

0.3V steps are reflected by an AnalogRead difference of about 19.
Or opposite: you have an effective resolution of about 0.02V

Is that exact enough for your battery monitoring?

O.K

Let's say I take 10KOham and 20Koham
this will give my 5V max
5=15*(10/(10+20))

now what ?
how does it help me to continue with the steps?
if the battery is 14.5V I will get 4.833V
if the battery is 13.5V I will get 4.5V

Thanks ,

now what ?
how does it help me to continue with the steps?

Now it is just the same arithmetic as when the voltage was up to 15V, but scaled down by a factor of 3.

(BTW, sp. "ohm" - it was the bloke's name)

I'm sorry ,
but I don't understand what I need to to now .
maybe you can explain in more easy words?
all I know is that the 15V will give my 1023 at the analog (this is the max right? )

thanks ,

I'd probably write a function or macro to do your conversion for you, given the values of the potential divider resistors, and let the compiler and the processor do all the hard work for you.
Then you can just write stuff like

if (voltage > convertDivider (14.7)) {
  level = 100;
}

You can add refinements, but if you keep this sort of structure, you can debug more easily, because all the units are easily recognised when you print them.

my problem is how to change from 14.7 (for example) to analog values
the part of convertDivider
what to do after the conversion is simpler

thanks ,

Assume the reference voltage is 5 volts.
Then an increment or decrement of a single count from the analogue to digital converter represents 5.0 / 1023 volts.

If it's not a "requirement" to only have 6 distinct results only ( 100, 80, 60, 40, 20, 0 )
you can use the map function to turn the analogRead result to a convenient number.

Maybe you just get started and show where you're stuck and tell why ?

there isn't any requirement to 6
can you tell me what does the map function do , and hoe to use it?
and maybe to show me a simple example of it? to understand

Thanks ,

http://arduino.cc/en/Reference/Map

I have read it
but I don't understand it
let me show you what I understand , and fix me if I'm wrong (please...)

y = map(x, 0, 1023 , 1, 100);

y- the new convert number
x- the analog read
0 - from analog low 0
1023 - from analog high 1023
1- to new low 1
5 - to new high 100

every analog that I will read I will get new convert number from 1 to 100, yes?

every analog that I will read I will get new convert number from 1 to 100, yes?

Yes.

You are making heavier wether of this. It is not engineering but simple elementary school maths.

... and you'll use it with numbers like this:

y = map(x, 823, 1014 , 0, 100);

depending on the actual resistor values and which voltage/(analog Reading) you define as 0 % battery capacity.
( Observe the **See also: constrain() ** hint at the end of the Map reference )

If you have arranged your potential divider to give you 5V out when you put 15V in, then for 15V you get a reading of 1023 steps.

Therefore a step is 15 / 1024 = 0.0146484375 volts - it is 1024 because 1023 steps give you 1024 spaces.

So if you measure say 130 from the analogue input this means you have a voltage of :- 130 * 0.0146484375 = 1.904296875 Volts

Then you get real about the accuracy and say this is 1.90 Volts.

Mike,

I understand OP's initial problem was to expose 14.7V or above as 100 % and 13.5V or below as 0 %
( in at least 6 steps )

So I propose map() and constrain() , and hope he'll stick with integer arithmetics
and gets his map parameters by experiment ...

If you are concerned with accuracy, you shouldn't just map the number based on the math. First of all the value of the resistor is likely not to be exact and more importantly there will we a very small current flowing throught the arduino pin and this affects the voltage divider.

I create the divider, then hook up the arduino and perform analog read using the serial monitor. Then I compare that with a measurement of the battery with a digital multimeter.

So you then get something like analogRead(A0) = 800, while the voltmeter is reading 13.1 volts.

Then you can code the conversion like:

long calc1 = ((analogRead(A0) * 16375L) / 100000L) //which would equal 131
float voltage = (calc1 / 10) // this would equal 13.1 (volts!)

You could modify it for two decimals of precision or whatever you prefer.

Also be aware that the bigger resistors you use (the less current you run through it), the less accurate the divider is, so you have to find the right balace for your needs.

and more importantly there will we a very small current flowing throught the arduino pin and this affects the voltage divider.

No.
This is a very very small current and in practice with a 30K total resistor chain will not change the voltage by any significant ammount. The technical term is chuff all.

Look get real. We are talking about measuring a battery to see the state of it. A simple analysis and 1% resistors with a 10 bit converter is more than enough for the OPs requirements.

Grumpy_Mike:
Look get real.

Nice to meet you Grumpy Mike : I

I did state "if you are concerned with acuracy", I wasn't suggesting it was the only way to go. I am brand new to Arduino, and I get the information I need 90% of the time by reading old threads on this forum, so I do not have to bother guys like you with simple questions, I try to save the asking for when I have little other choice. Adding my thoughts to this thread might help the OP or anyone else who may read it in the future.

This was the first time I tried to share on this forum, to try to help someone else instead of just being a mooch.

He is maping 0 - 100% in just 1.2volts, so accuracy appears to be an issue. I was just trying to help, and I still feel my approach is not "over the top". Also, 1% resistors are not the norm, 5% are, and with 5% resistors it can throw this calculation off (worst case scenario) by .5v, that's nearly 50% of the range he wants to measure. Whats the harm in measuring and knowing you are reading the actual voltage?

Just my thoughts.