Hello
I have a project creating an Ohmmeter that tests several sensors at the same time.
For all purposes and intents, let's go with trying to measure a benchmark of 180Ohm resistors.
So I have the basics down, I can test for several resistors at the same time.
My problem is that measuring several of them reduces my expected values too much.
Here is what I do:
Every 500ms I turn 1 digital pin on. It sends a current to 4 resistors.
in each output I have a voltage divider, comprised of the known resistor (820ohm) and the unknown (which should output around 180ohm).
These voltage dividers are connected to a conduit leading to a wire which leads to an analog pin.
The whole thing multiplied by 4
The expected output should be around 180ohm with tolerance of less than 10%.
I have a fix, but I'm not sure if it's good-
R = Rref * (1 / ((Vin / Vout) - 1)) ** 4*;
Can I do that? If not, does anyone have an idea what am I doing wrong?
Why times 4?
It seems your idea is to have 16 independent voltage dividers...
Do you also measure your vcc? (Voltage divider with 2 equal resistors to another analog pin).
All depend on the accuracy of your 5V supply (which is often not great...
You are aware that analogread will give a number in the range 0-1023 (or 1024 I am not sure)?
You should check that the digital output delivers that much output current without a small decrease of voltage...
@build_1971
Thanks
I'm aware of the analogread number range, and I am measuring voltage but from the digital pins, not from vcc (because I didn't have a reason to do it)
If I remove lines from the analog conduit, the value is as close as I wanted it
Can you draw a circuit, with just one bridge assembly, so we can comprehend your method?
Not Fritzy.
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.
By connecting four of your potential dividers together to the same Analogue pin you effectively end up with 820Ω pulling the pin high, together with the parallel combination of (4 x 180Ω plus 3 x 820Ω) pulling the pin low.
You just can't connect separate 4 potential dividers to the same analogue pin and not expect interaction between them.
To test 16 resistors simultaneously you need 16 analogue pins not 4.
My impression is that OP wants to perform 'scanning' by enabling or disabling the dividers with DO. So activate 4 dividers and measure them with 4 analog ports and then move to the next four dividers. Like multiplexing of LED's.
Perhaps the problem is that, when not activated, the digitalWrite will hold the divider low. Maybe it should be set to pinMode INPUT to let it float (so it does not influence the neighbouring dividers that are read by the same analogPin). Like with charlieplexing...
We would need a proper schematic and the code to see what the general idea is...
const int sensorPin1 = A0, sensorPin2 = A1, sensorPin3 = A2, sensorPin4 = A3; // Analog input pins that sense Vout. Sensor 1.
const int triggerPin1 = 7; // Digital input pin that triggers set 1.
const int triggerPin2 = 8; // Digital input pin that triggers set 2.
const int triggerPin3 = 9; // Digital input pin that triggers set 3.
const int triggerPin4 = 10; // Digital input pin that triggers set 4.
int sensorValue = 0; // sensorPin default value, first set.
float Vin = 5; // Input voltage
float Vout = 0; // Vout default value
float Rref = 820; // Reference resistor's value in ohms (you can give this value in kiloohms or megaohms - the resistance of the tested resistor will be given in the same units)
float R = 0; // Tested resistors default value
int value = 1; // Activation map: 1 through 4 determines which digital pin is currently active, corresponding to tested sets.
void setup ()
{
digitalWrite(triggerPin1, HIGH);
digitalWrite(triggerPin2, LOW);
digitalWrite(triggerPin3, LOW);
digitalWrite(triggerPin4, LOW);
analogWrite(triggerPin1,125);
analogWrite(triggerPin2,150);
analogWrite(triggerPin3,175);
analogWrite(triggerPin4,200);
Serial.begin(9600); // Initialize serial communications at 9600 bps
}
float resistance(int Pin)
{
sensorValue = analogRead(Pin); // Read Vout on analog input pin A0 (Arduino can sense from 0-1023, 1023 is 5V)
//Serial.println(value);
Vout = (Vin * sensorValue) / 1023; // Convert Vout to volts
R = Rref * (1 / ((Vin / Vout) - 1)); // Formula to calculate tested resistor's value
return R;
}
void loop ()
{
switch(value)
{
case 1:
R = resistance(sensorPin1);
Serial.print("Brush 1 of Sensor 1: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin2);
Serial.print("Brush 2 of Sensor 1: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin3);
Serial.print("Brush 3 of Sensor 1: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin4);
Serial.print("Brush 4 of Sensor 1: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
digitalWrite(triggerPin1, LOW); // Turn this set's trigger off, continue with the next set
digitalWrite(triggerPin2, HIGH); // Turn this set's trigger on, for the next sampling
value = 2;
break;
case 2:
R = resistance(sensorPin1);
Serial.print("Brush 1 of Sensor 2: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin2);
Serial.print("Brush 2 of Sensor 2: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin3);
Serial.print("Brush 3 of Sensor 2: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin4);
Serial.print("Brush 4 of Sensor 2: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
digitalWrite(triggerPin2, LOW); // Turn this set's trigger off, continue with the next set
digitalWrite(triggerPin3, HIGH); // Turn this set's trigger on, for the next sampling
value = 3;
break;
case 3:
R = resistance(sensorPin1);
Serial.print("Brush 1 of Sensor 3: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin2);
Serial.print("Brush 2 of Sensor 3: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin3);
Serial.print("Brush 3 of Sensor 3: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin4);
Serial.print("Brush 4 of Sensor 3: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
digitalWrite(triggerPin3, LOW); // Turn this set's trigger off, continue with the next set
digitalWrite(triggerPin4, HIGH); // Turn this set's trigger on, for the next sampling
value = 4;
break;
case 4:
R = resistance(sensorPin1);
Serial.print("Brush 1 of Sensor 4: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin2);
Serial.print("Brush 2 of Sensor 4: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin3);
Serial.print("Brush 3 of Sensor 4: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
R = resistance(sensorPin4);
Serial.print("Brush 4 of Sensor 4: ");
Serial.println(R); // Give calculated resistance in Serial Monitor
digitalWrite(triggerPin4, LOW); // Turn this set's trigger off, continue with the next set
digitalWrite(triggerPin1, HIGH); // Turn this set's trigger on, for the next sampling
value = 1;
break;
default:
break;
}
Serial.println(); // Keep the log spaced
delay(1000); // Delay in milliseconds between sensors
}
The forum keeps displaying everything in right-to-left so apologies if this causes confusion
Does it work now?
Or do you still need to set pinMode(pin, INPUT) instead of digitalWrite(pin, LOW)?
If so, do not forget to add
pinMode(pin, OUTPUT) before the next digitalWrite(pin, ...
const int sensorPin1 = A0, sensorPin2 = A1, sensorPin3 = A2, sensorPin4 = A3; // Analog input pins that sense Vout. Sensor 1.
const int triggerPin1 = 6; // Digital input pin that triggers set 1.
const int triggerPin2 = 9; // Digital input pin that triggers set 2.
const int triggerPin3 = 10; // Digital input pin that triggers set 3.
const int triggerPin4 = 11; // Digital input pin that triggers set 4.
int sensorValue = 0; // sensorPin default value, first set.
float Vin = 5; // Input voltage
float Vout = 0; // Vout default value
float Rref = 820; // Reference resistor's value in ohms (you can give this value in kiloohms or megaohms - the resistance of the tested resistor will be given in the same units)
float R = 0; // Tested resistors default value
int value = 1; // Activation map: 1 through 4 determines which digital pin is currently active, corresponding to tested sets.
void setup ()
{
pinMode(triggerPin1, OUTPUT);
pinMode(triggerPin2, OUTPUT);
pinMode(triggerPin3, OUTPUT);
pinMode(triggerPin4, OUTPUT);
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
pinMode(sensorPin3, INPUT);
pinMode(sensorPin4, INPUT);
digitalWrite(triggerPin1, HIGH);
digitalWrite(triggerPin2, LOW);
digitalWrite(triggerPin3, LOW);
digitalWrite(triggerPin4, LOW);
analogWrite(triggerPin1,125);
analogWrite(triggerPin2,150);
analogWrite(triggerPin3,175);
analogWrite(triggerPin4,200);
Serial.begin(9600); // Initialize serial communications at 9600 bps
}
Results are still the same- 43.91ohm out of 180
You should change pinMode repeatedly in loop().
digitalWrite(pin, LOW) will not shut off power to the pin. It will actively connect the pin to ground...
@TomGeorge
My idea was to use measure 4 resistors every iteration. Starting from those connected to digital pin 7. Get their values, turn pin 7 off, turn the next pin on and the next iteration will measure the resistances connected to digital pin 8
and so on.
Schematic: