Resistor measure - I am getting random values

Hello everybody!
I am testing a resistor measurer which should print a PASS or FAIL values if the Ohm value matches between 900K ~ 1,1M Ohms.
The divider is composed by a resistor of 22K Ohm to GND and the 1M Ohm resistor to VCC.
But sometimes the LCD screen shows random values.
I have grounded all analog pins using a 1K Ohm resistor. Did not work.
Is there another method to avoid getting random values?

Thank you.

Note that the A/D is designed to be used with a 10K input impedance.

You could try reading the analogue input twice in a row and only using the second value.

You could try a 0.1uF ceramic capacitor between the input and ground.

You could try printing out the value and seeing how far it is out.

If all that fails then put an rail to rail op amp configured as a voltage follower between the divider and the analogue input.

My crystal ball says that the problem is on line 42 of the code that we haven't seen.

Also, 22K in the divider is a poor way to measure a 1M resistor. However, the results should be poor, not random.

Wiring diagram? Wire lengths?

Yes, use a 1M resistor in parallel with 10--100nF (plastic film) as the lower part of the divider and wait
at least 0.5 seconds before taking each reading to allow for settling time of the RC circuit.

The noise you are seeing will be much less significant against a count of about 500 than it is
against a count of about 20.

You are probably seeing some sort of interference noise, but first fix the lack of precision in
your method.

Hello dear friends. I connected a capacitor in parallel with 22K resistor and the problem was solved. I just added a small delay before measure starts to ensure RC circuit is perfect stabilized.

Thank you so much for your help! I really appreciate it.

Best regards.

That is high enough resistance values you are testing that you need to make sure your fingers are not touching across the resistors - your body/skin resistance will significantly affect the readings.

claudiohi:
Hello dear friends. I connected a capacitor in parallel with 22K resistor and the problem was solved. I just added a small delay before measure starts to ensure RC circuit is perfect stabilized.

Thank you so much for your help! I really appreciate it.

Best regards.

If you sample over a period longer than that of the noise in your circuit, then the value will be more accurate.
Careful with the capacitance, it's charge discharge period can affect the measurement, for that reason I'd use a 0.1 to 0.2 µF ceramic here.

Ceramics may be leaky, use plastic film at high impedance.