Need help with pressure transducer.

I am working on a project that involves me monitoring several pressures. I picked up 3 sensors on ebay, 2 that are 150 psi, and 1 500 psi. Trying to get the code to output correct is like pulling teeth at this point.

I can read the value, map it to the voltage range and when I compare the voltage output with my dmm they are the same, within a few mv. It's getting the voltage to map to the pressure range that I'm having trouble with.

Any help would be greatly appreciated.

The sensors.

http://www.ebay.com/itm/271763798948?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

http://www.ebay.com/itm/261248772710?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

My code:

void setup() {
  
  Serial.begin(9600)

void loop() {
  
  int airpressurevalue = analogRead(A0);
  int oilpressurevalue = analogRead(A1);
  int fuelpressurevalue = analogRead(A2);
  float airpressurevoltage = map(airpressurevalue,0,1023,0.5,4.5);
  float oilpressurevoltage = map(oilpressurevalue,0,1023,0.5,4.5);
  float fuelpressurevoltage = map(fuelpressurevalue,0,1023,0.5,4.5);
  float airpressurepsi = map(airpressurevoltage,0.5,4.5,0,150);
  float oilpressurepsi = map(oilpressurevoltage,0.5,4.5,0,150);
  float fuelpressurepsi = map(fuelpressurevoltage,0.5,4.5,0,500);
  
  Serial.print("Air Pressure ADC Value: ");
  Serial.println(airpressurevalue);
  Serial.println();
  Serial.print("Air Pressure Voltage: ");
  Serial.println(airpressurevoltage);
  Serial.println();
  Serial.print("Air Pressure PSI: ");
  Serial.println(airpressurepsi);
  Serial.println();
  
  Serial.print("Oil Pressure ADC Value: ");
  Serial.println(oilpressurevalue);
  Serial.println();
  Serial.print("Oil Pressure Voltage: ");
  Serial.println(oilpressurevoltage);
  Serial.println();
  Serial.print("Oil Pressure PSI: ");
  Serial.println(oilpressurepsi);
  Serial.println();
  
  Serial.print("Fuel Pressure ADC Value: ");
  Serial.println(fuelpressurevalue);
  Serial.println();
  Serial.print("Fuel Pressure Voltage: ");
  Serial.println(fuelpressurevoltage);
  Serial.println();
  Serial.print("Fuel Pressure PSI: ");
  Serial.println(fuelpressurepsi);
  Serial.println();
  
  delay(1000);
  
}

With a bit of thought, you do that with just one map statement. Instead of first converting to voltage, convert to PSI instead. According to the plot on the ebay page, the conversion is quite linear. Hint: if 5V = 1024, 4.5V = 922.

jremington:
With a bit of thought, you do that with just one map statement. Instead of first converting to voltage, convert to PSI instead. According to the plot on the ebay page, the conversion is quite linear. Hint: if 5V = 1024, 4.5V = 921.

I wanted to be able to verify what I was seeing on my fluke so that is why I did the map for the voltage.

I get what you are saying, I’ll redo my mapping since I do know it is getting what I expect as far as voltage.

For someone who learned VB in the '90s and never dealt with sensor input this is a little on the fun side. Not just the code but being able to do something that isn’t restricted to a pc.

Thanks.

Be careful when using map(). It can misbehave when the input value is outside the defined input range. You may need to use the constrain function as well.

Well thank you to all who replied. After having this project on hold for a few months I decided to play around with it today. Getting pretty annoyed with the mapping results I decided to see exactly how the mapping was done. Well to my surprise the map() function sucks.

void setup( void )
{
 Serial.begin( 9600 );
 
 long i;
 long m;
 
 for ( i=0; i <=1023; ++i )
 {
   m = map( i, 0, 1023, 0, 1 );
   Serial.print( i );
   Serial.print( "   " );
   Serial.println( m );
 }
}

void loop( void )
{
}

Netted the results of

0   0
1   0
2   0
3   0
4   0
5   0
6   0
7   0
8   0
9   0
10   0
11   0
12   0
13   0
14   0
15   0
16   0
17   0
18   0
19   0
20   0
21   0
22   0
23   0
24   0
25   0
26   0
27   0
28   0
29   0
30   0
31   0
32   0
33   0
34   0
35   0
36   0
37   0
38   0
39   0
40   0
41   0
42   0
43   0
44   0
45   0
46   0
47   0
48   0
49   0
50   0
51   0
52   0
53   0
54   0
55   0
56   0
57   0
58   0
59   0
60   0
61   0
62   0
63   0
64   0
65   0
66   0
67   0
68   0
69   0
70   0
71   0
72   0
73   0
74   0
75   0
76   0
77   0
78   0
79   0
...
512   0
...
914   0
915   0
916   0
917   0
...
1015   0
1016   0
1017   0
1018   0
1019   0
1020   0
1021   0
1022   0
1023   1

Maybe this example (for the 150psi sensor) will help.

Use pre-reads and smoothing for higher accuracy.
Leo…

int rawValue; // A/D readings
int offset = 51; // ~0.5volt zero pressure adjust (~30-72)
int fullScale = 819; // ~4.5volt max pressure (span) adjust (~798-840)
float pressure; // final pressure in psi

void setup() {
  Serial.begin(9600);
}

void loop() {
  rawValue = analogRead(A0);
  pressure = (rawValue - offset) * 150.0 / (fullScale - offset); // pressure conversion
  Serial.print("The pressure is  ");
  Serial.print(pressure, 1); // one decimal place
  Serial.println("  psi");
  delay(500);
}

Thanks,

I actually just got out the calculator and messing in excel made my tables of raw values, and voltages then figuring where it would start and stop based on raw values did my own math and then mapped it based on what I got and it came to a better output than what I was getting before. I was actually thinking about something very similar to what you posted.

Wawa:
Maybe this example (for the 150psi sensor) will help.

Use pre-reads and smoothing for higher accuracy.
Leo..

int rawValue; // A/D readings

int offset = 51; // ~0.5volt zero pressure adjust (~30-72)
int fullScale = 819; // ~4.5volt max pressure (span) adjust (~798-840)
float pressure; // final pressure in psi

void setup() {
  Serial.begin(9600);
}

void loop() {
  rawValue = analogRead(A0);
  pressure = (rawValue - offset) * 150 / (fullScale - offset); // pressure conversion
  Serial.print("The pressure is  ");
  Serial.print(pressure, 1); // one decimal place
  Serial.println("  psi");
  delay(500);
}

Just edited the post.
150 into 150.0
Please re-load.
Leo..

Just ran a test on this code and it's so much better. By having the actual matrix of the raw values and voltages then comparing what the map function gives to what I calculated made life much easier. I was trying to map based on voltages but didn't realize map didn't work that way. Once I wrapped my head around that I was able to sit down and figure out the start and end point and map it out based on raw values instead.

void setup() {
  Serial.begin(9600);
}

void loop() {
  int value150sensor = analogRead(A0);
  int value500sensor = analogRead(A1);

  float voltage150sensor = value150sensor * (5.0 / 1023.0); 
  float voltage500sensor = value500sensor * (5.0 / 1023.0);

  long pressure150sensor = map(value150sensor, 102, 919, 0, 150);
  long pressure500sensor = map(value500sensor, 102, 919, 0, 500);

  Serial.print("150 PSI Transducer ADC Value: ");
  Serial.println(value150sensor);
  Serial.print("500 PSI Transducer ADC Value: ");
  Serial.println(value500sensor);
  Serial.print("150 PSI Transducer Voltage: ");
  Serial.println(voltage150sensor);
  Serial.print("500 PSI Transducer Voltage: ");
  Serial.println(voltage500sensor);
  Serial.print("150 PSI Transducer PSI: ");
  Serial.println(pressure150sensor);
  Serial.print("500 PSI Transducer PSI: ");
  Serial.println(pressure500sensor);
  Serial.println(); 
  Serial.println();
  Serial.println();
  Serial.println();
  Serial.println();

  delay(2000);
}

All can be done with two lines of code.

float pressure150sensor = (analogRead(A0) - 102) * 150.0 / 817;
float pressure500sensor = (analogRead(A1) - 102) * 500.0 / 817;

Your code doesn't display overflow. (e.g. 152 or -3psi).
But you might not want that.
Leo..

I’m aware it could be done with considerably less code. I needed a way to verify values were what I was expecting, it will be truncated before final version is sent.

I added the code using math rather than map() and while it averages right along with the map I’m not sure if I’m going to use it.

As said, pre-read and averaging/smoothing increases accuracy.
I will post an example later.
Leo..

Wawa:
As said, pre-read and averaging/smoothing increases accuracy.
I will post an example later.
Leo…

From the code you posted to using the map() function the accuracy is about the same. In the application I’m using decimal point accuracy isn’t needed. I was just having trouble wrapping my head around mapping it.

sir, I’m using the same kind of sensor. can someone finally tell, which code suits better for measuring sensor pressure accurately

That type of sensor has a range of 10% of the supply voltage (0.5V for 5 volt supply) for zero pressure, and 90% (4.5V) for full scale pressure. Post a link to the sensor you have. What kind of pressure readout do you want?

nandhu123:
sir, I'm using the same kind of sensor. can someone finally tell, which code suits better for measuring sensor pressure accurately

You're responding to a necrothread, it's over four years old.

You'll have better chance of a response by opening your own thread, detailing your own specific issue.