# 100psi pressure transducer working code inside. Using as fuel pressure gauge!

Hey,

I found this code online

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

void loop(){
Serial.print("Sensor Value: ");
Serial.print(sensorVal);

float voltage = (sensorVal*5.0)/1024.0;
Serial.print("Volts: ");
Serial.print(voltage);

float pressure_pascal = (3.0*((float)voltage-0.47))*1000000.0;
float pressure_bar = pressure_pascal/10e5;
Serial.print("Pressure = ");
Serial.print(pressure_bar);
Serial.println(" bars");
Serial.print("Pressure = ");

delay(100);
}
``````

I have 100 PSI trasducer using 5v.
4.5v is 100 psi

How do i make the code up to work with my sensor?

Use that line instead of the pascal calculation. Convert to other units if you need to.
This give you correct results only if the values on the alibaba page are correct.

``````float pressure_psi = ((float)voltage - 0.5) * 25.0;
``````

This is ok too right?
sensor is showing 0.5v now so equals to zero. If I blow into it, I get a value. I can test with compressor tomorrow.

``````#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int psival;
int Psipin = 0;
int toBar;

void setup() {
lcd.begin (16, 2);
Serial.begin(9600);

}

void loop() {
//calculating y value and converting to bar with *0.06895
float y = (psival-102)*100/(921-102)*0.06895;

//  lcd.print("BOOST = ");
//lcd.setCursor(0, 1);
//lcd.print(y);
//lcd.setCursor(5, 1);
//lcd.print("PSI");
Serial.print(y);
delay (1000);
//lcd.clear();
}
``````

okay im stuck. I dont really understand the code.
There is so many different codes out there and all different.

I just need to show on LCD pressure in bar.
I know this is asking lot but this really doesnt open for me…

it gives me with this code:

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

void loop(){

Serial.println(sensorVal);

delay(100);
}
``````

thats 0.5v on reading with digital meter.

I tested sensor with pressure and digital meter and following stats:
80psi is 4v
60psi is 3v
40psi is 2v

I couldnt see what arduino showed as analog since I didnt have screen where air pressure was.

So how do I get this analog reading to show pressure in bar or psi?
any codes?

Sensors like that output a voltage of 10-90% of their supply, for the pressure span they are calibrated for.
10% being zero pressure, and 90% max pressure.

10% of Arduino's A/D range (1024) is about 102, and 90% is about 922.

This stripped down code cuts off those extremes (0-10% and 90-100%),
and uses a multiplication factor to display pressure in the max number you want (100psi or 6.89476 bar).
Leo..

``````int offset = 102; // zero pressure calibrate
int fullScale = 922; // max pressure calibrate
float pressure; // final pressure

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

void loop() {
pressure = (analogRead(A0) - offset) * 6.89476  / (fullScale - offset); // pressure conversion
Serial.print("Pressure is  ");
Serial.print(pressure);
Serial.println("  bar");
delay(500);
}
``````

I figured it out and now I have working fuel pressure sensor. Thanks for all help
Here is code for LCD 16x2 too

``````//Sample using LiquidCrystal library
#include <LiquidCrystal.h>

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);              // start the library

}

void loop()
{

Serial.println(sensorVal);

float voltage = (sensorVal*5.0)/1024.0;
Serial.print("Volts: ");
Serial.print(voltage);
lcd.setCursor(0,0);

float pressure_psi = ((float)voltage - 0.5) * 25.0;
float bar = pressure_psi * 0.06894;
Serial.print("PSI: ");
Serial.print(pressure_psi);
Serial.print("Bar: ");
Serial.print(bar);

//Print a message to second line of LCD
lcd.print("PSI:");
lcd.print(pressure_psi);

lcd.setCursor(0, 1);
lcd.print("Bar:");
lcd.print(bar);

lcd.print(" V:");
lcd.print(voltage);

delay(100);
}
``````

can anyone provide the circuit diagram for this setup

If you are using this for measuring an automotive fuel system you will have to add a good amount of analog filtering on its output, before the input on the nano. I would start with:

Sensor output --> ~5k --> 1µF (ceramic or film) capacitor to ground --> ~500 --> nano input.

The 5k & 1µF filter the signal, the 500 is to protect the nano in case the power supply is suddenly shorted to ground.

Add a 0.1µF on the power going to the sensor (near the nano).

You will find the fuel pressure in a fuel injected vehicle has substantial pressure spikes. They could easily range from 20 to 60 psi (on top of the ~72 PSI of the fuel system).

In addition the EMI / RF energy picked up on the wires to the sensor can also be an issue.