Pressure sensor not changing the value

Hello all, I need some help if I just reading a voltage signal from a 1.2 MPa pressure sensor from a pin it will give a value in serial monitor. If I give pressure on the sensor the value is changing. Everything fine.

I am now adding some new code to transfer the voltage signal into a pressure value. This is the code:

#define SENSOR A0//the YELLOW pin of the Sensor is connected with A0 of Arduino/OPEN-SMART UNO R3

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

{
  int raw = analogRead(SENSOR);
  
  Serial.println("Pressure is");
  float pressure_MPa = (raw / 1024 - 0.1) / 0.75;  // voltage to pressure
  Serial.print(pressure_MPa);
  Serial.println(" MPa");
  
  delay(500);
}

after I uplaod the code 0.13 Mpa is shown, fine! Now when I am giving pressure on the sensor the value isn`t changing? Why is it like this? Is it just because I ony can see two decimal places? If yes how can I change the accurancy, to see more decimal places?

Thanks

Why not also print raw so you can see what values your formula is working with?

Steve

how can I change the accurancy, to see more decimal places?

The print method defaults to 2 decimal places when printing floats. There is an additional parameter that can be supplied to the print method to specify the number of decimal places.

Serial.print(pressure_MPa, 5);

Will print 5 decimal places.

Thanks for your quick responds. I now can see 5 decimal places. But even with that If i added pressure o the sensor nothing is changing? Why?

This one:

Just print the value of raw, should be near 102 with no pressure applied, report back with your result.

Hello, I am a rookie...so don`t know what that mean print the value of raw should be near 102?

From the ad:

Ausgangsspannung: 0.5-4.5V DC

The transducer outputs 0.5V with 0 pressure.

At the beginning of your loop function, you store the value of analogRead into a variable called raw.

The suggestion is that you use Serial.println to see what value it has, just as you do with printing pressure_MPa.

raw is between 103 and 102 what does that mean?

Looks like your sensor is OK, need to work on your math, so at 1.2 MPa raw should be about 921, your span of 0 to 1.2 Mpa would be 921 - 102 = 819.

float pressure = (analogRead(A0) - 102.0) / 819 * 1.2;
Serial.print(pressure);
Serial.println("  megaPascals");

Note: 1.2 mPa is about 5 times the pressure in a car tire so give up trying to blow in it.

raw is between 103 and 102 what does that mean?

The pressure transducer puts out 0.5V for 0MPa. The raw ADC value that you get for 0.5V is 102.

(1024.0/5.0) * 0.5 = 102.4. Assuming that Vcc is 5.0V and the Aref is default.

Hello all, thanks for your help!

I know that the sensor is working. But why is the pressure stated in the monitor not changing? Blowing the sensor should not go up to 1.2 Mpa taht is clear. But the pressure output should change a bit. But it does nothing!

  int raw = analogRead(SENSOR);
 
  Serial.println("Pressure is");
  float pressure_MPa = (raw / 1024 - 0.1) / 0.75;  // voltage to pressure
                        ^^^^^^^^^^
  Serial.print(pressure_MPa);
  Serial.println(" MPa");

You are using integer division by 1024, so you will always get zero.

MarkT:

  int raw = analogRead(SENSOR);

Serial.println("Pressure is");
  float pressure_MPa = (raw / 1024 - 0.1) / 0.75;  // voltage to pressure
                        ^^^^^^^^^^
  Serial.print(pressure_MPa);
  Serial.println(" MPa");




You are using integer division by 1024, so you will always get zero.

What should I do? That is the program I got from the website

What website?

ArneDunio:
raw is between 103 and 102 what does that mean?

So if raw never changes from that value then the calculated value for MPa won't change either. It sounds like it's working.

Steve

You are using integer division by 1024, so you will always get zero.

What should I do?

Don't use integer division. Change the divide to floating point, like this:

  float pressure_MPa = (raw / 1024.0 - 0.1) / 0.75;  // voltage to pressure

Or, declare raw to be a float, like this:

float raw=analogRead(SENSOR);
const byte sensorPin = A0;
float sensorRating = 1.2; // 1.2MPa sensor
int offset = 102; // zero pressure adjust
int fullScale = 922; // max pressure (span) adjust
float pressure; // final pressure

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

void loop() {
  pressure = (analogRead(sensorPin) - offset) * sensorRating / (fullScale - offset);
  
  Serial.print("Pressure: ");
  Serial.print(pressure, 3); // three decimal places
  Serial.println(" MPa");
  delay(500);
}

An average human can only blow ~0.01MPa, so you might have to find another way to pressurise the sensor.
Leo..

groundFungus:
What website?

You know, THE website. :roll_eyes: