All Sensors Pressure Sensor Problem

Hi Guys,

So I have this costume Pressure sensor that I have tried to program it a couple of times and I'm not reading the right values. See below for the coding. I only need to read the analog voltage and convert it to mmHg (units of air Pressure). Also I have attached the data sheet of the pressure sensor. Any help will be appreciated.
Thanks.

#define ADC_Sensor 2 // Arduino analog pin

const float Null = 0.50; // Null VDC; datasheet Page 32
const float Sensitivity = 13.33; // Sensitivity mV/psi; datasheet Page 32

void setup()
{
Serial.begin(9600);
}
void loop() //Beginig of the loop counter
{
Serial.print("P: ");
Serial.print(getPressure());
Serial.println("mmHg ");
delay(1000);
}

float getPressure(void)
{
float pressurePSI,pressuremmHg,pressureVDC;
int pressure;

pressure = analogRead(ADC_Sensor);
//pressureVDC = (float)pressure * 0.0048828125; // (5V/1024 (digital counts) = 0.0048828125) 1024 is the maximun voltage at 5V and 0 is the 0V.
//pressureVDC = pressureVDC - Null;
//pressurePSI = pressureVDC / Sensitivity * 1000;
//pressuremmHg = pressurePSI - 0.15;

return pressuremmHg;
}

SGILA-Engin15100910350.pdf (483 KB)

Try this.
Leo..

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

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

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

Hey Wawa:

I tried your code, it does not read the pressure more than 30 mmHg.
Thanks

I calculated those values according to the datasheet of the sensor.
Maybe your application does not produce more than 30mmHg.

If you have a DMM, you could measure the output voltage of the sensor.
30mmHg should be ~0.625volt, and 300mmHg should be ~4volt.
Leo..

Hey Leo,

Your are absolutely right, I tested it with my DMM, but why do I get 30 mmHg in the serial monitor ??

Hey Leo,

How did you come up with these numbers for the offset, Full Scale and the Pressure formula? could you explain a little, I'm kinda new to these stuff, any explanation will clarify a lot of things.

Thank you.

~0.625volt will display 30mmHg.
What do you want in the serial monitor. A fake value?

Change 300 into 3000, and you see 10x the value on the serial monitor.
One decimal place with 300mmHg is already pushing it over the limit, because you only have 768 values (819-51) to work with, and 300.0 is 3000 values.

If you want bar or psi or anything else, feel free to change that number "300" into anything you like.
Leo..

aghaderi2006:
How did you come up with these numbers for the offset, Full Scale and the Pressure formula? could you explain a little, I'm kinda new to these stuff, any explanation will clarify a lot of things.

If you look at the datasheet of the sensor, you see that the sensor outputs ~0.25volt at zero pressure.
And 4volt at max pressure of 300mmHg.
0.25volt on the analogue input is a digital value of 1024/5 * 0.25 = 51
4volt volt is 1024/5 *4 = 819
The rest is just maths.

You should at least calibrate the zero offset.
Change the offset value by +/-1, and re-upload untill you have 0mmHg in the serial monitor at zero pressure.
Leo..

This will get you a higher granularity (more values) if you just want to use the values to do something with.
Control LEDs, motors, etc.
Output is ~250-1023.
Use "map" to scale it to e.g. 0-256.
Leo..

int rawValue;

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

void loop() {
  rawValue = analogRead(A0);
  Serial.print(rawValue));
  delay(500);
}

Thanks Leo,

So I have a have a hand manometer connected directly to the pressure sensor. On the gauge I can read 300mmHg and when I measure the voltage of the pressure sensor, As you mentioned that "30mmHg should be ~0.625volt, and 300mmHg should be ~4volt." I read these exact values, However on the serial monitor I see 30mmHg when I pressurize the pressure sensor to 300mmHg. I understand your calculations but why the pressure sensor is showing the right voltage and the micro controller is reading 30 mmHg ? The hand Manometer is calibrated and the pressure sensor is new (I tried at least 3 pressure sensors) but no luck.

You're right.
300 had to be 300.0
Forgot "pressure" was a float.
Corrected the code.
Leo..

Hey LEO,

Thanks the Code works as a champ. Hey one quick question though, Is there any way that I could write a .TXT file or a scrip to be able to change the offset and the Fullscale numbers without uploading the hole code to the Arduino every single time. Something that I could change in the .TXT file and it will effect the offset and the Fullscale numbers in general without uploading the code.

Thanks,

Offset and fullScale are just variables.
They can be changed while the code is running with e.g. up/down buttons.

Don't know what you want to do with those values.
Maybe code could auto-zero on startup. And/or auto-gain to full scale.
Leo..