Gm 3 Bar Map Sensor Question

So I am new to the whole coding thing and have been working on making a boost gauge for my car. I have done lots of searching and am finding different equations and cant seem to get the right code for the system. I am trying to get the value to read "0" when no pressure or vacuum is applied. When I used the line  mapval = (analogRead(mapsen)) / (0.079681 + 20.975) - 15.53; I get it to "0" but when i give it full 5v it is only going to 33, when it should be at 44. I have tried 3 other lines that didnt produce what I am looking for. Could anyone please give me some insight on what needs to be changed.

Diagram Imgur: The magic of the Internet

[code]
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE); // DF Robots


int mapsen = 0; //port to read = A0
float boostVal; //
float mapval = 0;



void setup () {
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Boost: ");
  
  lcd.setCursor(0,1);
  lcd.print("A/F: ");
 

}


void loop () {
  //mapval= (analogRead(mapsen) * 5.0 / ( 1024.0 * 0.0162 ) ) + 0.0179 ;
  //float boostVal = ( analogRead(mapsen) * 5.0 / ( 1024.0 * 0.0162 ) ) + 0.0179 ;
  //mapval = (analogRead(mapsen) * 8.94 )+ 14.53;
  mapval = (analogRead(mapsen)) / (0.079681 + 20.975) - 15.53;
 
  lcd.setCursor(7,0);
  lcd.print(mapval);
  delay(250);
   
}

[/code]

Could anyone please give me some insight on what needs to be changed.

No, because you don't give us enough insights into your setup. Post links to the used hardware and a wiring diagram.
What does work in your sketch, what did it return and what did you expect?

Added more info to the post does that help at all.

GM MAP sensor identification information 1 bar 2 bar 3 bar

Unfortunately this is just a photo of the sensor and a few details but no datasheet. But based on the data found on that page I guess that this sensor doesn't expect 5V on it's power pins as it puts out more than 5V in some cases. Most car parts expects a 12V power supply. You might try to connect a voltage divider at the output to ensure your Arduino doesn't get an overvoltage.

I get it to "0" but when i give it full 5v it is only going to 33, when it should be at 44. I have tried 3 other lines that didnt produce what I am looking for. Could anyone please give me some insight on what needs to be changed.

You get 0 if you give 5V to what? to A0? If this is the case your analog pin probably already got an overvoltage and is ruined.

Where is that formula coming from? Do you have a link for reference? A datasheet of the sensor would help much too.

Start printing the raw value you get from analogRead(A0) to see if you actually can read the sensor.

15 in/Hg of vacuum (0 Bar for the sensor): close to 0V
0 PSI (barometric pressure, 1 Bar for the sensor): around 1.66V
14.7 PSI (1 Bar of boost, or 2 Bar for the sensor): around 3.32V
29.4 PSI (2 Bar of boost, or 3 Bar for the sensor): around 4.98V
This will vary according to the temperature and your altitude.
It's better to hook up a pressure gauge and a volt meter to check what the actual readings are.
This a 5v sensor.

Assuming you want the readout in psi.
Try this test sketch.
Leo..

const int offset = 400; // zero pressure adjust
const int fullScale = 1006; // max pressure adjust
float pressure; // final pressure

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

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

So I did measurements of the sensor and this is what I came up with. So this is the pressure, voltage and the value.
-27 - .1v - 26
-20 - .4v - 92
-10 - .9v - 196
0 psi - 1.5v 330
10 - 2.5v - 548
20 - 3.5v - 783
30 - 4.5v - 1000

Voltage is not relevant, because the sensor is ratiometric.
From that list you can change the three relevant lines in the code from post#5.

const int offset = 330; // zero pressure adjust
const int fullScale = 1000; // max pressure adjust

pressure = (analogRead(A0) - offset) * 30.0 / (fullScale - offset); // 30psi sensor

Leo..

So I changed the offset and the fullscale and that worked like a charm. Now just trying to figure out how to get vacuum to read correct. it is about 4 inHg off. When I am pulling 10 inHg it is at 6 inHg. Also is there a way to change the decimal place to only read whole numbers. When I change "float pressure" to "int pressure" it works but it keeps the second digit when i drop the pressure off. Example. it goes 7-8-9-10-11-12. Then I let off the pressure and it goes 12-12-12-92-82-72. It keeps the second digit.

offset is the zero value without pressure, and fullScale is the gain/amplification.
Lowering that 1000 value lowers postive as well as the negative readout.
I assume you power the sensor from the Mega's 5volt pin.

lcd.print(mapval, x); // 'x' is the number of decimal places (defaults to 2), but can be any number, even 0

You might have to print a number of spaces to the LCD first, before printing a new value (to wipe an old value).

lcd.setCursor(7,0);
lcd.print(" "); // print blanks
lcd.setCursor(7,0);
lcd.print(mapval, 0);

Leo..

ok cool i will try that. yes i am running the sensor off the 5v on the mega.