Voltage divider

Hello,

I'm trying to use ardunio as ohmmeter using voltage divider but while reading the resistance value from A0 or A1 the value is fluctuating.

Any person can help

Thanks in advance

MoSoli: Any person can help

First post your program and a diagram showing how everything is connected. See this Simple Image Upload Guide

Some examples of the output from the program would also be useful.

...R

I have attached the schematic, the code and the serial reading

try_fluc.ino (1.22 KB)

schematic.png

Try using serial.Print to display just the raw reading from the analogRead() before you run it through your I/V/R calculation, see what that shows.

MoSoli: I have attached the schematic, the code and the serial reading

Please make your images visible in your Post. I gave you a link to the instructions.

...R

it also fluctuates

schematic.png

I can't read the text in your image. It is much better just to copy and paste text rather than posting a picture of it.

It would also be more useful, for debugging, to show the values that are produced by analogRead().

What is the range of variation in the output?

I suspect a very stable reference voltage is required for what you want to do.

...R

You have a bad connection.

Are you using pins and connectors, or have you carefully soldered all of the wires?

Post a [u]clear[/u] photo of your setup.

I have soldered all the wires

It seems that you didn't match the fixed resistor value to the unknown resistor value. Therefore you have large gaps in the displayed resistance when the A/D jumps one value. For max resolution, the fixed resistor value should be switched/matched until the A/D returns about 512. If close(r) to 0 or 1023, then you have the above problems.

BJHenry (post#3) asked you to print the raw value. So what is it.

Please post your code according to the forum guidelines, so we can see it. Leo..

Hi, What are the values of resistance that you are using in the test?

Tom.. :)

Hi,
Try this, I have edited you code to keep float calculations working, and added some Serial.print statements to help debug.

int analogPin1 = A1;
int analogPin3 = A4;

int raw = 0;
float Vout = 0.0;
float V = 0.0;
float I = 0.0;
float R2 = 0.0;
float buffer = 0;
#define  Relay1 24
int outputValue = 0;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup()
{
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.print("Test Results  ");
  pinMode(analogPin1, INPUT);
  pinMode(Relay1, OUTPUT);
  //analogReference (EXTERNAL) ;
}

void loop()
{
  raw = analogRead(analogPin1);
  Serial.print("raw = ");
  Serial.print(raw);
  Vout = ((float)raw / 1024.0) * 5.0;
  Serial.print("  Vout = ");
  Serial.print(Vout);
  V = 5.0 - Vout;
  I = V / 301.0;
  R2 = Vout / I;
  Serial.print("  R2 = ");
  Serial.print(R2);
  if (R2 > 0.5 && R2 < 4.0)
  {
    Serial.print("  test 1 pass");
    Serial.println(  R2 / 1000);
  }
  else
  {
    Serial.println(  R2 / 1000);
  }
  delay(2000);
}

Tom… :slight_smile:

Reply to post #10 How can I match it as I do not know the unknown resistor

Hi,

MoSoli: Reply to post #10 How can I match it as I do not know the unknown resistor

For this part of development of your project, you SHOULD use known test resistor values so you can check your circuit and program. Have you used Ohms Law to check the range of values you can use for various resistors. If you think that ONE fixed value of your known resistor will let you measure all values form 1R to 10M, you will need to reconsider how you want to design your circuit. In the test you show your Serial.print values, what are the two resistors that are in your circuit. You must know your test values?

Have you run the code I edited?

Tom... :)

MoSoli: Reply to post #10 How can I match it as I do not know the unknown resistor

Why do you think a (digital) multimeter has several ranges for resistance. You can't measure a 1ohm resistor accurately with the meter on the 20Megohm range if your DMM only has 2000 counts. So the user has to know the expected value, and/or switch up/down to get the highest resolution. Or you could automate that by making the Arduino auto-ranging. Adding different value pull up resistors with output pins. Leo..

Reply post #12

the fixed resistor is 1.5 k and the unknown resistor (R2) should read 39k and I use a capacitor 0.1u between analog pin and ground

The code is run but (I = V / 1500);

int analogPin1 = A1;
int analogPin3 = A4;

int raw = 0;
float Vout = 0.0;
float V = 0.0;
float I = 0.0;
float R2 = 0.0;
float buffer = 0;
#define Relay1 24
int outputValue = 0;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("Test Results ");
pinMode(analogPin1, INPUT);
pinMode(Relay1, OUTPUT);
//analogReference (EXTERNAL) ;
}

void loop()
{
raw = analogRead(analogPin1);
Serial.print(“raw = “);
Serial.print(raw);
Vout = ((float)raw / 1024.0) * 5.0;
Serial.print(” Vout = “);
Serial.print(Vout);
V = 5.0 - Vout;
I = V / 1500;
R2 = Vout / I;
Serial.print(” R2 = “);
Serial.print(R2);
if (R2 > 0.5 && R2 < 4.0)
{
Serial.print(” test 1 pass”);
Serial.println( R2 );
}
else
{
Serial.println( R2 );
}
delay(2000);
}

raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 988 Vout = 4.82 R2 = 41166.6741166.67
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 985 Vout = 4.81 R2 = 37884.6237884.62
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 986 Vout = 4.81 R2 = 38921.0538921.05
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 987 Vout = 4.82 R2 = 40013.5140013.51
raw = 985 Vout = 4.81 R2 = 37884.6237884.62

reply to post #15

you are right, so if I have "n" numbers of resistances I need to measure ( I know the expected values I should get), I will need to check with "n" fixed resistances to give a close value of the unknown resistance. The closer the fixed resistance is the more accurate result I will get. Right?

is there any relation between the fixed value r and the expected value

Hi, Change this;

  Serial.print(Vout);
  V = 5.0 - Vout;
  I = V / 1500.0;
  R2 = Vout / I;
  Serial.print("  R2 = ");
  Serial.print(R2);

1500.0 You need to check how you mix int and float.

Tom... :)