# Pressure sensor in flowmeter is accurate but not consistent

#### teegfit

Joined Aug 23, 2020
10
Hi All,

I have a ultra low differential pressure sensor in a flow meter configuration(Venturi meter). https://www.te.com/commerce/Documen...pdfEnglishENG_DS_SM9000_A1.pdfCAT-BLPS0062

Through help from the members on this forum I was able to get rid of the zero error and then after that the sensor was reading perfectly and when I applied a moving average filter I was able to consistent results. I am pushing a calibrated 3 liters of air through the flow meter as seen in the pictures below.

Now the problem: I will push the air through and it will be accurate 3.0L +/- 5% for maybe 20 readings. and then something will happen (not physically, everything is the same setup). But suddenly it will start showing 3.5 -3.8 L for a few readings and then will change and go back to 3L. Does anyone have any idea what could be happening here? This is a supposedly high quality sensor so I would not expect this inconsistency, could it be broken?

I am recording the data as averaged moving filter and also not averaged, sometimes the averaged data is closer to the 3L and then it will switch.

How I am recording the data:

Sensor attached to arduino > into matlab > matlab records 500 data points from the sensor > first and last 50 are used to calculate the zero error( I push the syringe inbetween these values) > those counts from the sensor are turned into pressure differentials across the venturi meter > Volumetric flow rate in L/s is calculated for each of these points> Integrate over these 500 values to get the area under the curve i.e. the total volume that has passed through the venturi meter.

Code attached

Code:
clear a dev;
a = arduino();

%%Read from the pressure sensor

clear global;
clear dev counts Erroradjustedcounts p countserr1 countserr2 countserrtot;
i = 0;
data_length = 500;

F0 = x(1);
F1 = x(2);

C = bitshift(F1,8);
readings = F0 + C;

while i < data_length

i = i + 1;
% Calling the sensor reading
F0 = x(1);
F1 = x(2);
C = bitshift(F1,8);
readings = F0 + C;

counts(i,:) = [i count];

end

Erroradjustedcounts = zeros( i, 2);
p = zeros(i,2);
v = zeros(100, 2);
g = zeros(100, 2);
vf = zeros(i,2);
vfr = zeros(i,2);
i = 0;
for i=1:50 %Calculate zero error over first 50 values
if counts(i,2) < 200
v(i,:) = [i counts(i,2)];
end
end

countserr1 = mode(v(1:50,2)); %Average of the values under 100 in the first 100 hundred values

for i=450:500 %Calculate zero error over last 100 values
if counts(i,2) < 200
g(i,:) = [i counts(i,2)];

end
end
countserr2 = mode(g(450:500,2)); %Average of the values under 100 in the last 100

countserrtot = (countserr1 + countserr2)/2;

for i=1:500

Erroradjustedcounts(i,:) = [i counts(i,2)-countserrtot];
pmin = -250;
pmaxpmin = 500;

p(i,:) = [i (pmin+(outread(i,2)*pmaxpmin))]; % Pressure in Pa

if p(i,2) < 0.01
p(i,2) = 0;
end

end
% for i=1:100;
% leftover = sum(Erroradjustedcounts(i,2));% This is ranging from -300 to + 300, this could be the reason of our error
% end
% % % calculating p
% leftovers = 2*sum(leftover);
%
% %Calculating pressure for leftover error
% pmin = -250;
% outreadleftover = ((leftovers)-(-26215))/(26214-(-26215)) ;
% pmaxpmin = 500;
% pleftover = ((pmin+(outreadleftover*pmaxpmin)));
% pleftover = abs(pleftover);
% lvfr = (cd*(a1*sqrt((2*pleftover/(r*((c^2)-1))))));
% lvfr = lvfr*1000;

% %Calculating Volumetric Flow Rate
%
%
for i=1:500
a1=0.00031415927; % Cross sectional Area of the first part of the Tube
a2=0.00023560563; % Cross sectional Area of the second part of the Tube
r=1.225; %Density of air
c=a1/a2; % Ratio of Areas
cd = 0.98; % discharge coefficient

vf(i,:) = [i (cd*(a1*sqrt((2*p(i,2)/(r*((c^2)-1))))))]; %Calculating Volumetric flow rate in M^3/s
vfr(i,:) = [i vf(i,2)*1000];
windowSize = 25;
b = (1/windowSize)*ones(1,windowSize);
a = 1.2;
filvfr = filter(b,a,vfr(:,2));

