Go Down

Topic: Wheatstone bridge (Read 5750 times) previous topic - next topic

robtillaart

Quote
i try this code and i I get a negative result,
and i try all code in this thread but it seems all is wrong, because when I change his resistor can result in 1000ohm


You should not measure Vin but Vout.
Vin is a given reference voltage.

I posted your original code with in the comments the proposed code. It fails as it did before.

I will propose the final code which is in line with the other posts:
in the comments the result of the formulas.
Code: [Select]

float Vin = 5.0;
float Vout = 0;
float R1 = 1000;
float R2 = 1000;
float R3 = 1000;
float Rg = 0;

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

void loop()
{
  Vout = analogRead(A0) * (Vin / 1023.0);  // Vout = 0. (assuming all resistors are 1000

  float B = ( R2 * Vin) / (R1 + R2);  // B = 5000/2000 = 2.5
  Rg =  R3 * Vin / (Vout + B) - R3;  // Rg = 5000 / (0 + 2.5) - 1000 = 1000.

  Serial.print(Rg);
  Serial.println(" Ohm");
  delay(1000);
}
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up