MPX4250AP Problem with the readings

Hello, I’m a newbie in eletronics and Arduino but I’ll need to read pressure values for a project, and I’m having a hard time getting decent readings.

I’m using a (brand new) Arduino Nano and a MPX4250 Absolute Pressure sensor, and here is the simple circuit I’m working with.

From the sensor’s datasheet, I got this formula:
Nominal transfer value: VOUT = VCC x (P × 0.004 – 0.04) ± (Pressure error × Temp. Factor × 0.004 x VCC)
Without taking into account the Pressure error, I got to this code:

 float ap_kPa=0;
  int sensorValue=0;

void setup() {
  // put your setup code here, to run once:
  pinMode(A0, INPUT);
  Serial.begin(9600);
  
  
}

void loop() {
  // put your main code here, to run repeatedly:
  sensorValue = analogRead(A0); 
  ap_kPa = 250 * sensorValue / 1023.0 + 10;
  Serial.println(ap_kPa);
  ap_kPa = 0;
  sensorValue = 0;                          
  delay(1000);
}

and with this, I got these readings:

17:35:30.872 -> 36.60
17:35:31.872 -> 36.60
17:35:32.872 -> 34.16
17:35:33.872 -> 32.45
17:35:34.872 -> 30.74
17:35:35.872 -> 28.54
17:35:36.872 -> 24.87
17:35:37.866 -> 23.41
17:35:38.866 -> 21.70
17:35:39.867 -> 18.27
17:35:40.867 -> 14.61
17:35:41.867 -> 9.48
17:35:42.867 -> 5.08
17:35:43.867 -> 2.88
17:35:44.867 -> -2.01
17:35:45.867 -> -7.39
17:35:46.867 -> -12.03
17:35:47.867 -> -16.43
17:35:48.867 -> -21.80
17:35:49.867 -> 38.10
17:35:50.867 -> 32.73
17:35:51.867 -> 27.84
17:35:52.908 -> 21.24
17:35:53.867 -> 14.89
17:35:54.867 -> 12.44
17:35:55.867 -> 10.24
17:35:56.867 -> 10.00
17:35:57.908 -> 10.00
17:35:58.867 -> 10.00
17:35:59.908 -> 10.00
17:36:00.908 -> 10.00
17:36:01.868 -> 10.00
17:36:02.908 -> 10.00
17:36:03.868 -> 10.00
17:36:04.908 -> 10.00
17:36:05.908 -> 10.00
17:36:06.908 -> 11.47
17:36:07.908 -> 15.13
17:36:08.908 -> 19.53
17:36:09.908 -> 22.22
17:36:10.908 -> 25.88
17:36:11.908 -> 28.82
17:36:12.908 -> 34.93
17:36:13.908 -> 41.04
17:36:14.908 -> -16.67

I was using an Arduino Uno before, but the values were as random as these ones.
Sometimes I get a few values = 10.00, but it changes really quickly into much higher or lower ones.

I cannot understand this, why am I getting such random numbers? Are the values in KPa too low for room pressure fluctuation?

Thanks in advance

Always start really simple.
Just read the sensor, and print the A/D values. See if they fluctuate.
If they do, then it could be the wiring/breadboard.

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

void loop() {
  Serial.println(analogRead(A0));
  delay(500);
}
 ap_kPa = 0;
  sensorValue = 0;

Why?

OP's image.


You MUST power ratiometric sensors like this from the 5volt pin of the Arduino.
If you use a different supply for the sensor then you loose the ratiometric relationship,
resulting in instability.
Leo..

Thanks for the reply Leo. Sadly, I can only try this on monday when I get back to my work place.

  ap_kPa = 0;
  sensorValue = 0;

I've coded this a month ago, was using an old sensor that was laying around in my work place and I had the same problem. Then I ordered a new one, thinking it might be the sensor's fault. So, I'm not sure why, but I think I was getting some kind of error and that was my fix. Like I said, I am a newbie, and my coding skills are a bit rusty atm.

