I am using arduino Uno to read voltage from A0 pin with simple 1/3 resister divider (5v applies to a voltage divider, and A0 gets 1/3 of 5v). There is a relay connected to D1 pin.
(My eventual goal is to measure 15v, that's why using voltage divider to diagnose the problem)
I noticed that when relay is on, the A0 read is higher than it should be. I am not sure what's the cause, and like to understand it.
Description about the circuit:
A0: analog pin used to measure voltage.
D1: a digital pin used to control a relay.
Resistor divider: R1 = 2k, R2 = 1k. R1 connects to 5v (arudino Uno 5v output). A0 is connected to R2, therefore, A0 should get 1/3 of 5v, which is 1.67v.
Few measurements to diagnose the problem:
Vmesaure_all: a manual voltage measure on R1 + R2.
Vmeasure_r1: a manual voltage measure on R2 only, which is input voltage of A0.
Vcode_r1_A0: arduino A0 analog read.
A)Relay is off:
Vmeasure_r1=1.67v (1.67 *3 = 5.01)
Vmesaure_all=5.03v
Vcode_r1_A0=339 (339 * 3 = 1017)
All above makes sense.
B) Relay is on:
Vmeasure_r1=1.63v (1.63 * 3 = 4.89v. OK. Makes sense as it is almost same as Vmesaure_all)
Vmesaure_all=4.91v (Relay is a load, it makes voltage drop on if measuring voltage of R1+ R2. I think it is expected)
Vcode_r1_A0=345 (why higher than 339, which is relay off A0 read???)
I could not explain this. If use this value to calculate voltage on R1 + R2, you will get higher voltage (the voltage to be measured), compared with relay off.
I would expect Vcode_r1_A0 to be < 339.
I did few experiments, andgot consistent behavior described above. Why?