Megaohm meter

Hi,
Can anyone help me in building a circuit (on ARDUINO UNO) that can detect megohm resistance (from 14 Mohm to 1 Mohm)?. I tried with a voltage divider but i don’t know why i can’t detect that range of resistance even i i use a known resistance of 10 Mohm.

If you tell us what you did (post code and schematic diagram), maybe we could explain where you went wrong.

Thank you
When i used these codes for measuring lower resistance (10 kohm) it worked (changing the value of R1 to kohm resitors).

this is my code, i followed this link http://www.circuitbasics.com/arduino-ohm-meter/:
"
int analogPin= 0;
int raw= 0;
int Vin= 5;
float Vout= 0;
float R1= 1000000;
float R2= 0;
float buffer= 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
raw= analogRead(analogPin);
if(raw)
{
buffer= raw * Vin;
Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
R2= R1 * buffer;
//Serial.print("Vout: ");
//Serial.println(Vout);
Serial.print("R2: ");
Serial.println(R2);
delay(100);
}
}
"

Even using this other code it doesn't work:
"

int flexs =A0; //flex sensor connected in pin A0
int data = 0;

void setup()
{

Serial.begin(115200);
pinMode(flexs, INPUT);
}

void loop()
{
data = analogRead(flexs);
Serial.println(data);
delay(50);
}
"

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

Please use code tags when posting code. See "How to use this forum".

When you have time, post a wiring diagram (hand drawn, not Fritzing).

The ATMega328P microcontroller "...ADC is optimized for analog signals with an output impedance of approximately 10kohm or less." (from the datasheet.) Because it uses a sample-and-hold architecture, current needs to flow from the circuit being measured into the pin to charge that S/H capacitor during the sample time.

With a super-high resistor divider you're probably not getting sufficient current flowing into the pin to allow the S/H to work properly.

Consider adding a low-output impedance buffer between your resistor divider and the analog pin. An operational amplifier configured as a voltage follower might work though at your resistances the circuit may not be entirely stable.

Something along the lines of an OPA141 might be worth a try.

https://www.digikey.ca/product-detail/en/texas-instruments/OPA141AIDR/296-48324-1-ND/8347339

Why did you post the code that worked? Don't you want help with what didn't work.

Please edit your post to add code tags, and post a wiring diagram.

I'd use a rail-to-rail CMOS or JFET input opamp as a follower to buffer the voltage divider.