A more logical way (to me) to calculate pressure.
Leo..

int offset = 42; // to calibrate zero pressure
float span = 0.2601; // to calibrate max pressure
float ap_kPa;

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

void loop() {
  ap_kPa = ((analogRead(A0) - offset) * span);
  Serial.print("Pressure is: ");
  Serial.print(ap_kPa, 1); // one decimal place is all you get
  Serial.println(" kPa");
  delay(500);
}

Hi again.
I powered the sensor with the 5v pin like you said and got these readings:

16:08:26.494 -> 30.42
16:08:27.494 -> -15.31
16:08:28.494 -> 39.95
16:08:29.494 -> 37.02
16:08:30.494 -> 34.58
16:08:31.494 -> 33.60
16:08:32.494 -> 35.80
16:08:33.494 -> 38.73
16:08:34.494 -> 41.17
16:08:35.494 -> -18.73
16:08:36.494 -> -10.91
16:08:37.494 -> 3.75
16:08:38.534 -> 3.75
16:08:39.494 -> 3.75
16:08:40.534 -> 3.75
16:08:41.494 -> 3.75
16:08:42.534 -> 3.75
16:08:43.494 -> 3.75
16:08:44.534 -> 3.75
16:08:45.534 -> 3.75
16:08:46.494 -> 3.75
16:08:47.534 -> 3.75
16:08:48.494 -> -2.36
16:08:49.534 -> -11.65
16:08:50.494 -> -19.71
16:08:51.534 -> 37.75
16:08:52.534 -> 35.55
16:08:53.534 -> 34.33
16:08:54.534 -> 33.84
16:08:55.534 -> 34.33
16:08:56.534 -> 36.04
16:08:57.534 -> 38.49
16:08:58.534 -> 40.44
16:08:59.534 -> -20.69
16:09:00.534 -> -16.04
16:09:01.536 -> -5.05
16:09:02.536 -> 3.75
16:09:03.536 -> 3.75
16:09:04.536 -> 3.75
16:09:05.536 -> 3.75
16:09:06.536 -> 3.75

Wawa:
A more logical way (to me) to calculate pressure.

Then I changed the code for the one you used, and got these ones:

