Digital Pressure Guage Programming Help Needed

Hello All!

I am fairly new to Arduino! I am working on making a pressure meter that would be similar to measuring blood pressure, but just need to read the pressure in mmhg. I am using a MPX5100 pressure sensor and the Arduino Uno. I have tried this code from a post on here. I am using a air pump like is used for a fish tank, small with a 370 motor(can find them everywhere on ebay).I am providing back pressure using a little adjustable valve. The issue I have is keeping a solid zero with no pressure and a good solid pressure reading without it jumping around a little. I guess I would need maybe some averaging code, not sure really what I need!

I would also like to get rid of the decimal point and stay with just whole numbers.

Here is the code, any help with the code would be greatly appreciated!

Code originally from WAWA here on the forum. This was for a different pressure sensor.

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);
}

MPX5100.pdf (412 KB)

Air Pump.jpg

I've used something like this - a running everage invoked every time you take a reading:

float ave4,ave5, altitude;
const int aveLen = 50;

    ave4 +=  altitude  ;
    ave4 *= (1-1/aveLen1);
    ave5 = ave4/(aveLen1-1);

As you can guess this was for an altimeter, using a BME280.

aveLen gives the number of samples over which to average.

Allan

Allan has pointed you in the right direction for averaging your analog value. As this project evolves, you'll probably discover that averaging samples taken two times a second isn't going to give you what you need to create a responsive control system. When that happens, consider digital filtering.

There is a simple DSP library here: Arduino Playground - Filters

Run the example program to get a better understanding of what it does. If you're headed towards any kind of heart rate or blood pressure device, you really need to be headed in the direction of digital filters.

You don't need a background in Calculus to use it although it does help in understanding the methods. While I'm not keen on the libraries use of floats (especially for time values), it's a good starting point for understanding how simple DSP works. Don't be afraid to ask questions, that's what the forum is all about.

As the original post mentioned that I wasn't wanting to do this for blood pressure, just for monitoring pressure.

I need help with setting up the pressure sensor correctly in the code to be correct for that sensor in mmhg, getting it to keep a zero when no pressure and getting a good stabile reading when reading some pressure.

Also get rid of the decimal on the reading, just want whole numbers.

The air pump will always keep your signal jumping a bit. That's because of how those pumps work.

KevinRoach:
Also get rid of the decimal on the reading, just want whole numbers.

Cast to int type. If you want to keep some precision, do the number x10 or x100 before casting to int.

Not sure what you mean. Can you show me an example?

The air pumps I am using for the application require two for the pressure I need and what I have done is put the two together and made a small air tank for them. this makes it pretty stable but still want it a little better.

How about the code is ok for the MPX5100 pressure senor?

Those air pumps look awfully familiar... I have a box full of them. They're cheap and they're crap, they tend to stop running within months if not weeks. Shaking them will get the motor running again, though. No matter, they're crap, get proper air pumps for anything that has to last longer than an afternoon of tinkering.

KevinRoach:

For getting float to int, more here.

Then your air pump problem: the most stable values you get by adding a one-way valve between air pump and pressure sensor. Then you can stop the air pump, do your pressure reading (without the pump noise - the one-way valve prevents air from flowing back), and start the pump again. Doing so now and then should also help keeping those pumps actually pumping (the power kick usually gets them running again). Whether that works for you of course depends on what happens to your compressed air.

Ok I will look at the info you posted, Thanks!

Any suggestions on better pumps?

I'm using the A400, a small 12V pump (takes DC but there's a small PCB in the wire that converts it to AC, interestingly - also available for other power inputs). You can find them on Taobao, Aliexpress or manufacturer's site www.qdahead.com. A few of them have been pumping air in my hydroponics systems for over half a year now, which is how long I have them. No issues so far.

I looked over all the information given and tried some code but doesn't seem to be working for me. I cant get the averaging code to work.

As far as what I am doing is just getting a pressure reading like flow through a adjustable valve. So i have to leave the pumps run all the time.

Hi,
What are you pumping the air into?
Where are you measuring the pressure?

Can you post a picture of your project and/or a diagram of your air flow through the pump and out to the pressure sensor and vessel.

If you are trying to get the pressure of flowing air, then you have to consider the physical arrangement of pressure sensor and "pipe".

Thanks.. Tom.. :slight_smile:

Ok i have added a pic of the setup! My issue is the pumps being the kind they are, but I don't know if I can get a small different kind that can provide constant flow of air.

I can put air into the sensor with a small syringe and then clamp it to hold the pressure and it is stable, so I now know it is not the setup, noise etc.

Hi,
Do you have room for a separate larger storage cylinder to have the pressure sensor measure.
Because you are measuring from the pipe, you are measuring pressure like a pitot tube.

This is effectively measure flow and pressure.

Pump impulses will be a problem, a separate storage cylinder will help.

You may try measuring at your tank on the pumps, but not from the outlet pipe.

Tom... :slight_smile:

To let e everyone know that made suggestions, I have come up with a good setup with every shown in the past posts by adding a low pass filter on the pressure sensor.