question about battery

is there any simple way to read a battery's voltage from arduino? thx?

This is a pretty common question. Search this forum and Google for "Measure Battery."

You've given no details (why kind of battery, how often you need to measure it, what you want to do based on the reading, etc.)

coos:
is there any simple way to read a battery’s voltage from arduino?

For a voltage between 5V and 0V, referenced to Arduino ground: analogRead()

For a voltage ABOVE 5V, referenced to Arduino ground: Voltage divider (two resistors) and analogRead()

For negative voltages things get complicated.

[quote author=James C4S link=topic=58033.msg417025#msg417025 date=1302363770] This is a pretty common question. Search this forum and Google for "Measure Battery."

You've given no details (why kind of battery, how often you need to measure it, what you want to do based on the reading, etc.) [/quote]

It's 12V li-ion battery?i want to know when the battery should be replace?so i should measure it first

thx for reply

I have found that if you want to measure the same battery the arduino is on, you need to isolate the battery from the I/O pin when un-powered. Otherwise the atmega will get "back powered" through the I/O pin, draining your battery.