16:18:45.776 -> Pressure is: 255.2 kPa
16:18:46.256 -> Pressure is: 255.2 kPa
16:18:46.771 -> Pressure is: 255.2 kPa
16:18:47.291 -> Pressure is: 255.2 kPa
16:18:47.771 -> Pressure is: 254.9 kPa
16:18:48.291 -> Pressure is: 250.0 kPa
16:18:48.771 -> Pressure is: 242.7 kPa
16:18:49.291 -> Pressure is: 234.6 kPa
16:18:49.771 -> Pressure is: 226.5 kPa
16:18:50.291 -> Pressure is: 218.5 kPa
16:18:50.771 -> Pressure is: 213.5 kPa
16:18:51.291 -> Pressure is: 213.3 kPa
16:18:51.771 -> Pressure is: 213.5 kPa
16:18:52.291 -> Pressure is: 214.1 kPa
16:18:52.771 -> Pressure is: 214.6 kPa
16:18:53.291 -> Pressure is: 216.9 kPa
16:18:53.771 -> Pressure is: 219.8 kPa
16:18:54.291 -> Pressure is: 222.9 kPa
16:18:54.764 -> Pressure is: 224.7 kPa
16:18:55.278 -> Pressure is: 227.3 kPa
16:18:55.798 -> Pressure is: 231.0 kPa
16:18:56.278 -> Pressure is: 235.7 kPa
16:18:56.798 -> Pressure is: 241.9 kPa
16:18:57.278 -> Pressure is: 253.1 kPa
16:18:57.798 -> Pressure is: 255.2 kPa
16:18:58.278 -> Pressure is: 255.2 kPa
16:18:58.798 -> Pressure is: 255.2 kPa
16:18:59.278 -> Pressure is: 255.2 kPa
16:18:59.798 -> Pressure is: 255.2 kPa
16:19:00.318 -> Pressure is: 255.2 kPa
16:19:00.798 -> Pressure is: 255.2 kPa
16:19:01.278 -> Pressure is: 255.2 kPa
16:19:01.798 -> Pressure is: 255.2 kPa
16:19:02.318 -> Pressure is: 255.2 kPa
16:19:02.798 -> Pressure is: 255.2 kPa
16:19:03.278 -> Pressure is: 255.2 kPa
16:19:03.798 -> Pressure is: 255.2 kPa
16:19:04.278 -> Pressure is: 255.2 kPa
16:19:04.798 -> Pressure is: 255.2 kPa
16:19:05.318 -> Pressure is: 255.2 kPa
16:19:05.798 -> Pressure is: 255.2 kPa
16:19:06.278 -> Pressure is: 251.5 kPa
16:19:06.798 -> Pressure is: 247.9 kPa
16:19:07.318 -> Pressure is: 242.2 kPa
16:19:07.798 -> Pressure is: 235.1 kPa
16:19:08.278 -> Pressure is: 228.6 kPa
16:19:08.798 -> Pressure is: 222.6 kPa
16:19:09.318 -> Pressure is: 216.1 kPa
16:19:09.798 -> Pressure is: 213.3 kPa
16:19:10.318 -> Pressure is: 213.3 kPa
16:19:10.798 -> Pressure is: 213.5 kPa
16:19:11.318 -> Pressure is: 214.1 kPa
16:19:11.798 -> Pressure is: 214.3 kPa
16:19:12.318 -> Pressure is: 215.1 kPa
16:19:12.798 -> Pressure is: 216.7 kPa
16:19:13.318 -> Pressure is: 219.3 kPa
16:19:13.798 -> Pressure is: 221.9 kPa
16:19:14.318 -> Pressure is: 223.4 kPa
16:19:14.798 -> Pressure is: 225.2 kPa
16:19:15.318 -> Pressure is: 227.1 kPa
16:19:15.798 -> Pressure is: 230.2 kPa
16:19:16.318 -> Pressure is: 233.8 kPa
16:19:16.838 -> Pressure is: 239.3 kPa
16:19:17.318 -> Pressure is: 248.7 kPa
16:19:17.798 -> Pressure is: 255.2 kPa
16:19:18.318 -> Pressure is: 255.2 kPa
16:19:18.838 -> Pressure is: 255.2 kPa
16:19:19.318 -> Pressure is: 255.2 kPa
16:19:19.838 -> Pressure is: 255.2 kPa

These values also don't make sense, because the max pressure read by the sensor is 250kPa. Atmospheric pressure is 101kPa.

I don't understand this:

int offset = 42; // to calibrate zero pressure
float span = 0.2601; // to calibrate max pressure

42 to calibrate zero? What does this mean? Why do I have to calibrate zero? I want to get the absolute pressure value.

And what is the span aswell?

Edit: Shouldn't the span be 250/1023 = 0.2444, and the offset 10/0.2444 = 40.92? (and we should add the offset instead of subtracting?) These are similar values to the ones I used. Why did you use these?

Thanks in advance

Wawa:
Always start really simple.
Just read the sensor, and print the A/D values. See if they fluctuate.

 16:58:01.132 -> 946
