I agree with CR. The real issue is that you are using nominal values for all of your assumptions, which isn't the case. Small errors in the resistors (you didn't say what the actual measured value was), battery voltage, and VCC supply will result in your calculation being off.
Also, make sure you are using the correct data types for variables and constants.
float voltsense = analogRead(voltpin);
float voltage = 5*voltsense/1024;
None of those are floats.
int voltsense = analogRead(voltpin);
float voltage = 5.0 * voltsense / 1024.0;
Welcome to the world of engineering -- which attempts to get the right answers despite the fallibility of man and his manufactured components.
First Question: What model of board are you using?
Second: What is the voltage (Vcc) present on the board?
Third: When you read the spec for your processor chip what did it say the accuracy of your readings would be? (You did read the spec -- right?)
Fourth: Are we talking about long "rats nest" wiring or a simple short run to the battery under test.
Fifth: Is this the ONLY thing hooked to your board? It's not like you have a half-dozen servos and an LED display there too right?
A 12V battery that measures 11.18 Volts sounds interesting -- they usually read higher. A AA battery normally reads what -- 1.62V? Is your voltmeter reading as it should.
The technical version of "Who watches the watcher?" is -- "Who validates the tester?"
People seem to be worrying about the Resistor Values and the tolerance value. Why? In the old days we used trim-pots to set the measuring circuit to a "reference" voltage/current/whatever. We knew and understood "error" --epsilon? The Greek E -- right?
Nowadays everything is digital -- so when we "read" the analog world it must be right? Correct?
I think the issue is the "jitter" in the values.
What is the source of those Jitter amounts.
Is it excessive. If so -- where is it coming from.
Will averaging multiple reads compensate. (Probably...)
The Arduino "accuracy" can be adjusted -- by sacrificing "read speed" -- it can be adjusted -- I have done it. You don't need capacitors. Averaging should in most cases do the same things.
The jitter is likely coming from the onboard ADC -- why? Is it within allowable limits. Is there a source voltage problem for the Arduino Supply? Is there ripple?
Its a controlled current sink with battery voltage measurement (attached diagram), where i am taking readings 1 second apart and storing them in MicroSD Card !
The 10k resistor reads 9.96k on meter and 5k reads 5.01k
The battery Now Reads 11.12V through Meter & Voltage After the Voltage divider is 3.76V
But my code should be independent of voltage reduction, as i need to monitor battery as it discharges but it should be able to measure and scale from 12 to 1 Volt !
simplytuff:
5.00 to be precise but thats through the external 5v pin provided on arduino i believe the arduino default internal reference might be lower ?