First of this forum has been a great help for all my projects and this is the first time I've actually had to ask a question.
I am using an Arduino to read a pressure sensor. The pressure sensor reads from 0-200PSI. At 0PSI the resistance is 10.9 Ohms and at 200PSI it is 163.6 Ohms.
I used a voltage divider at first to try and find the value of the sensor and then mapped that in the code, but it was not accurate at all. I used a 10Ohm at R1 and supplied 5v.
I am using pin A0 to read the sensor.
I was wondering if anyone could recommend a better set up to read the resistance from the sensor and convert that to a pressure reading?
Do you think a voltage divider would work alright?
At first I had a 10 Ohm resistor as R1, R2 was the pressure sensor, Vin was 5v, and I measured the values from Vout to A0.
Once I found the values inputted into A0, I mapped it to 0-200PSI. This worked great at 0 and 200 PSI, but anything in between was off. It would read about 120 PSI when it was really 40 PSI in the tank, etc....
Instead of putting a resistor in series with the sensor to form a potential divider, with its inherent nonlinear characteristics, you can feed the sensor from a constant current source.
The voltage across the sensor is then proportional to it's resistance.
You can make a constant current source from an LM317 voltage regulator and a single resistor.
If you choose a current of around 6mA, and make it variable, then you should be able to calibrate your circuit to give you an ADC count of just over 200 for 200psi, and just remove a small zero offset to give you a direct reading of psi.
You could use a higher current if you want better resolution, but you risk damaging the sensor by excessive power dissipation.
JohnLincoln:
Instead of putting a resistor in series with the sensor to form a potential divider, with its inherent nonlinear characteristics, you can feed the sensor from a constant current source.
The voltage across the sensor is then proportional to it's resistance.
You can make a constant current source from an LM317 voltage regulator and a single resistor.
If you choose a current of around 6mA, and make it variable, then you should be able to calibrate your circuit to give you an ADC count of just over 200 for 200psi, and just remove a small zero offset to give you a direct reading of psi.
You could use a higher current if you want better resolution, but you risk damaging the sensor by excessive power dissipation.
So you believe this is the best way to go?
There is no way to get it to work with a simple voltage divider?
If I went with the voltage regulator, R2 would be the sensor and what you recommend R1 be?
Sensor sticker states 10-180ohm.
I would try a voltage divider with a 680ohm resistor.
That will give ~1volt max (0.97v@200psi) at the analogue input.
Read that with 1.1volt Aref.
That resistor/sensor ratio might already be lineair enough without current source or formulas.
Add a formula if you want it more accurate.
Leo..
Ah, didn't see the link on my phone.
Some good info there. If I follow it and make a similar setup, I get a resistance reading of 13.08 Ohm at 0 PSI and 166.46 at 200 PSI.
I am using a 330 Ohm 5% resister as R1 and 3.3v as Aref and Vin.
Now to just try and come up with a formula to convert this and see what I get.
Yeah, its still giving some weird readings... Maybe I am going into this to far with the formulas?
// which analog pin to connect
#define THERMISTORPIN A0
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 5
// the value of the 'other' resistor
#define SERIESRESISTOR 330
int samples[NUMSAMPLES];
void setup(void) {
Serial.begin(9600);
// connect AREF to 3.3V and use that as VCC, less noisy!
analogReference(EXTERNAL);
}
void loop(void) {
uint8_t i;
float average;
// take N samples in a row, with a slight delay
for (i=0; i< NUMSAMPLES; i++) {
samples[i] = analogRead(THERMISTORPIN);
delay(10);
}
// average all the samples out
average = 0;
for (i=0; i< NUMSAMPLES; i++) {
average += samples[i];
}
average /= NUMSAMPLES;
//Serial.print("Average analog reading ");
//Serial.println(average);
// convert the value to resistance
average = 1023 / average - 1;
average = SERIESRESISTOR / average;
Serial.print("Sensor resistance ");
Serial.println(average);
int P;
P =(0.7669*average)+13.08;
Serial.print("P: ");
Serial.println(P);
delay(100);
}
What are these 'inaccurate' and 'weird' readings ?
In post 3 you show us that it has a near linear relation - how did you plot this ? It doesn't look weird ...
Regardless, columns A and C in that plot pretty much outline a lookup table you could use to convert 'PSI' to actual - use a linear interpolation for intermediate values ...
Or assume completely linear and:
actual = 0.765*PSI + 11
Is it noisy ? average samples over time in that case (a simple low pass filter)