Arduino and analogRead

Hi all -

I'd like to use my Arduino as a basic voltmeter. I'm building a blimp and need to monitor the battery. I am using The MathWorks' ArduinoIO API, which essentially gives me the same functions as is naively available on the Arduino if I wrote in embedded C.

I have a 12V battery and using three 2kOhm resistors to build a voltage divider. I tied analog pin 5 of my Duemilanove to the last resistor in the circuit; a voltmeter verifies that the voltage across the last resistor is 4.14V.

I expected an analogRead() against that pin would give a reading of about 847, but this value is constantly jumping inside a range of 350 to 500.

Connecting the pin to AREF and trying an analogRead() gives me 1023, and connecting it to GND gives me 0, as expected.

So I'm not sure what's wrong with my circuit - am I missing something here? I thought this should be a pretty simple task..

Thanks for the help!

I tied analog pin 5 of my Duemilanove to the last resistor in the circuit; a voltmeter verifies that the voltage across the last resistor is 4.14V.

Your connections are not clear. Any chance you can upload a diagram of how you have things connected?

                      +-------------+-+
                      |               |
                      |               |
                      |             +-++
                  +---+----+        |  |
                  |   +    |        |  |
                  |        |        |  | 2kOhm
                  |  12V   |        |  |
                  |   -    |        +-++
                  +---+----+          |
                      |             +-++
                      |             |  |
                      |             |  | 2kOhm
                      |             |  |
                      |             |  |
                      |             +-++          ARDUINO A5
                      |               +---------------------+
                      |             +-++
                      |             |  |
                      |             |  |  2kOhm
                      |             |  |
                      |             +-++
                      +---------------+

I'm measuring the voltage across the last resistor.

EDIT: I think I got it - had to connect the Arduino's ground to the negative battery terminal..

Your depiction doesn't show a connection from the 12vdc negative to a arduio ground pin, that is also required.

Lefty