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?
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.
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.
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!