Hello,
I've almost finished my steam engine indicator using a rotary encoder and a pressure transducer and everything looks fine so far. The only thing I am scratching my head over is a challenge I encounter:
I attached the pressure transducer to pin A0, but the output looks suspiciously digital.
The sketch I am fiddling with is below:
#include <math.h>
const int pin = A0;
float sensorValue = 0;
float voltage = 0;
float psi = 0;
void setup()
{
pinMode (pin, INPUT);
Serial.begin(9600);
}
void loop()
{
sensorValue = analogRead(A0);
//1st solution attempt
float voltage = sensorValue/1024*5;
float v1 = voltage - 0.5; //the datasheet says a pressure of 0bar/psi corresponds to 0.5V. So 0.5V have to be subtracted to obtain a "starting point".
float bar = (v1/0.116)-0.109; //0.116 is a constant meaning 0.116V change mean a change of 1 bar. Only for this 500psi sensor.
//The 0.109 are for callibration & it is probable this number has to be adjusted for every transducer.
//2nd solution attempt
psi = ((sensorValue - 102)*500/(921-102))-1.832;
Serial.println(sensorValue, 3);
}
Don't mind if a variable is initialized twice or something else, because it isn't cleaned up yet.
The sketch plots something like this:
As you can see, the graph line only changes between 3 values. Very rarely a spike can be seen, which has twice the amplitude from 0 than the 2 common value deviations from 0 psi. I've looked the values up in the serial monitor and even there, there is not the slightest deviation from the 3-4 values represented. Not even behind the decimal point. So, there are ONLY 4 decimal values defining the graph. I suspect the more frequent a value is represented, the closer the real value is to that value.
As seen above, I've checked up what the raw sensor data shows me and it shows, as suspected, only 4 values. 104, 105, 106, 107. I've read somewhere, that the analog input isn't really analog (well, precise enough for many applications), but transforms a voltage value from 0 to 5V into an integer value between 0 and 1023 or 1024.
In consequence, it means there are only 1024 "steps" for a pressure range of 500psi (even less, because the transducer outputs between 0.5 and 4.5V into the A0 pin.
The question I have is: How do I get a better result? Is it better to use an external analog to digital converter modul? Or would it also just give me a 1024-step-resolution? And if not, what model could I use? Or are there better approaches?
Thanks in advance.
