What I want to use this method later is to adjust a value (distance in millimeter) using 4 rotary switches without touching the source code every time.
/*
Resistance Measurement - www.circuits4you.com
Reads an analog input on pin 0, converts it to resistance, and prints the result to the serial monitor.
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1024.0);
float I = voltage / 1000;
float VRx = 5 - voltage;
float Rx = VRx / I;
Rx = (5 - voltage) / I;
// print out the value you read:
Serial.print("Resistance:");
Serial.print(Rx);
Serial.println(" Ohms");
delay(3000);
}
Which resistor are you measuring - R1 or R2?
What the resistance of the "known" resistor? On the scheme I can see two resistance values - 1.1k and 20k ?
Where you use it in the calculation:
Both resistors are known. I just wanted to test this tutorial to understand how its working.
I use USB to power it. The Arduino is connected to a powered USB Hub
I just wanted to say that your formula is not for your resistor values. I hope that you understand it...
Try this simplest code and show the output in IDE monitor
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1000);
}
I suspect from the wildly varying values that one or more of your connections is loose. Do the results change if you gently wobble the components and connections around? It might help to post some photos of your setup.
You need to decide which resistor is your reference and which one is your object of measurement.
Then you need to rewrite this equation to solve the resistor you want to know...
Thanks.
For this Project I will stay with the sensor value.
I also noticed as soon I power the Arduino with 9V, i get very stable results.
Thank you all for helping. Next step is learning functions and building this: