Dear All,
I am helping a research group at my university. They need to measure the value of the resistance of a material so I wrote a code for Arduino so they can measure the value of the resistance and also the conditions (I will include a DHT and a photoresistor later on, I have already work with them).
As long as my expertise is (bio)polymer (nano)composites more than arduino electronic and coding I have few questions that I would like to ask you.
Few questions:
The material should have a resistance value between 2 to 10 Mohms, and we need to measure it with an accuracy of 0.1 Mohms.
So I was thinking of putting a pull-out resistor of 100 kOhms. Or its better a pull-in is better to increase resolution? I have seen that usually its used 10 KOhms resistors, but in this case, I want to go a little bit upper to increase resolution. I am doing it right?
So, this is the code,
int TestPinIn = 3; //We will connect the material to this PWM pin, so potentially we can test the resitance in the range of 0-5 V.
int TestPinOut = 5; // The output of the material, this voltage shoudl give us the resistance.
float Vcc; //Voltage value provided by arduino (0-5 V).
float Vread; // Voltage value detected by arduino (0-1023)
float V; //Voltage value detected by arduino (0-5 V)
float Rvalue; // Value of the resistance
float Pullres = 10000; //value of the resistance of the resistor
void setup()
{
pinMode(TestPinIn,OUTPUT);
pinMode(TestPinOut, INPUT);
Serial.begin(9600);
}
void loop()
{
Serial.println("Measure starting in 15 s");
delay(5000);
Serial.println("Measure starting in 10 s");
delay(5000);
Serial.println("Measure starting in 5 s");
delay(5000);
Serial.println("Measure starting now");
unsigned long StartTime = millis();
for( int x = 0 ; x < 255 ; x = x + 25 )
{
analogWrite(TestPinIn, x); //the output voltage value of the pin that supplies electricity to the material will vary from 0 to almost 5 V
Vcc = 5.0*(x/255);//Voltage provided by arduino
float Vout = analogRead(TestPinOut); //Read how much voltage arrives to the detection pin
V = Vout*(5.0/1023.0); // Conver the voltage value to 0 - 5 V from the 0-1023 of the analogread.
Rvalue = Pullres*(Vcc/V -1);// https://en.wikipedia.org/wiki/Voltage_divider
unsigned long CurrentTime = millis();
unsigned long ElapsedTime = CurrentTime - StartTime;
Serial.print("Time: ");
Serial.print(ElapsedTime);
Serial.print(" s; ");
Serial.print("Vcc: ");
Serial.print(Vcc);
Serial.print(" V; ");
Serial.print("Vdetected: ");
Serial.print(V);
Serial.print(" V; ");
Serial.print("Resistance of the material: ");
Serial.print(Rvalue/1000.0);
Serial.println(" kOhms; ");
delay(500);
}
}