Pressure Measurement

im a engineering student beginer with programing
I want to read the pressure sensor MPX53GP using arduino
with the following code

float psensor = analogRead(A0);

long time = 0;
int interval = 1000; 

void setup() {
  Serial.begin(9600);
  }
  
void loop() {
  float psensor = analogRead(0) ;
  float voltage = (psensor * (5.0 / 1023.0));
  float pressure = (100 * ((voltage)/(5.0 - voltage)));

  if(millis() > time + interval) {
    Serial.print("V: ");
    Serial.print(voltage,1); 
    Serial.print("  Press: ");
    Serial.println(pressure,1);  
    time = millis();
    
  }
}

but the value obtained when no pressure is always as shown below can not be 0

if the code is wrong or something is missing with the code

thanks for help :slight_smile:

testing sensor.jpg

im using INA125P for signal amplifier with this circuit

float pressure = (100 * ((voltage)/(5.0 - voltage)));

This line in your code looks bogus to me.

There are many things that "might" be wrong with your system. You need to take a systematic approach to identifying what works, and what doesn't work.

Is the sensor working ? Measure the voltage output of the amplifier, and change the pressure. Does the voltage change ?

Your variable "time", and any other variables used in calculations with millis( ), should be "unsigned long".

And the first line of your program is invalid. You cannot call the analogRead( ) function outside of any function in your program.

Do you want psensor to be a global variable, or defined locally for each iteration of loop( ) ? Make up your mind.

Calling analogRead(A0) in one place, and analogRead(0) in another place, might work. Or it might not...

According to your output, you are getting 2.3 volts.

This might be correct. Look at the datasheet for your amplifier device. It might be designed to output a voltage level which is half of the power supply voltage ( half of 5V would be 2.5 volts ).

sensor work as well, if i apply pressure then the output voltage change.

so this code

float pressure = (100 * ((voltage)/(5.0 - voltage)));

that might be not used, i want read this sensure to kPA , i think thats code for change voltage value to pressure value (kPA)
.
still newbie with coding :frowning:

thanks for ur help :slight_smile:

testing sensor2.jpg

Well the voltage is supposed to be a linear function of the pressure, over the working range. That doesn't look even slightly like a linear function to me.

The device datasheet shows the relation of voltage to pressure. The voltage output of this device is quite high, compared to a strain gauge. The amplifier gain does not need to be very large.

Your circuit is probably designed to create an analog voltage output V, where

V = V0 + gk(P-P0)

where V0 is the output voltage when there is no differential pressure ( probably 2.5 volts ), g is the gain of the amplifier, k is the response gain of the transducer, and P0 is the atmospheric pressure.

The pressure relative to the atmospheric pressure is going to be

(P-P0) = (1/gk)(V-V0)

which doesn't look like your formula, at all

thanks for ur help sir :slight_smile:

.

so i must change my formula with Voltage output V and Atsmospheric pressure code ?

I think your problem might be in this line:

  float psensor = analogRead(0) ;

Perhaps the 0 should be A0. If I read your schematic correctly, that is.

aah okeoke sir
i'm trying change that code

thanks sir :slight_smile: