Convert Analog to Digital Reading, pressure Tranducer

Hello everyone,

So I am working on a project for a device called Super Air Meter
I have an Ashcroft pressure transducer 0-250 psig


and I am using the code below, the problem is that I want to get the analog reading and also, clabritate the transducer with pressure gauge to make it accurate

/* This example demonstrates how to take a standard 3-wire pressure transducer
 *  and read the analog signal, then convert the signal to a readable output and
 *  display it onto an LCD screen.
 *  
 *  Contact Tyler at tylerovens@me.com if you have any questions
 */

#include "Wire.h" //allows communication over i2c devices
#include <LiquidCrystal_I2C.h>

const int pressureInput = A0; //select the analog input pin for the pressure transducer
const int pressureZero = 102.4; //analog reading of pressure transducer at 0psi
const int pressureMax = 921.6; //analog reading of pressure transducer at 100psi
const int pressuretransducermaxPSI = 100; //psi value of transducer being used
const int baudRate = 9600; //constant integer to set the baud rate for serial monitor
const int sensorreadDelay = 250; //constant integer to set the sensor read delay in milliseconds

float pressureValue = 0; //variable to store the value coming from the pressure transducer

LiquidCrystal_I2C lcd(0x27, 20, 4); //sets the LCD I2C communication address; format(address, columns, rows)

void setup() //setup routine, runs once when system turned on or reset
{
  Serial.begin(baudRate); //initializes serial communication at set baud rate bits per second
  lcd.init(); //initializes the LCD screen
}

void loop() //loop routine runs over and over again forever
{
  pressureValue = analogRead(pressureInput); //reads value from input pin and assigns to variable
  pressureValue = ((pressureValue-pressureZero)*pressuretransducermaxPSI)/(pressureMax-pressureZero); //conversion equation to convert analog reading to psi
  Serial.print(pressureValue, 1); //prints value from previous line to serial
  Serial.println("psi"); //prints label to serial
  lcd.setCursor(0,0); //sets cursor to column 0, row 0
  lcd.print("Pressure:"); //prints label
  lcd.print(pressureValue, 1); //prints pressure value to lcd screen, 1 digit on float
  lcd.print("psi"); //prints label after value
  lcd.print("   "); //to clear the display after large values or negatives
  delay(sensorreadDelay); //delay in milliseconds between read values
}


int cannot hold decimal places.

Your code is already doing that, it seems.

The reading at 0= 102.4, but what about at 100 psi? (921.6) my transducer has max pressure up to 250 psi, should I change 921.6?

onst int pressureZero = 102.4; //analog reading of pressure transducer at 0psi
const int pressureMax = 921.6; //analog reading of pressure transducer at 100psi
const int pressuretransducermaxPSI = 100; //psi value of transducer being used```

What would the "reading" be at 250 PSI?
Can You post a link to the datasheet? Your commented code is not in harmony with the picture data.

Hello abraham9698
Check the datasheet of the sensor for the transmission function.
Have a nice day and enjoy coding in C++.

Yes the code is for 100 psi transducer, and I want to modify it to the Ashcroft that I have

The code you posted is for a ratiometric sensor, but your sensor is absolute/linear.
Offsets are already accounted for by the electronics inside the sensor.
Therefore you can convert A/D reading directly to pressure.
(float) pressure = analogRead(A0) * 250.0 / 1024; // should work, assuming a 5volt Arduino
But then readout is as unstable as Arduino's supply voltage.

You could dial down the sensor output to 0-1volt with a voltage divider, and use 1.1volt Aref.
Or, maybe better, use an ADS1115 breakout board (with voltage divider).
Leo..

1 Like

Last point you mentioned
do you mean by doing that the analog reading (921.6) will change to a different number?

Forget about those numbers.
Those numbers are for sensors with a 0.5-4.5volt 10-90% output, which your sensor is not.
You sensor has a 0-5volt output.
Leo..

I used this code with the transducer I have, but it shows me 0psi, it does not read at all! Is it because of the code or the transducer could be damaged?

#include "Wire.h" //allows communication over i2c devices
#include <LiquidCrystal_I2C.h>

const int pressureInput = A0; //select the analog input pin for the pressure transducer
const int baudRate = 9600; //constant integer to set the baud rate for serial monitor
const int sensorreadDelay = 250; //constant integer to set the sensor read delay in milliseconds

float pressureValue = 0; //variable to store the value coming from the pressure transducer
float pressure = analogRead(A0) * 250.0 / 1024; //convert A/D reading directly to pressure
LiquidCrystal_I2C lcd(0x27, 20, 4); //sets the LCD I2C communication address; format(address, columns, rows)

void setup() //setup routine, runs once when system turned on or reset
{
  Serial.begin(baudRate); //initializes serial communication at set baud rate bits per second
  lcd.init(); //initializes the LCD screen
}

void loop() //loop routine runs over and over again forever
{
  pressureValue = analogRead(pressureInput); //reads value from input pin and assigns to variable
  Serial.print(pressureValue, 1); //prints value from previous line to serial
  Serial.println("PSI"); //prints label to serial
  lcd.setCursor(0,0); //sets cursor to column 0, row 0
  lcd.print("Pressure:"); //prints label
  lcd.print(pressureValue, 1); //prints pressure value to lcd screen, 1 digit on float
  lcd.print("psi"); //prints label after value
  lcd.print("   "); //to clear the display after large values or negatives
  delay(sensorreadDelay); //delay in milliseconds between read values
}

Your code looks correct for taking an analogRead() on pin A0.

Can you confirm that with the sensor disconnected, and A0 jumpered to 5v or 3.3v you get a reading other than 0? If the answer is 0 then the Arduino pin is defective and you can try a different analog input.

If the Arduino is indeed working correctly for AnalogRead() the then issue is that the sensor is not putting out a readable voltage. Is it powered correctly? Is it seeing pressure?

Got lines in the wrong place and variables mixed up.
Start clean, get it working, build up from there.
Here is the short version that should work (compiles, but not tested).

float pressure;

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

void loop() {
  pressure = analogRead(A0) * 250.0 / 1024; //convert A/D reading directly to pressure
  Serial.print(pressure, 1);
  Serial.println(" PSI");
  delay(250);
}

Don't connect the sensor yet, but connect A0 to the 3.3volt pin first.
The serial monitor should display about 166 with 3.3volt input.
Then remove the 3.3volt link and try the sensor.
Leo..

I did as you mentioned then I got around 86 psi in the serial monitor. After that, I connected the sensor to the Arduino (red cable to 3.3v, black to ground, white to A0)

When I connected the sensor to 5v it shows only 0 but with 3.3v it shows reading!

You didn't tell us which Arduino you have (a requirement in post#1).
If you don't, then we assume an Uno.

So which Arduino are you using.
Leo..

Yes I am using UNO R3
I still have the same issue with 5v whenever I connect it, it doesn't show reading from the sensor

Just tested the sketch from post#12 with an Uno and a wire link between A0 and the 3.3volt pin.

The serial monitor displayed 166.0 as expected.

Check your setup and/or post an image.
Leo..

Yes, I got 164.6 PSI

This is the sketch I am using

The image in the first post indicates the sensor should be powered with 9-36v.

Here is a link to the G2 data sheet. Can you confirm which model you have?
https://www.ashcroft.com/wp-content/uploads/2020/09/datasheet-g2-pressuretransducer.pdf

I'm using this model