16:58:01.652 -> 1023
16:58:02.132 -> 1023
16:58:02.652 -> 1023
16:58:03.132 -> 1019
16:58:03.652 -> 1004
16:58:04.132 -> 980
16:58:04.652 -> 959
16:58:05.132 -> 939
16:58:05.652 -> 921
16:58:06.172 -> 905
16:58:06.652 -> 889
16:58:07.132 -> 880
16:58:07.652 -> 876
16:58:08.172 -> 876
16:58:08.652 -> 875
16:58:09.132 -> 872
16:58:09.652 -> 874
16:58:10.172 -> 876
16:58:10.652 -> 877
16:58:11.172 -> 882
16:58:11.652 -> 888
16:58:12.172 -> 896
16:58:12.652 -> 902
16:58:13.172 -> 908
16:58:13.652 -> 912
16:58:14.132 -> 918
16:58:14.652 -> 925
16:58:15.172 -> 933
16:58:15.652 -> 939
16:58:16.132 -> 949
16:58:16.652 -> 961
16:58:17.172 -> 972
16:58:17.652 -> 994
16:58:18.172 -> 1016
16:58:18.652 -> 1023
16:58:19.172 -> 1023
16:58:19.652 -> 1023
16:58:20.173 -> 1023
16:58:20.653 -> 1023
16:58:21.173 -> 1023
16:58:21.653 -> 1023
16:58:22.173 -> 1023
16:58:22.653 -> 1023
16:58:23.173 -> 1023
16:58:23.653 -> 1023
16:58:24.173 -> 1023
16:58:24.653 -> 1023
16:58:25.173 -> 1023
16:58:25.653 -> 1023
16:58:26.173 -> 1023
16:58:26.693 -> 1023
16:58:27.173 -> 1023
16:58:27.653 -> 1023
16:58:28.173 -> 1023
16:58:28.693 -> 1023
16:58:29.173 -> 1023
16:58:29.653 -> 1023
16:58:30.173 -> 1023
16:58:30.653 -> 1023
16:58:31.173 -> 1023
16:58:31.695 -> 1023
16:58:32.175 -> 1023
16:58:32.655 -> 1023
16:58:33.175 -> 1023
16:58:33.695 -> 1019
16:58:34.175 -> 1013
16:58:34.655 -> 1004
16:58:35.175 -> 991
16:58:35.695 -> 981
16:58:36.175 -> 972
16:58:36.655 -> 963
16:58:37.175 -> 954
16:58:37.695 -> 946
16:58:38.175 -> 937
16:58:38.695 -> 930
16:58:39.175 -> 922
16:58:39.695 -> 914
16:58:40.175 -> 904
16:58:40.695 -> 895
16:58:41.175 -> 887
16:58:41.695 -> 880
16:58:42.175 -> 877
16:58:42.695 -> 876
16:58:43.175 -> 875
16:58:43.695 -> 873
16:58:44.175 -> 874
16:58:44.695 -> 875
16:58:45.175 -> 875
16:58:45.695 -> 874
16:58:46.175 -> 873
16:58:46.695 -> 873
16:58:47.175 -> 875
16:58:47.695 -> 877
16:58:48.175 -> 879
16:58:48.695 -> 883
16:58:49.175 -> 887
16:58:49.695 -> 893
16:58:50.175 -> 897
16:58:50.695 -> 901
16:58:51.175 -> 906
16:58:51.695 -> 911
16:58:52.175 -> 913
16:58:52.695 -> 916
16:58:53.175 -> 921
16:58:53.695 -> 926
16:58:54.215 -> 933
16:58:54.695 -> 940
16:58:55.175 -> 947
16:58:55.695 -> 957
16:58:56.215 -> 968
16:58:56.695 -> 986
16:58:57.175 -> 1010
16:58:57.695 -> 1023
16:58:58.215 -> 1023
16:58:58.695 -> 1023
16:58:59.175 -> 1023
16:58:59.695 -> 1023
16:59:00.215 -> 1023
16:59:00.695 -> 1023
16:59:01.215 -> 1023

Edit: btw, I changed the pinMode of A0 to input, on setup. I assumed you forgot to type it.

I changed the wiring just for a more intuitive coloring, and my values changed drastically.
I don't understand what's happening.

These are now the readings of the analogic values on pin A0:

