i’m trying to make a ohmmeter with an arduino and i’m having a program making it auto range. i have been trying it a few different ways, both on the hardwear side and in the code but i cant seem to make any head way.
i have some diodes(1n4148 and have tried 1n4003) in series with my contral resisters. im using a voltage devider with R1 as my constant and the lower resister is what im putting between leads with analogRead delow the diode.
now A1 is telling me, with a 6k7 as R6 ohm is .057v, 1299.4350ohm, range 2, analog pin0 115
that all seems a little random to me. i know the forword voltage of the diode is going to change the reading i get some but going to a different restister just seems to give a nother random reading.
does any one know another approach to this?
// _____
// - | _R1__ | - VCC
// AnalogPin - '_____
// '- | _R2__ | - GND
// R2 = resistance to be measured
int AnalogPin = 0; // potentiometer wiper (middle terminal) connected to analog pin 3
int Alog1;
int Alog2;
int Alog3;
int Alog4;
int Alog5;
// outside leads to ground and +5V
int raw = 0; // variable to store the raw input value
int Vin = 5; // variable to store the input voltage
float Vout = 0; // variable to store the output voltage
float R1 = 10; // variable to store the R1 value
float R2 = 0; // variable to store the R2 value
float buffer = 0; // buffer variable for calculation
int range = 200;
void setup ()
{
Serial.begin (9600);
Serial.println ("Measure resistance");
Serial.println ();
}
void loop ()
{
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
range = 0;
R1 =1000000;//1g ohm
digitalWrite(8, HIGH);
raw = analogRead(AnalogPin);
if(raw < 100){
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
raw = analogRead(AnalogPin);
range = 1;
R1 =100000;//100k ohm
}
if(raw < 100){
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
raw = analogRead(AnalogPin);
range = 2;
R1 =10000;//10k ohm
}
if(raw < 100){
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
raw = analogRead(AnalogPin);
range = 3;
R1 =1000;//1k ohm
}
if(raw < 100){
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
raw = analogRead(AnalogPin);
range = 4;
R1 =100;//100 ohm
}
Alog1 = analogRead(1);
Alog2 = analogRead(2);
Alog3 = analogRead(3);
Alog4 = analogRead(4);
Alog5 = analogRead(5);
Vout = (5.0 / 1000.0) * raw;
buffer = (Vin / Vout) - 1;
R2 = (R1 / buffer);
Serial.print("Voltage: "); //
Serial.println(Vout); // Outputs the information
Serial.print ("resistance ");
Serial.print (R2, DEC);
Serial.println (" ohm.");
Serial.print ("range: ");
Serial.println(range, 1);
Serial.print ("analogPin: ");
Serial.println (raw, DEC);
Serial.print ("Alog1: ");
Serial.println (Alog1, DEC);
Serial.print ("Alog2: ");
Serial.println (Alog2, DEC);
Serial.print ("Alog3: ");
Serial.println (Alog3, DEC);
Serial.print ("Alog4: ");
Serial.println (Alog4, DEC);
Serial.print ("Alog5: ");
Serial.println (Alog5, DEC);
Serial.println ("**************************");
delay (3000);
}