Pressure logger from arduino

I'm trying to build a pressure data logger using an Arduino and Mindman MP47P-03-F1 (https://www.mindman.com.tw/proimages/pdf/E_MP47_S.pdf) pressure sensor, the sensor is connected to an outer 12-24 VDC power source. I've connected the analog wire to the the Arduino's A0 and connected the DC- (blue wire) of the sensor and the DC- of the power supply to the GND on the board. i get a voltage reading even when the pressure is 0 and the reading is unstable so the pressure i get is fluctuating and noisy. Any suggestions on how to fix this?
This is the code:

const int analogPin = A0; 
const float slope = 0.25;
const float intercept = -0.25;
const unsigned long startTime = millis();

void setup() {
  Serial.begin(9600);
  Serial.println("Time (s)\t\tPressure (MPa)");
}

void loop() {
  unsigned long elapsedTime = millis() - startTime;
  int sensorValue = analogRead(analogPin);
  float voltage = sensorValue * (5.0 / 1023.0);  
  float pressure = slope * (voltage - intercept);

  Serial.println(sensorValue);
  Serial.print(elapsedTime / 1000.0);
  Serial.print("\t\t");
  Serial.println(pressure);

  delay(1000); 
}

Thanks

The analog output will be between 0.6V and 5V, it doesn't start at 0V

1 Like

An unstable voltage reading is usually indicates a "floating" input, or loose connection. Did you solder the connections to the sensor? Did you connect the sensor GND and Arduino GND?

Please post a close up, focused photo showing the board and all the connections.

Yes - that is doing exactly what it says on the tin:

How much is it fluctuating?
With analogue, a certain amount of fluctuation is to be expected.

Do you have (access to) an oscilloscope to see how clean/steady the signal actually is?

And also important is: How often do you see fluctuations? Are they repetitive?

1 Like

unfortunately, i dont have a scope. from the voltage reading i get from the arduino, it fluctuates around 1V with +-0.2V. this fluctuation is translated into ~1kPa of pressure.

the fluctuations are random, i dont see any pattern of repetition.
do i also need to normalize the pressure so that 1V is 0 MPa?

Which Arduino, and how is it powered.
A picture of the setup might also help.
Leo..

1 Like

Hi,
If you replace the pressure sensor with a potentiometer, do you still get the fluctuations.

How long is the lead from sensor to controller?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

1 Like


the arduino is powered by it's own power supply. the sensor is powered by a 12-24V power supply.

With all that spider wiring, it's not that surprising that you pick up noise.

So try averaging.

Some noise is inherent in analogue measurements ...

You have the power supply negative routed through through the Arduino ground (GND).
Don't do that!
Connect the power supply white wire directly to the MP47 blue wire

I see two power supplies connected to the Uno.
USB, and an unspecified supply connected to the DC socket.
I hope that supply is between 7 and 12volt.

Don't code from A/D value to voltage to pressure.
Go directly from A/D value to pressure.
Leo..

const int sensorPin = A0;
const int offset = 123; // zero pressure adjust
const int fullScale = 1023; // max pressure adjust
float sensorType = 1000.0; // kPa
float pressure; // final pressure

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

void loop() {
  pressure = (analogRead(sensorPin) - offset) * sensorType / (fullScale - offset);

  Serial.print("Pressure: ");
  Serial.print(pressure, 0);
  Serial.println(" kPa");
  delay(1000);
}

thanks for the code Wawa, but why did you use the offset as 123? it doesn't zero the pressure. i changed it to 201 and it works good.
the thing is a keep getting spikes in the pressure without actually putting pressure in:
|202||1.2165|
|201||0.0000|
|202||1.2165|
|201||1.2165|
|201||-1.2165|
|200||3.6496|
|202||0.0000|
|202||1.2165|
|201||0.0000|
|201||-2.4331|
|201||0.0000|
|201||0.0000|
the left side is the analogRead values and the right is the pressure. for the same analogRead values i get different pressures.


i changed the wirings as jim-p suggested and connected the power supply directly to the blue wire

Something wrong.
The MP47P-03-F1 can only read Positive pressures
Try using a different analog like A3

Yes, i didn't see an issue with the connection

Did you try another analog input

The datasheet of the sensor says that it outputs 0.6volt at zero pressure.
With a 5volt processor and 10-bit A/D I get 0.6 / 5 * 1024 = 122.88 (123).

If you're not getting 0.6volt (123) from the sensor without pressure, then there could be something wrong with the sensor or sensor supply.

I see four decimal places in your readout (I did cut off the decimal places).
Wishful thinking. With a 10-bit A/D you get about 900 steps, which is not even enough to display 1000kPa without any decimal places. If you want decimal places, then display in Mpa or Bar.
`float sensorType = 10.0; // Bar

A jump of one A/D value from 201 is not that bad, and can be fixed with smoothing code.
Leo..

@jim-p i tried a different analog input but with no success.

@Wawa, from what i've calculated, the voltage at 0 MPa should be 1V (P=0.25V-0.25) and this is what i also get when measuring.
is there no other way to remove the ±1 fluctuations in the analog read? each of this jumps translates to ~1KPa of pressre.

I now see that the sensor has a 1-5volt range, so offset should indeed be set to about 200.

You have a 1000kPa sensor an A/D with 1024 - 202 = 822 steps that could jump one digit.
That makes it seemingly impossible to display with a 1kPa resolution.

I did mention smoothing code (oversampling) in post#18. That will give you a more stable readout and more A/D values to display in 1kPa.
Leo..

1 Like