17:24:38.357 -> 154
17:24:38.837 -> 0
17:24:39.357 -> 0
17:24:39.837 -> 0
17:24:40.357 -> 0
17:24:40.837 -> 0
17:24:41.357 -> 0
17:24:41.837 -> 0
17:24:42.357 -> 2
17:24:42.838 -> 7
17:24:43.358 -> 15
17:24:43.838 -> 24
17:24:44.359 -> 33
17:24:44.839 -> 41
17:24:45.359 -> 48
17:24:45.839 -> 55
17:24:46.359 -> 62
17:24:46.840 -> 69
17:24:47.360 -> 74
17:24:47.840 -> 79
17:24:48.360 -> 81
17:24:48.840 -> 85
17:24:49.360 -> 86
17:24:49.840 -> 88
17:24:50.360 -> 91
17:24:50.840 -> 91
17:24:51.360 -> 92
17:24:51.880 -> 95
17:24:52.360 -> 95
17:24:52.840 -> 95
17:24:53.360 -> 94
17:24:53.880 -> 94
17:24:54.360 -> 94
17:24:54.840 -> 95
17:24:55.360 -> 93
17:24:55.840 -> 93
17:24:56.360 -> 92
17:24:56.840 -> 92
17:24:57.360 -> 92
17:24:57.840 -> 91
17:24:58.360 -> 90
17:24:58.880 -> 89
17:24:59.360 -> 87
17:24:59.840 -> 86
17:25:00.360 -> 82
17:25:00.880 -> 78
17:25:01.360 -> 73
17:25:01.840 -> 67
17:25:02.360 -> 58
17:25:02.880 -> 49
17:25:03.360 -> 40
17:25:03.840 -> 29
17:25:04.360 -> 16
17:25:04.880 -> 2
17:25:05.360 -> 0
17:25:05.880 -> 0
17:25:06.360 -> 0
17:25:06.880 -> 0
17:25:07.360 -> 0
17:25:07.880 -> 0
17:25:08.360 -> 0
17:25:08.880 -> 0
17:25:09.360 -> 0
17:25:09.880 -> 0
17:25:10.360 -> 0
17:25:10.880 -> 0
17:25:11.360 -> 0
17:25:11.880 -> 0
17:25:12.360 -> 0
17:25:12.880 -> 0
17:25:13.360 -> 0
17:25:13.880 -> 0
17:25:14.360 -> 0
17:25:14.880 -> 0
17:25:15.360 -> 0
17:25:15.880 -> 0
17:25:16.360 -> 0
17:25:16.880 -> 0
17:25:17.360 -> 0
17:25:17.880 -> 0
17:25:18.360 -> 0
17:25:18.880 -> 0
17:25:19.360 -> 0
17:25:19.880 -> 0
17:25:20.362 -> 0
17:25:20.882 -> 0
17:25:21.362 -> 0
17:25:21.882 -> 0
17:25:22.362 -> 0
17:25:22.882 -> 0
17:25:23.402 -> 0
17:25:23.882 -> 0
17:25:24.362 -> 3
17:25:24.882 -> 7
17:25:25.402 -> 14
17:25:25.882 -> 23
17:25:26.362 -> 32
17:25:26.882 -> 41
17:25:27.402 -> 48
17:25:27.882 -> 57
17:25:28.362 -> 64
17:25:28.882 -> 72
17:25:29.362 -> 77
17:25:29.882 -> 83
17:25:30.402 -> 85
17:25:30.882 -> 89
17:25:31.362 -> 90
17:25:31.883 -> 93
17:25:32.403 -> 94
17:25:32.883 -> 95
17:25:33.363 -> 95
17:25:33.883 -> 95
17:25:34.403 -> 95
17:25:34.883 -> 95
17:25:35.363 -> 95
17:25:35.883 -> 92
17:25:36.403 -> 94
17:25:36.883 -> 94
17:25:37.403 -> 94
17:25:37.883 -> 90
17:25:38.403 -> 86
17:25:38.883 -> 85
17:25:39.403 -> 83
17:25:39.883 -> 78
17:25:40.403 -> 73
17:25:40.883 -> 69
17:25:41.403 -> 62
17:25:41.883 -> 54
17:25:42.403 -> 46
17:25:42.883 -> 38
17:25:43.403 -> 28
17:25:43.883 -> 16
17:25:44.403 -> 3
17:25:44.883 -> 0
17:25:45.403 -> 0
17:25:45.883 -> 0
17:25:46.403 -> 0
17:25:46.883 -> 0
17:25:47.403 -> 0
17:25:47.883 -> 0
17:25:48.403 -> 0
17:25:48.883 -> 0

