Hello guys hope you can help me get data from this absolute pressure sensor

Hello guys hope you can help me get data from this absolute pressure sensor im using the following sensor

http://uk.farnell.com/honeywell/nbplann150paunv/sensor-pressure-abs-150-psi-smt/dp/2146007

and this is my gauge project i have tweaked someone else code etc but its not reading right can’t get my head around the scale and the Vout+ and Vout- and yes i have searched all over place i may be chasing my tail with the scale from my issues with the input ?

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#include <SPI.h>
#define sensorPin 0
#define OLED_MOSI   11
#define OLED_CLK   13
#define OLED_DC    12
#define OLED_CS    10
#define OLED_RESET 2
Adafruit_SH1106 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);



// bar graph

float rawval = 0; // Setup raw sensor value
float barboost = 0; // Setup value for boost bar

// peak

int boostPeakReset = 6000; // time in milis to reset peak value
float boostPeak = 0.00;
float boostMax = 0.00;
unsigned long boostPeakTimer = 0;

// log

byte count;
byte sensorArray[128];
byte drawHeight;
boolean filled = 0; //decide either filled, or dot-display. 0==dot display.


void setup()
{
  display.begin(SH1106_SWITCHCAPVCC); // 3.3V power supply
  display.clearDisplay(); // Clear the display and ram
  for (count = 0; count <= 128; count++) //zero all elements
  {
    sensorArray[count] = 0;
  }
}

void loop() // Start loop
{
  int boostmbar = map(analogRead(sensorPin), 1023, 167.77, 5, 0.82);
  rawval = analogRead(0); // Read MAP sensor raw value on analog port 0
  barboost = (((rawval * 0.19) - 69.45) + 10); // Calculate boost value for the bargraph  


  if (boostPeak < boostmbar && boostmbar > 0.50) {
    boostPeak = boostmbar;
    boostPeakTimer = millis();
    if (boostMax < boostPeak) {
      boostMax = boostPeak;
    }
  }
  else if (boostPeak > boostmbar && (millis() - boostPeakTimer) > boostPeakReset) {
    boostPeak = 0.00;
  }


  // log 

  drawHeight = map(analogRead(A0), 0, 1023, 0, 25 );  

  sensorArray[0] = drawHeight;

  for (count = 55; count <= 128; count++ )
  {
    if (filled == false)
    {
      display.drawPixel(count, 71 - sensorArray[count - 55], WHITE);
    }
    else
      display.drawLine(count, 1, count, 71 - sensorArray[count - 55], WHITE); 
  }

  for (count = 80; count >= 2; count--) // count down from 160 to 2
  {
    sensorArray[count - 1] = sensorArray[count - 2];
  }

  //display.drawLine(55, 43, 55, 64, WHITE);
  display.setTextColor(WHITE);
  display.setTextSize(3);
  display.setCursor(0, 0);
  display.println((boostmbar * 0.001) - 0.97);    // 0.97 = 970mbar atmospheric pressure correction

  display.drawRect(0, 24, 128, 12, WHITE); // Border of the bar chart
  display.fillRect(0, 24, barboost, 12, WHITE); // Draws the bar depending on the sensor value
  
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(97, 0);
  display.println("BAR");

  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0, 40);
  display.println("PEEK");

  display.setTextSize(2);
  display.setCursor(0, 50);
  display.println((boostPeak * 0.001) - 0.97); // 0.97 = 970mbar atmospheric pressure correction


  if (970 < boostmbar ) {
    display.setTextSize(1);
    display.setCursor(97, 14);
    display.println("BOOST");
  }
  else if (970 > boostmbar ) {
    display.setTextSize(1);
    display.setCursor(97, 14);
    display.println("VAC");
  }

  delay(1);
  display.display();
  display.clearDisplay();
}

i have used the simple voltage serial output to measure voltage coming from the sensor but its at 2 ish volts i expected more like 0.82v ?

Looks like that sensor outputs about 130 mV @ 150 PSI with a 5V supply and around 13mV @ atmospheric pressure, do you have DMM to measure?

yes i have dmm what output am i after the + or - ? confused thanks for prompt reply

