Voltmeter; arduino value always falling

Hi,
I've got an Uno board. I'm trying to measure voltage, with the maximum voltage in at 24V. I've got a potential divider set up, with 4 10K resistors as R1 and 1 10K as R2 (for a total of 40K R1). A quick calculation sees that the output to Arduino is 4.8V

My arduino code is set to print the voltage, but instead of holding steady at a specific voltage, it is continuously falling, before jumping up again, as seen here:

958.00
829.00
718.00
621.00
537.00
464.00
400.00
347.00
299.00
258.00
223.00
193.00
167.00
144.00
125.00
107.00
93.00
81.00
71.00
62.00
54.00
47.00
41.00
36.00
31.00
27.00
24.00
21.00
18.00
1005.00
872.00
753.00
......

I've checked all my connections and measured the output with a multimeter too, it is sitting at one value but the Arduino output is still falling.

Does anyone know what I'm doing wrong?

Thanks in advance for any help!

Could be several things. First off did you remember to run a wire from the negative terminal of the 24vdc voltage source to a arduino ground wire? That is a requirement.

Posting a drawing of your wiring would be very useful.

Might post your code also, use the # to post it into a code window.

Lefty

Hi,

Code for this is:

float value=0;

void setup(){
  pinMode(A0,INPUT); 
  Serial.begin(9600);
}

void loop(){
  value=analogRead(A0);
  Serial.println(value);
  delay(500);
}

I can't figure out how to insert an image, so I've attached a circuit diagram and also an image of the circuit so you can see whats going on!

rail circuit.png

It looks from your breadboard that you might have an off-by-one error in the connection between the third and fourth resistors (counting from the left).

--
The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected

Some bugs...

float value=0;  // <-- change float to int

void setup(){
  pinMode(A0,INPUT); // <-- no need for setup pin in Analog. 
  Serial.begin(9600);
}

void loop(){
  value=analogRead(A0);
  Serial.println(value); // Add ( value, DEC)
  delay(500);
}

Here a tip. Use a simple circuit to test your code.

In you case, I will use a small potentiometer, connect one end to +5 and the other end GND, the middle going to the Arduino analog pin ( A0 to A5 ), run the code and expect a vlaue ( 0 to 1023 ) to be print.

If code work, THEN construct the circuit you want to do, test it with out Arduino connected, if reading correct, then connect the Ardiuno and see your results.