MPX5100 Pressure Sensor Code Help Needed

Hello All!

I am using a MPX5100 pressure sensor to monitor flow pressure of a valve. I have the code I have found for another sensor and made it work with this sensor. I need to zero reading and the pressure reading to be stable(averaged) etc. so I get a good stable reading. I have tride programming from examples but no luck.

Can some one please help me?

Thanks,
Kevin

// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

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


int Battery;

void setup()
{
  // set up the LCD's number of columns and rows:
  lcd.begin(16,2);
}

void loop() 
{
  rawValue = analogRead(A0);
  pressure = (rawValue - offset)* 650.00 / (fullScale - offset); // pressure conversion
  Battery = analogRead(A1)/10.2;  // Display battery percentage at max 100%

  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0 , 0);
  
  
  if (Battery > 80)
  {
  lcd.print("BATTERY:");
  lcd.print(Battery);
  lcd.print("%     ");
  }
  else
  {
  lcd.print("*CHARGE BATTERY*");
  }
  
  lcd.setCursor(0 , 1);
  lcd.print("FLOW RATE:");
  lcd.print(pressure);
  lcd.print("   ");
  delay(1000);
  }

Sounds like a lot of fluctuation, can you post a wiring diagram? You can probably use a smoothing algorithm (there are many) to get more stable readings but do as much smoothing, filtering in hardware as you can first ( bypass caps, etc.). Also, what kind of environment is your project in?

lcd.print(pressure);

That prints a ~100 times higher number than the resolution of the A/D.
The decimal places are meaningless.

Try lcd.print(pressure, 0);

Leo…

WaWa,

That took care of the decimal place numbers, geat THANKS!

Now just need to figure what to do on making 0 and pressure reading more stable.

Kevin

I have attached the wiring diagram. I am also using 2 pumps with a miniature holding tank to stabilize the pulses from the pumps, which helped a lot but still getting some fluctuation in the readings.

Is zero also unstable when the sensor is removed from the air/valve? Leo..

Yes, bounces around 0, -1,-2, 1, 2

With pump running sometimes as much as 5 or so.

How did you supply the Arduino. Which Arduino. How long is the wiring between sensor and Arduino.

A 'real' picture could explain much more than a 'Fritzing'. Leo..

Try if reading the analogue inputs twice improves things. Change

rawValue = analogRead(A0);
pressure = (rawValue - offset)* 650.00 / (fullScale - offset); // pressure conversion
Battery = analogRead(A1)/10.2;  // Display battery percentage at max 100%

To

rawValue = analogRead(A0); // dummy read
rawValue = analogRead(A0);
pressure = (rawValue - offset)* 650.00 / (fullScale - offset); // pressure conversion
Battery = analogRead(A1); // dummy read
Battery = analogRead(A1)/10.2;  // Display battery percentage at max 100%

Arduino supply, computer and tried wall adapter

Arduino Uno

3" on the wiring

I have attached some pics

Updated my prior post.

I have noticed before anymore program modifications the circuit doesnt seem to be as responsive as a mechanical mmhg gauge from a blood pressure cuff.

Any ideas on this?

Tried the code you posted to replace mine. The dummy reads didn't seem to help. My battery read seem to be fine it is just the pressure sensor.

Hi,

I’ve done a lot of work on automotive fuel systems that included measuring the fuel pressure. I found you can only do so much with mathematical averaging. I obtained the best results when I added a low pass filter to the sensor’s output.

I would start by adding a simple R-C filter to the arduino input.

Perhaps like the attachment;

The resistors can be any film resistor, the capacitor needs to be a ceramic or film type.

if you tried an electrolytic it would filter the variations but leave a constant error when the input is no changing.

Resistor R1 is to protect the arduino on shutdown if the capacitor had significant charge remaining.

Good luck.

filter.jpg

Not sure the attachment you are referring to?

Sorry, the attachment didn't attach. I modified the original post to include the attachment.

I take it the RC network(low pass filter) is for eliminating noise?

I don't seem to have a noise preblem, it's these air pump motors pulsing causing the instabality. I need to average the reading or smooth buthavent been able to get some code to work.

If the low pass filter does more than remove noise please let me know!

Thanks, Kevin

A low-pass filter at the output of the sensor also removes pulses. How much depends on the corner frequency. Access to a scope would help. Leo..

Ok great! I have a scope and can look at it.

What would I change if I want to fine tune the filter?

KevinRoach:
What would I change if I want to fine tune the filter?

Value of the capacitor.

A higher value filters more, but also makes the sensor a bit slower to respond to real changes.

Maybe aim for a ripple <=5mV (one A/D count), measured on the cap.
Leo…

Thank you guys for the help, very much appreciated!

I will get out the scope and play with the capacitors.