Pressure sensor question!

Hello guys!

I have got a problem with my project and i cant figure it out where is the problem.
I have got an arduino uno witch 16x2 lcd and a pressure sensor(3 wire (gnd,+5,signal))
I just started to work with arduino a few weeks ago so im a noob!
I wrote a code i think its works but i have got a problem to convert my analog reading into pressure.
So here is the code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int mapsen = A1;
int signal=mapsen;
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
lcd.print(" AUDI");
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print a message to the lcd.
lcd.print(" A4");
delay(2000); // wait for 3 seconds
lcd.clear();
pinMode(mapsen, INPUT);
}

void loop()
{
// read the input on analog pin 0:
int sensorValue = analogRead(A1);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1040.0);
sensorValue=(analogRead(A1)+0.072571356)/0.0116;
// print out the value you read:
lcd.setCursor(0,0); // Sets the cursor to col 0 and row 0
lcd.print("Boost: "); // Prints Sensor Val: to LCD
lcd.print(analogRead(mapsen)*(5.0/1040.0)); // Prints value on val to LCD
lcd.print(" Bar"); // Prints Sensor Val: to LCD

delay(1000);
}

lcd shows 1.58 when i blow into the sensor goes up or down so its working,but i cant convert voltage to bars(here is the formula sensorValue=(analogRead(A1)+0.072571356)/0.0116;)
its always displays the same value 1.58 and 1.59
form the pressure sensor signal voltage(its 1.58 1.59)
Where is the missing point?
And an other question about 0-5V sensors it i put 5/1023 my readings are off when i measure signal voltage with multi meter it shows 1.58 and 1.59 but when i put this 5/1023 it goes up like 1.62
SO thats why i put 1040 and lcd shows real voltage that shows multimeter to

Thanks For help me out!

Plese, provide a link to your pressure sensor.

Also, please put code tags </> across the codes that you have posted. Just select the codes and click on this sign </> of the tools bar. Your code will appear like --

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

float voltage = sensorValue * (5.0 / 1024.0); Check your reference voltage.

sensorValue=(voltage+0.072571356)/0.0116; (just guessing)

Sorry for my mistakes guys i just started this thing! :smiley:
My reference voltage is 4,96V measured with multi meter

float voltage = sensorValue * (4.96 / 1024.0);

Thanks i put the new values in,it seems to work!
Now shows in Kpa how can i convert it to bar? i need to divide by 100 but where can i put that in my code?

Anywhere you like before you print the value.

void loop()
{
// read the input on analog pin 0:
  int sensorValue = analogRead(A1);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = (sensorValue*4.96)/ 1023.0;
  sensorValue=((voltage+0.072571356)/0.0116);
  sensorValue=sensorValue/100;
  // print out the value you read:
lcd.setCursor(7,0); // Sets the cursor to col 0 and row 0
lcd.print(sensorValue);

delay(1000);
}

If i did like this shows 1 instead of 1,44
if i delete senckound calculations shows 144

  int sensorValue = analogRead(A1);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = (sensorValue*4.96)/ 1024.0;
  sensorValue=((voltage+0.072571356)/0.0116);
  // print out the value you read:
lcd.setCursor(7,0); // Sets the cursor to col 0 and row 0
lcd.print(sensorValue / 100.0);

Ahhh i got it!!
Thank you very much guys!
I never seen before such a friendy and helpful forum thanks AGAIN!!

Thanks Ricsi! :slight_smile:

sensorValue=((voltage+0.072571356)/0.0116);

sensorValue is of type int.

voltage is of type float.

Do we need to cast the RHS to make the data type compatible by doing as follows?

sensorValue = (int)((voltage+0.072571356)/0.0116);

GolamMostafa:
Do we need to cast the RHS to make the data type compatible by doing as follows?

If the pressures are expressed in kPa, and we don't go below atmospheric pressure, then probably not.

Hey guys!

I got an other question about this code!
Now everything is working my only "problem" is that my sensor starts reading from barometric pressure so my lcd now shows 0,95Bar how can i adjust the sensor zero point to show 0,00bar at atmosferic pressure?

Subtract 0.95 bar.

Yes i know the baro pressure is 0,95Bar but i dont know where i need to subtrac to set zero point 0,00bar (so 095-000bar) and the counting starts from there

You've got the code - why not experiment?

Ahh i got it!
Thank you very much!

An other silly question is about connecting a temperature sensor to this project.
Unfortunatelly i dont know how can i connect my bosch temperature sensor i have got a data sheet about that sensor,any1 can help me where can i start? or how can i do this? (and with the coding)

I have got the connections its a 4 wire sensor pressure with temperature combined sensor,the pressure it seems to work i need to check with real time pressures but the temperature i dont know.
At ~ambient temp my multimeter reads 1,94(20k) its ~ 1940ohm.
what kind of data needed to work with this sensor?

Ricsi168:
I have got the connections its a 4 wire sensor pressure with temperature combined sensor,the pressure it seems to work i need to check with real time pressures but the temperature i dont know.
At ~ambient temp my multimeter reads 1,94(20k) its ~ 1940ohm.
what kind of data needed to work with this sensor?

The type of sensor or the sensor technology.