4
\$\begingroup\$

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?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ See also this question. \$\endgroup\$
    – stevenvh
    Aug 9 '12 at 17:45
  • \$\begingroup\$ I know this is a pretty old question and I can't seem to be able to answer it anymore, but in case other people come across it, I think the problem was that you hadn't set the pin as input in the TRISx register. Also remember to set the ANSELx register. \$\endgroup\$ Nov 17 '15 at 15:30
3
\$\begingroup\$

You are picking up noise, pretty much like a radio receiver does, but on a lower frequency. If you closely look at the values you measure, you will recognize the 60 or 50Hz mains in it.

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.

\$\endgroup\$
2
  • \$\begingroup\$ That sounds interesting! I wouldn't have guessed it. So, how should my set-up look like? ADC4 - battery - 10K - ground? Is that right? And how could I measure 0V on ADC4 (without the battery)? \$\endgroup\$
    – user11395
    Aug 9 '12 at 15:45
  • \$\begingroup\$ 10k\$\Omega\$ from ADC4 to ground, parallel to where you want to measure your battery. \$\endgroup\$
    – jippie
    Aug 9 '12 at 17:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.