This is my first attempt at logging pressure. I bought a 3-wire "100 PSI" pressure transducer from Amazon. I think it's actually a 0.5Mpa transducer because I'm using a >>highly accurate<<
bicycle pump to test it and an external gauge from an old air compressor. I trust the air compressor gauge far more than the bicycle pump gauge. I never threw the air compressor in the back of my truck. It matters not, 0.5Mpa will work just fine for my purposes. There's a blow off valve set at 75 PSI so it should never see 0.5Mpa and typical operating range is 30-something to mid-50s PSI.
I digress. When the transducer is at ambient pressure, it returns a value between 163 and 168 instead of the expected low 100s. I'm guessing it's easier to adjust the calculation to work on a scale from 165-??? than it is to write a calibration adjustment, but I want to keep this intuitive for future changes without having to spend so much time to calibrate my code.
What is a better way to do this that still puts a variable in the calculation to adjust both the zero and still have full sweep of the range?
Note: there's values in comments that I used when I thought I had a 0-100PSI transducer.
int transducer_signal;
long last_output;
float scale = 0.5; //72PSI 0.689; //100PSI //the maximum resolution on the transducer in Mpa. Mine is 100PSI or 0.689
float calibration_offset = -0.0403; //-0.0535; //inverse of whatever the transducer reads at ambient pressure. This one reads 0.05 (guessing on the 0.055 part) at ambient pressure
float calibration_magnifyer = 1; //0.51; //if transducer is perfectly accurate, this is 1; If it reads high, it's less than 1; Reads low, more than 1; Never zero!
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
long now = millis()/1000;
transducer_signal = analogRead(A0);
if(now % 5 == 0 && last_output != now){
Serial.print("input: ");
Serial.println(transducer_signal);
float outputMpa = (((transducer_signal - 102) * scale / 819) + calibration_offset) * calibration_magnifyer; //math works like this: minimum is 0.5V max is 4.5V. So you must subtract 10% off each end of the meter. 102=1024/10, 819=1024-102 "scale" is what ever the full resolution of the transducer is.
Serial.print("calculated value: ");
Serial.print(outputMpa);
Serial.print(" Mpa, ");
Serial.print(outputMpa * 1000);
Serial.print(" pa, PSI: ");
Serial.println(outputMpa * 145);
last_output = now;
}
}
Last, the reason I think I have a 0.5Mpa transducer is I got this output a few times when pumping it up. The "input" is the raw value from the Arduino.
input: 1024
calculated value: 0.52 Mpa, 522.58 pa, PSI: 75.77
I'm a big guy. I like to pick stuff up and put stuff down. It really didn't feel like I was pumping 100PSI through a bicycle pump which 1024 on a 100PSI transducer should be well above 100PSI.