end
plot(p(:,2));
plot(filvfr);
plot(vfr(:,2));

Ar = trapz(0.01,vfr(:,2));
Ar2 = trapz(0.01,filvfr) ; %% minus the zero error left over

#### Attachments

• 2.3 MB Views: 18
• 1.2 MB Views: 18

#### Deleted member 115935

Joined Dec 31, 1969
0
Hi All,

I have a ultra low differential pressure sensor in a flow meter configuration(Venturi meter). https://www.te.com/commerce/DocumentDelivery/DDEController?Action=showdoc&DocId=Data+SheetSM9000A1pdfEnglishENG_DS_SM9000_A1.pdfCAT-BLPS0062

Through help from the members on this forum I was able to get rid of the zero error and then after that the sensor was reading perfectly and when I applied a moving average filter I was able to consistent results. I am pushing a calibrated 3 liters of air through the flow meter as seen in the pictures below.

Now the problem: I will push the air through and it will be accurate 3.0L +/- 5% for maybe 20 readings. and then something will happen (not physically, everything is the same setup). But suddenly it will start showing 3.5 -3.8 L for a few readings and then will change and go back to 3L. Does anyone have any idea what could be happening here? This is a supposedly high quality sensor so I would not expect this inconsistency, could it be broken?

I am recording the data as averaged moving filter and also not averaged, sometimes the averaged data is closer to the 3L and then it will switch.

How I am recording the data:

Sensor attached to arduino > into matlab > matlab records 500 data points from the sensor > first and last 50 are used to calculate the zero error( I push the syringe inbetween these values) > those counts from the sensor are turned into pressure differentials across the venturi meter > Volumetric flow rate in L/s is calculated for each of these points> Integrate over these 500 values to get the area under the curve i.e. the total volume that has passed through the venturi meter.

Code attached

Code:
clear a dev;
a = arduino();

%%Read from the pressure sensor

clear global;
clear dev counts Erroradjustedcounts p countserr1 countserr2 countserrtot;
i = 0;
data_length = 500;

F0 = x(1);
F1 = x(2);

C = bitshift(F1,8);
readings = F0 + C;

while i < data_length

i = i + 1;
% Calling the sensor reading
F0 = x(1);
F1 = x(2);
C = bitshift(F1,8);
readings = F0 + C;

counts(i,:) = [i count];

end

Erroradjustedcounts = zeros( i, 2);
p = zeros(i,2);
v = zeros(100, 2);
g = zeros(100, 2);
vf = zeros(i,2);
vfr = zeros(i,2);
i = 0;
for i=1:50 %Calculate zero error over first 50 values
if counts(i,2) < 200
v(i,:) = [i counts(i,2)];
end
end

countserr1 = mode(v(1:50,2)); %Average of the values under 100 in the first 100 hundred values

for i=450:500 %Calculate zero error over last 100 values
if counts(i,2) < 200
g(i,:) = [i counts(i,2)];

end
end
countserr2 = mode(g(450:500,2)); %Average of the values under 100 in the last 100

countserrtot = (countserr1 + countserr2)/2;

for i=1:500

Erroradjustedcounts(i,:) = [i counts(i,2)-countserrtot];
pmin = -250;
pmaxpmin = 500;

p(i,:) = [i (pmin+(outread(i,2)*pmaxpmin))]; % Pressure in Pa

if p(i,2) < 0.01
p(i,2) = 0;
end

end
% for i=1:100;
% leftover = sum(Erroradjustedcounts(i,2));% This is ranging from -300 to + 300, this could be the reason of our error
% end
% % % calculating p
% leftovers = 2*sum(leftover);
%
% %Calculating pressure for leftover error
% pmin = -250;
% outreadleftover = ((leftovers)-(-26215))/(26214-(-26215)) ;
% pmaxpmin = 500;
% pleftover = ((pmin+(outreadleftover*pmaxpmin)));
% pleftover = abs(pleftover);
% lvfr = (cd*(a1*sqrt((2*pleftover/(r*((c^2)-1))))));
% lvfr = lvfr*1000;

% %Calculating Volumetric Flow Rate
%
%
for i=1:500
a1=0.00031415927; % Cross sectional Area of the first part of the Tube
a2=0.00023560563; % Cross sectional Area of the second part of the Tube
r=1.225; %Density of air
c=a1/a2; % Ratio of Areas
cd = 0.98; % discharge coefficient

