Hi, I am trying to build a water pressure sensor with a cheap 100 psi pressure sensor off Amazon, I am using an Arduino Uno and have followed a guy on Youtubes tutorial, however the output is floating ie when no pressure the output is reading 6 - 8 psi, I know the resolution is 10 bit but my question is would a higher resolution help me and could I use an add on board ?
/* 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 firstname.lastname@example.org if you have any questions
#include "Wire.h" //allows communication over i2c devices
#include "LiquidCrystal_I2C.h" //allows interfacing with LCD screens
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(0x3f, 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.begin(); //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
To calibrate the pressure sensor you need to first subtract off the reading you get when it is at zero relative pressure (exposed to the atmosphere). Then the output is scaled so that the pressure reading is correct when the sensor input is at a known higher pressure.
That means that the pressureZero value must be lowered a lot, maybe to about 55.
Change the value and upload until it displays as close to zero as possible.
The Arduino A/D returns integers.
Using a float with a decimal place indicates that the youtuber is a beginner. There are other things in the code which experienced coders would have done differently, like printing fixed LCD text in setup(). The display will now probably flicker.
Start by updating these lines
const int pressureZero = 55; // calibrate for zero pressure
const int pressureMax = 921; // calibrate if you can for max pressure
const float pressuretransducermaxPSI = 100.0;
The first thing I would do is to print out the raw pressureValue in counts. This eliminates any code / conversion error.
The next step would be to add a 0.1µF capacitor to the input of the Arduino A/D pin to the closest Arduino ground. And add a 5k to 10k resistor in series with the pressure sensor signal. This will filter out any "noise" on the signal that could cause unstable readings.
Assuming the pressure transduce and the Uno are both connected to the same 5V. Then:
sensor voltage for each psi = 5/100 = 50mv/psi
A/D voltage for each count = 5/1024 = 4.88 mv / count
This gives you ~ 10 counts for each PSI. Adding resolution will give you no benefit.
This type of pressure transducer is notorious for zero pressure issues. The sense element is a disc of stainless steel with a strain gauge attached to it. Its very difficult for the mfg to keep the element from "oil canning" at zero pressure.
So I wouldn't worry too much about an offset at zero pressure.
Not exactly true.
Sensors like this usually have a limited output range of 0.5 to 4.5volt on a 5volt supply.
So only about 800 counts of a 10-bit A/D. Not quite enough to display 100 with one decimal place, unless you take multiple samples and average (smoothing code).
Can't say 50mV'psi (or 40mV/psi) either, because sensors like this are ratiometric, so mV/psi is supply dependent. Just stick with A/D counts per psi, and forget about 'volts'.
At least the ratiometric code the youtuber used is correct.
pressure = (A/D value - zero offset) * sensor rating / ( max A/D value at sensor rating - zero offset)
I didn't read through the code (not my strong point). However I've seen a LOT of pressure transducers working in automotive and I've never seen a 0.25 to 4.75. I can't say such a transducer doesn't exist but it would be a rare bird.
Without additional information I would say your suggestion of 0.5 to 4.5 is most likely with the remainder being just a poor zero on a low cost pressure sensor. But I guess well see....