Anyways, the 0 value doesn't make sense. It would mean that the pressure is 0, and that is impossible, since it's an absolute pressure sensor.

Also if I replace the sensor with older one:

17:27:24.127 -> 134
17:27:24.607 -> 0
17:27:25.087 -> 0
17:27:25.607 -> 0
17:27:26.127 -> 0
17:27:26.607 -> 0
17:27:27.086 -> 0
17:27:27.607 -> 0
17:27:28.127 -> 0
17:27:28.607 -> 0
17:27:29.127 -> 0
17:27:29.607 -> 0
17:27:30.127 -> 0
17:27:30.607 -> 0
17:27:31.127 -> 0
17:27:31.607 -> 0
17:27:32.127 -> 0
17:27:32.607 -> 3
17:27:33.127 -> 12
17:27:33.607 -> 23
17:27:34.127 -> 33
17:27:34.606 -> 40
17:27:35.126 -> 48
17:27:35.606 -> 56
17:27:36.126 -> 64
17:27:36.606 -> 71
17:27:37.127 -> 76
17:27:37.607 -> 81
17:27:38.126 -> 83
17:27:38.606 -> 85
17:27:39.126 -> 87
17:27:39.606 -> 89
17:27:40.126 -> 90
17:27:40.606 -> 93
17:27:41.126 -> 93
17:27:41.606 -> 92
17:27:42.126 -> 93
17:27:42.606 -> 91
17:27:43.126 -> 90
17:27:43.607 -> 90
17:27:44.127 -> 89
17:27:44.607 -> 88
17:27:45.127 -> 85
17:27:45.607 -> 82
17:27:46.127 -> 79
17:27:46.648 -> 74
17:27:47.128 -> 66
17:27:47.608 -> 55
17:27:48.128 -> 41
17:27:48.648 -> 25
17:27:49.128 -> 6
17:27:49.608 -> 0
17:27:50.128 -> 0
17:27:50.648 -> 0
17:27:51.128 -> 0
17:27:51.648 -> 0
17:27:52.128 -> 0
17:27:52.648 -> 0
17:27:53.128 -> 0
17:27:53.648 -> 0
17:27:54.128 -> 0
17:27:54.608 -> 0
17:27:55.128 -> 0
17:27:55.648 -> 0
17:27:56.128 -> 0
17:27:56.608 -> 0
17:27:57.128 -> 0
17:27:57.648 -> 0
17:27:58.128 -> 0
17:27:58.608 -> 0
17:27:59.128 -> 0
17:27:59.648 -> 0
17:28:00.128 -> 7
17:28:00.648 -> 20
17:28:01.128 -> 33
17:28:01.648 -> 45
17:28:02.128 -> 56
17:28:02.658 -> 67
17:28:03.128 -> 75
17:28:03.648 -> 78
17:28:04.128 -> 83
17:28:04.648 -> 86
17:28:05.128 -> 88
17:28:05.648 -> 91
17:28:06.128 -> 91
17:28:06.648 -> 90
17:28:07.128 -> 89

Same range of values.

This is how the circuit looks like.

Values should be stable.
If you don't have any tubes (pressure) connected, then those fluctuating values could mean a bad wire and/or breadboard.
Leo..