# battery voltage with microcontroller [duplicate]

Possible Duplicate:
Arduino has an input value in disconnected pin

I wish to measure the voltage of a 1.5V battery using a microcontroller (supply voltage of 3V).

I thought of connecting the battery on the ADC4 input of the microcontroller, and wrote a program which reads the ADC4.

Initially, I programmed the microcontroller without connecting the battery to ADC4. I was expecting to get a value of 0V (nothing connected to ADC4), but I didn't. Instead, I am getting a higher value which is also fluctuating. I tried to measure the voltage on ADC4 with a voltmeter, but I can't get a reading since it is obviously fluctuating. Why is that happening?

-
See also this question. –  stevenvh Aug 9 '12 at 17:45

## marked as duplicate by W5VO♦Aug 9 '12 at 15:42

Easiest way to get rid of it is to attach a resistor to ground, you want a slight load when measuring the battery anyway. 10k$\Omega$ will probably get rid of the noise. Depending on the battery you might want to change it to a lower value to give it some load.
10k$\Omega$ from ADC4 to ground, parallel to where you want to measure your battery. –  jippie Aug 9 '12 at 17:59