This is my wiring (270k resistor on the left, 820k on the right):
This is my code:
String str1 = "A0: ";
String str2 = "V; A1: ";
String str3 = "V";
double analog_A0;
double analog_A1;
void setup() {
Serial.begin(9600);
}
void loop() {
analog_A0 = analogRead(A0) / 200.19;
analog_A1 = analogRead(A1) / 200.19;
Serial.println(str1 + analog_A0 + str2 + analog_A1 + str3);
}
So what I want to do is the arduino Uno be able to read voltages between 0 and ~20V like a voltmeter. I need to divide voltages by 4, so 20V is divided to 5V.
I read the first part of this article and I understood that I could use a voltage divider to do so, and the sum of its resistors could be about 1Mohm.
Then I calculated two good standard resistor values, 820k and 270k, and bought them.
You can see how much voltage results with a voltage divider like this, at this online calculator:
Then I built the wiring as shown above and wrote the above code. I double checked wiring connections in case of any mistake.
The arduino Uno is connected to the computer via USB.
I measured the 5V pin on the arduino with a multimeter, and it reads ~5.11V, so I use this as the reference for the analogRead().
So the analogRead() returns 0-1023 values, and in case it returns 1023, the real voltage should be 1023 / 200.19 = 5.11V (hence the 200.19 in the code).
Now it should read 1.266V at A1 pin, but it is reading 1.43V:
I discovered that there is a "special" effect when reading these voltages with my multimeter: as the multimeter at 20V range doesn't have a much different impedance than the voltage divider (while the voltage divider has 1.09Mohm, the multimeter seems to have 1Mohm, or at least a few Mohms), when I try to read the voltage across the 270kOhm resistor using the multimeter, it influences the circuit so that the serial readings start to be 1.30V at A1 pin, and the multimeter reads 1.09V.
But it seems to me that if this influence of the analog input high impedance was the problem, then the read voltage should be lower than expected, not higher. It's like connecting a big resistor in parallel with the voltage divider resistor. The resistance will decrease, the current increases, and voltage decreases. I can't see why it's reading 1.43V instead of the expected 1.26V.
I also tried including the real measured values of the resistors in the online calculator, but it doesn't seem to make much a difference.
What is wrong? Thank you in advance.