Meter on DC mV range, black lead on " - ", red on sensor output pin.

there are 4 pins as follows

GND where i think you want my negative lead of dmm?

Vsupply Where the 5v goes in ?

then there are 2 outputs called

Vout+ (i presume this is where the red lead of my dmm wants to be ?

and

Vout-

these are my voltages

supply voltage is 4.77v

signal from Vout+ is 2.427v

signal from Vout- is 2.415v

So the sensor output@ atmospheric pressure is 2.427 - 2.415 = 0.012V or 12 mV, thats only 2 or 3 counts on the Arduino's ADC and 150 PSI would only be about 27, you're going to need at least 20 to 30X amplification to make that work, I would choose another sensor.

fantastic thanks for getting back so quick !

i had ordered this one as well its amplified but no internal vac reference just compares to atmospheric pressure

Yes, looks much easier to work with, can you figure out the 5% to 95% voltage range (0.5 to 4.5V) OK?

im not to good with calculations and equations yet ? but will this be able to measure vacuum ? no big deal if not

appreciate the help :slight_smile:

Yes, standard atmospheric pressure is 1.013 bar, any reading less than that will be negative pressure or vacuum.

but in data sheet this compares with atmos ? how would i adjust the code then ?

Well, at zero pressure the sensor outputs 0.5 volts, assuming a 5V reference, thats an ADC count of 102, at 10 bar (147 PSI), 4.5V, a count of 921, so a 147 psi span = 921 - 104 = 817 ADC count span after subtracting the zero offset, or 5.56 counts / PSI. 14.7 * 5.56 = about 81 counts after subtracting the 104 offset, leaving about 736 counts for 0 to 132 PSI gage pressure.

the calculations on my code are in millibar ? how to i input those numbers ? in here ?

int boostmbar = map(analogRead(sensorPin), 1023, 167.77, 5, 0.82);
  rawval = analogRead(0); // Read MAP sensor raw value on analog port 0
  barboost = (((rawval * 0.19) - 69.45) + 10); // Calculate boost value for the bargraph

and is it easy to convert to either kpa and psi ? new to all this

...map(analogRead(sensorPin), 1023, 167.77, 5, 0.82);

From the map reference page:
"The map() function uses integer math so will not generate fractions, when the math might indicate that it should do so. Fractional remainders are truncated, and are not rounded or averaged."
Leo..

i had entered this prior to your reply and it looked about right ?

nt boostmbar = map(analogRead(sensorPin), 21, 921, 102, 10000);
  rawval = analogRead(0); // Read MAP sensor raw value on analog port 0
  barboost = (((rawval * 0.19) - 69.45) + 10); // Calculate boost value for the bargraph

showing zero bar ie atmos ?

i had then entered the one you posted and it showed -0.98 bar is there an ofset i need to ad ?

My last post was for the 0.5 to 4.5V sensor, not the milliVolt one, to convert PSI to millibars, multiply by 68.945:

Well, at zero pressure the sensor outputs 0.5 volts, assuming a 5V reference, thats an ADC count of 102, at 0 pressure, at 10000 mbar, 4.5V, a count of 921, so a 10000 mbar span = 921 - 102 = 819 ADC count span after subtracting the zero offset, so atmospheric pressure would read about 83 counts after subtracting the 102 offset, leaving about 737 counts for 0 to 8987 mbar gage pressure.

so outsider did i enter it correctly ? getting there i seamed to work nice until i soldered for just a tad too long and the top came off bu i have another one on the way and it will soldered on with bismuth from work :wink: bodged the other one together for now still getting readings flickers from 0.00 to 0.01

i had fed it with 5v down the signal wire to just check range we got 10.15 sound about right at 5v ? i know it will never teach 5v but i don't have a 10 bar reference at home

nt boostmbar = map(analogRead(sensorPin), 21, 921, 102, 10000);
  rawval = analogRead(0); // Read MAP sensor raw value on analog port 0
  barboost = (((rawval * 0.19) - 69.45) + 10); // Calculate boost value for the bargraph 
[CODE]

tested quickly at work seams to read 2 bar similar to calibrated gauge will go higher but sensor is leaking new one arrived today will mill a nice enclosure on the weekend :slight_smile: one thing not sure if it is fixable but the jumping around from vac to boost is quite noticeable is there a way of filtering the input to stabilise the displayed values ?

Very persistent to get this working i have now tried to add rolling averages i think i have implemented it correctly ? used a library from this link GitHub - sofian/MovingAverage: An exponential moving average class for Arduino/Wiring.

readout seams jittery still regardless of altering

MovingAverage average(0.1);
#include <MovingAverage.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#include <SPI.h>
#define sensorPin 0
#define OLED_MOSI   11
#define OLED_CLK   13
#define OLED_DC    12
#define OLED_CS    10
#define OLED_RESET 2
Adafruit_SH1106 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
MovingAverage average(0.1);


// bar graph

float rawval = 0; // Setup raw sensor value
float barboost = 0; // Setup value for boost bar

// peak

int boostPeakReset = 6000; // time in milis to reset peak value
float boostPeak = 0.00;
float boostMax = 0.00;
unsigned long boostPeakTimer = 0;

// log

byte count;
byte sensorArray[128];
byte drawHeight;
boolean filled = 0; //decide either filled, or dot-display. 0==dot display.


void setup()
{
  Serial.begin(57600);
  // Initialize the average with the first value from analogRead().
  average.reset( analogRead(0) );
  display.begin(SH1106_SWITCHCAPVCC); // 3.3V power supply
  display.clearDisplay(); // Clear the display and ram
  for (count = 0; count <= 128; count++) //zero all elements
  {
    sensorArray[count] = 0;
  }
}

void loop() // Start loop
{
  
  average.update( analogRead(0) );
  Serial.println( average.get() );
  int boostmbar = map(analogRead(sensorPin), 21, 921, 102, 10000);
  rawval = analogRead(0); // Read MAP sensor raw value on analog port 0
  barboost = (((rawval * 0.19) - 69.45) + 10); // Calculate boost value for the bargraph  


  if (boostPeak < boostmbar && boostmbar > 0.50) {
    boostPeak = boostmbar;
    boostPeakTimer = millis();
    if (boostMax < boostPeak) {
      boostMax = boostPeak;
    }
  }
  else if (boostPeak > boostmbar && (millis() - boostPeakTimer) > boostPeakReset) {
    boostPeak = 0.00;
  }


  // log 

  drawHeight = map(analogRead(A0), 0, 1023, 0, 25 );  

  sensorArray[0] = drawHeight;

  for (count = 55; count <= 128; count++ )
  {
    if (filled == false)
    {
      display.drawPixel(count, 71 - sensorArray[count - 55], WHITE);
    }
    else
      display.drawLine(count, 1, count, 71 - sensorArray[count - 55], WHITE); 
  }

  for (count = 80; count >= 2; count--) // count down from 160 to 2
  {
    sensorArray[count - 1] = sensorArray[count - 2];
  }

  //display.drawLine(55, 43, 55, 64, WHITE);
  display.setTextColor(WHITE);
  display.setTextSize(3);
  display.setCursor(0, 0);
  display.println((boostmbar * 0.001) - 0.97);    // 0.97 = 970mbar atmospheric pressure correction

  display.drawRect(0, 24, 128, 12, WHITE); // Border of the bar chart
  display.fillRect(0, 24, barboost, 12, WHITE); // Draws the bar depending on the sensor value
  
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(97, 0);
  display.println("BAR");

  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0, 40);
  display.println("PEEK");

  display.setTextSize(2);
  display.setCursor(0, 50);
  display.println((boostPeak * 0.001) - 0.97); // 0.97 = 970mbar atmospheric pressure correction


  if (970 < boostmbar ) {
    display.setTextSize(1);
    display.setCursor(97, 14);
    display.println("BOOST");
  }
  else if (970 > boostmbar ) {
    display.setTextSize(1);
    display.setCursor(97, 14);
    display.println("VAC");
  }

  delay(1);
  display.display();
  display.clearDisplay();
}