Needing better averaging code for pressure sensor

Wawa:
A scope looks at voltage, not at ratio.
A smoother scope voltage is therefore useless.

Better to take a bunch of readings for averaging.
unsigned int total = 0; // reset
for (int x = 0; x < 64; x++) total += analogRead(A0);
Leo..

I thought the pressure sensor has a analog voltage output based on pressure input. So the nano reads the analog signal from the pressor sensor as a voltage. So intern a wavering voltage equals a wavering reading. Am I wrong to think of it that way?

The sensor has a ratiometric output.
If, at a certain pressure, the sensor outputs 2.5volt when powered with 5volt,
then the sensor outputs, with the same pressure, 2volt if the supply drops to 4volt.

Did you actually trace the cause of this pressure change (with a scope), before trying to fix it.
An 7809 for two pumps and the Nano sets off alarm bells in my head.
That regulator needs at least 2volt across to work, and will get into foldback current limiting above 1.2-1.5A.
Did you measure the output of that regulator with a scope (for dips).

I assume you also connected supply and ground of the sensor directly to VCC/GND of the Nano.
Sharing VCC/GND with motor wires could also give this behaviour.

If the vibration is purely from air pressure ripple, then try a mechanical solution first.
Stuff a piece of cotton from a cotton swab into the short tube that goes from the T-joint to the sensor.
Tightly packed inside the line, and close to the T-joint.
That will give some air flow resistance, and some buffering of the rest of air in the tube.

What do you mean with 'remainder'.
You could measure/calculate in integers, so you don't have a remainder.
Leo..

The remainder I am referring to is the averaging code I have now leaves a decimal.

Supply voltage is 12v and toal current draw on the 7809 is max 300ma. The circuit will not be on for long periods of time anyway but I am good at low current draw.

All voltages are stable when checked with the scope, so my issue is just the pulsating pumps.

Ground and power for the pressure sensor are directly from the Nano.

So with good steady voltage as checked with the scope my only issue is the pumps. I will try the cotton as you suggested.

If I need the code you posted can you tell me how I can implement it into mine? I kinda take it that X would be my value from the pressure sensor code? Just don't understand why it rereads analogread(AO) again.

When you use the Nano with 9V and the onboard voltage regulator of 5V is used, then it is a steady 5.0 V. Then the RC filter is okay. But I still prefer to keep the ratiometric match between the sensor and the Arduino to be able to use the USB cable to power the Arduino Nano.

Do you know what kind of pulsation the pump creates in the air pressure ? What is the frequency range and the amplitude of the pulsation ?

A ratiometric sensor does not output a voltage, but a voltage relative to the 5V.
The default setting for the Arduino is the analog reference set to VCC, so that is also relative to the 5V.
When the sensor outputs 20% of 5V, then the arduino reads 20% of 5V. When the 5V changes, both the sensor and the Arduino will still be at 20%. When that 20% is calculated into the pressure in kPa, then it will be same pressure, even when the 5V changes.

Common average:

// Without average
int value = analogRead( A0);


// With average
unsigned int total = 0;    // reset
for( int x = 0; x < 64; x++)
{
  total += analogRead( A0);
}
int value = total / 64;

That is reduce the noise. I would also use a moving average smoothing to reduce the pulsation from the pumps.

I think max human readable display rate is about four readings per second.
I would not want to see or use any pressure data older than 250ms if I would pick a 4Hz display rate.
So I would do any averaging/smoothing within that time frame, for a true/instant pressure, without lag.

Koepel is right about having to know a single pulsation duration.
Without that you can't choose the best averaging algorithm.
Leo..

Ok Guys! All great stuff and I want to learn more. I will get the info you asked for Koepel!

Here is what I did, I tried your suggestions on dampening the pulsations. I used a small RC Fuel filter and stuffed it with cotton. I put it right after the T fitting on the line to the pressure sensor. The reason I used a small fuel filter is it has a small screen and I didn't want any cotton fibers finding its way to the pressure sensor. It took 99.9% of the pulsing away. I get pretty good steady readings no lag time on the reading, very responsive and great repeatability.

I would still like to understand smoothing for my particular situation, great learning lesson.

I sincerely appreciate the help!
Kevin

dubq0620.jpg

That is a huge improvement !
I have a damper after the pump, the polyester fibers that I use let the air go through freely.

Koepel:
That is a huge improvement !
I have a damper after the pump, the polyester fibers that I use let the air go through freely.

Koepel:
When you use the Nano with 9V and the onboard voltage regulator of 5V is used, then it is a steady 5.0 V. Then the RC filter is okay. But I still prefer to keep the ratiometric match between the sensor and the Arduino to be able to use the USB cable to power the Arduino Nano.

Do you know what kind of pulsation the pump creates in the air pressure ? What is the frequency range and the amplitude of the pulsation ?

A ratiometric sensor does not output a voltage, but a voltage relative to the 5V.
The default setting for the Arduino is the analog reference set to VCC, so that is also relative to the 5V.
When the sensor outputs 20% of 5V, then the arduino reads 20% of 5V. When the 5V changes, both the sensor and the Arduino will still be at 20%. When that 20% is calculated into the pressure in kPa, then it will be same pressure, even when the 5V changes.

Common average:

// Without average

int value = analogRead( A0);

// With average
unsigned int total = 0;    // reset
for( int x = 0; x < 64; x++)
{
  total += analogRead( A0);
}
int value = total / 64;



That is reduce the noise. I would also use a moving average smoothing to reduce the pulsation from the pumps.

Koepel,

What is int x in the code? I somewhat understand the code but what is x in reference to?

Nothing special. Call it 'i' if you want to. It is just a variable for the for-loop.