Strange results with analog negative pressure sensor (Panasonic ADP5111)

Hi all,

I’m using a Panasonic ADP5111 in my project and I wrote the code in order to read the mBars in an air tube that seems to be working.

ADP5111 Datasheet

#define ADP A0

unsigned long Timer = 0; //similar to the "blink without delay"
const long Interval = 500;

void setup() {
  analogReference(EXTERNAL); //using external ic on aref, just to be safe

void loop() {
  unsigned long Current = millis();
  if (Current - Timer >= Interval)
    analogRead(ADP); //wake up pin (is it useful?)
    Timer = Current;
    int Rep = 64; // too much?
    int Raw = 0;
    for (int I = 0; I < Rep; I++) Raw += analogRead(ADP); //smoothing out values
    Raw = Raw / Rep;
    float V = Raw * (5.0 / 1023); //converting value to voltage
    float kPa = (vacV - 0.5) / 4.0 * 100; //voltage to kPa
    float mBar = vackPa * 10; //kPa to mBar

The sensor (ADP5111) is a 5V sensor, and the output goes from 0.5V to 4.5V (0 to 100kPa).

As you can see in the code, I’m using an external analog reference ic, analog filters and a smooth values formula.

However, I feel like the formula (or the whole code) is unnecessarily complicated.

Where are the errors (if any?)

int vacRaw = 0;
for (int vacI = 0; vacI < vacRep; vacI++) vacRaw += analogRead(ADP); //smoothing out values
vacRaw = vacRaw / vacRep;

  • use “float” (to avoid rounding down .999 to zero)

64 times read seems overkill