vf(i,:) = [i (cd*(a1*sqrt((2*p(i,2)/(r*((c^2)-1))))))]; %Calculating Volumetric flow rate in M^3/s
vfr(i,:) = [i vf(i,2)*1000];
windowSize = 25;
b = (1/windowSize)*ones(1,windowSize);
a = 1.2;
filvfr = filter(b,a,vfr(:,2));

end
plot(p(:,2));
plot(filvfr);
plot(vfr(:,2));

Ar = trapz(0.01,vfr(:,2));
Ar2 = trapz(0.01,filvfr) ; %% minus the zero error left over

you need to isolate where the error is happening, divide and conquer.

So the Arduino,
get that to print a running average of its reading to the Arduino serial terminal,.

Thinks like to often reading , external interference, will show up here.

If all these readings are good,
the problem is in your matlab code.

Any reason you are using matlab , not the native Arduino processor do do the number crunching ?

Try the matLab running with a dummy input file instead of the Arduino,
see if the response is the same,

Depending upon the above, you know which direction to look further.

#### teegfit

Joined Aug 23, 2020
10
you need to isolate where the error is happening, divide and conquer.

So the Arduino,
get that to print a running average of its reading to the Arduino serial terminal,.

Thinks like to often reading , external interference, will show up here.

If all these readings are good,
the problem is in your matlab code.

Any reason you are using matlab , not the native Arduino processor do do the number crunching ?

Try the matLab running with a dummy input file instead of the Arduino,
see if the response is the same,

Depending upon the above, you know which direction to look further.
Thanks, that is what I have tried to do, however I wonder if the sensor is broken and I am just wasting time.

The problem is I can get the average and it doesnt seem to be suffering from "much" interference, the sensor reads change by 1 -2 at 0 pressure over the course of a few minutes but then the readings will just start shifting and then stay in their shifted position, to me this doesnt sound like interference is the under laying issue.

I dont think it is the MATLAB code as I can examine all conversions and they seem to be ok and again, I am getting close to 0 at 0 pressure, usually 0.03/6.

"Try the matLab running with a dummy input file instead of the Arduino,
see if the response is the same, " - I will try this, good idea.

I am using MATLAB as I am taking the readings and then storing them before manipulating them, I don't think Arduino would have the storage for this.

Thanks for the response.

#### Deleted member 115935

Joined Dec 31, 1969
0
The arduino is very capable,
not least it can print to the terminal attached to the Arduino, and can store data to the PC directly
I'd suggest you look at what the arduino is reading,
then you know is it the Arduino / sensor or the link / matlab,

Arduino should easily be able to store several thousand readings in it memory , depending what you have

something like this has a Mbit or ram , and 2 Mbit of flash if you want to store longer term,
and also interface to SD card and an ethernet option.

https://www.pjrc.com/store/teensy40.html

#### bobcroft

Joined Aug 22, 2011
11
Have a look at Meguno-Link software, it can do logging, graphing and loads of other stuff. It is free for limited use and cheap for a full version. It can use serial, UDP and several other protocols. I highly recommend it. Again, as others have said, I would use just the Arduino for some basic tests.

#### RPLaJeunesse

Joined Jul 29, 2018
231
From the picture it appears that your hookup could be considered rather sloppy, and prone to noise from the nearest cellphone, wifi, or bluetooth device. Is sensor power bypassed with a 100nF capacitor right at the sensor? Maybe reduce the I2C pullups to 2k2 or 1k8. In general one should keep all leads as short as possible, keep wire pairs (+/- signal, +/- power) twisted, shield wires if appropriate, bypass supplies like your life depended on them, and put all the electronics inside a metal box that is grounded at only 1 point.

#### djsfantasi

Joined Apr 11, 2010
8,775
There is an Arduino library or Excel hack that allows you to save data from an Arduino to an Excel spreadsheet on a computer.

I’ll see if I can find it.

#### djsfantasi

Joined Apr 11, 2010
8,775
Here’s an Arduino site article on doing this. There are several resources that can be found by searching for ”Arduino to Excel”.

#### click_here

Joined Sep 22, 2020
545
Using Putty I usually just save it as a .csv file (comma separated variables) and import it to excel.