Pressure transducer code

Hi people,

I have a three wire 5v ebay pressure transducer rated to 1.2MPa (174psi) and am looking to verify that the code I have is correct. There seems to be a decent readout on the display, but I am unsure if this is the best way to program this sort of input.

The object is to have a readout in psi, I have this done by scaling an analog input as the transducer puts out a voltage based on it’s readings.

For now it displays ~17psi on the readout ambient. I’m unsure if this is because the transducer reads ambient pressure or if it can have a relative zero at ambient?

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

const int analogPin = A0;
float inputP1;
float outputP1;

void setup()
{
  lcd.begin(20, 4);
  lcd.clear();
}

void loop()
{
  inputP1 = analogRead(A0);
  outputP1 = ((float)inputP1/1024*175);
  // Divide by 1024 for arduino input - multiply by 175 as transducer reads 0 to 175psi
  
  lcd.setCursor(0,0);
  lcd.print("P1:");
  lcd.setCursor(4,0);
  lcd.print(outputP1);

  lcd.setCursor(0,1);
  lcd.print("A0:");
  lcd.setCursor(5,1);
  lcd.print(inputP1);
  
  delay (500);
}

Thanks in advance

I have a three wire 5v ebay pressure transducer rated to 1.2MPa (174psi) and am looking to verify that the code I have is correct.

Without a link to the transducer, we'd only be guessing. Personally, I'm not into guessing games.

Apologies, here's the link to the type I have:G1/4" inch 5V 0-1.2 MPa Pressure Transducer

(Useless) e-bay links don't count.

Did the link not work? Or is the information provided just useless?
That's about all the information I have on the sensor unfortunately.

Here is the specification from your link:

Working Voltage: 5VDC
Output Voltage: 0.5-4.5 VDC
Sensor material: Carbon steel alloy
Working Current: ≤10 mA
Working Pressure Range: 0-1.2 MPa
The Biggest Pressure: 2.4 MPa
Cable length: 19cm
Destroy Pressure: 3.0 MPa
Working TEMP. Range: 0-85℃
Storage Temperature Range: 0-100℃
Measuring Error: ±1.5 %FSO
Temperature Range Error: ±3.5 %FSO
Response Time: ≤2.0 ms
Cycle Life: 500,000 pcs
Application: non-corrosive gas liquid measurement

but where did you get the formula:

outputP1 = ((float)inputP1/1024*175);
  // Divide by 1024 for arduino input - multiply by 175 as transducer reads 0 to 175psi

Your formula appears to assume that the transducers delivers (linearly) between 0 and vcc for a pressure range 0 to 175 psi

I thought that's how they worked, but I guess that isn't the case? I'm not very familiar with sensors and programming.

I think in your case, if the sensor delivers 0.5 volts to 4.5 volts to represent 0 to 175 psi and if vcc = 5 volts, then outputP1 = ( inputP1 - 102 ) *175 / 818 (if my school day maths has not let me down too badly).

Seems to output a reasonable value now. (minus the noise from the cheap chinese sensor)

I am not sure however where the 818 comes from in the code. Perhaps my school math has let me down.

Well, it's better to calibrate a sensor than to assume, anyway.

aarg:
Well, it's better to calibrate a sensor than to assume, anyway.

I'm looking to have the sensor set up in a test rig once I get the code sorted out to see how accurate it really is. I have two of these and there's a variance of 2psi at ambient pressure already.

I mean calibrate in software.

These ratiometric sensors output 0.1 x Vcc upto 0.9 x Vcc for full scale. You can calculate
the value for a full-scale of F thus:

  int raw = analogRead (pin) ;
  float value = (raw  / 102.4 - 1) * F / 8 ;

I'm glad it seems to give a reasonable answer.
The problem is exactly like converting Fahrenheit to centigrade for water temperature.
The Fahrenheit scale goes from 32 to 212 and centigrade goes from 0 to 100 so the formula is C= (F-32) * (5/9)
The (5/9) comes from 100/(212 - 32).

In your case, the analog reading goes from 0 to 1023 for (in this case) a 5 volt supply. Your sensor delivers 0.5 volts for 0 PSI and 4.5 volts for 175 PSI according to the data sheet.
0.5 volts is an analog reading of 102 (rounded) for 0 PSI
4.5 volts is an analog reading of 921 (rounded) for 175 PSI

so the formula is Pressure (PSI) = ( Analog Reading - 102 ) * 175 / ( 921 - 102 )
which, allowing for rounding errors, is where my 818 came from.

921 - 102 = 818?

Your calculator needs new batteries.

PaulS:
921 - 102 = 818?

Your calculator needs new batteries.

I use it for calculating my pay. It always rounds in my favour.

6v6gt:
I use it for calculating my pay. It always rounds in my favour.

Base pay = 921.
Deductions = 102.
Resulting pay = 818.

That is rounding on your favor?

Yes. That is what I present for tax.

6v6gt:
Yes. That is what I present for tax.

Damned high tax bracket... 8)

hi wwiitteekk,

I have the same project using this transducer. Can you help me for the latest code in order to read and convert the sensor.

Thank you