pressure altitude sensor project coding help

hi everyone ,
i have been assigned a pressure altitude sensor arduino project as part of end of year college exams.
i am only a beginner at coding and am finding this assignment really tough.the project spec is below followed by my coding any help would be greatly appreciated as to where i am going so badly wrong.thanks so much

im really bdaly stuck,

“Pressure/Altitude sensor”
Sense pressure and convert to altitude with an input to compensate for prevailing barometric pressure. The system should report its readings to the serial port. The pressure sensor employed will be an MPX4115A

void setup() {

void loop(){
float pressure = readPressure(A1);
float millibars = pressure/100;
int const altitude = 2; // verify if it is right

Serial.print("Pressure = ");
Serial.println(" pascals");
Serial.print("Pressure = ");
Serial.println(" millibars");

/* Reads pressure from the given pin.

  • Returns a value in Pascals
    float readPressure(int pin){
    int pressureValue = analogRead(pin);
    float pressure=((pressureValue/1024.0)+0.095)/0.000009;
    return pressure;

// changing from pressure to altitude
float readaltitude(int pin){

float altitude =((-14.76 * pressure value)+14952); // change 200 to the statement
return altitude;

Serial.print("altitude = ");
Serial.println(" meters");
Serial.print("meters = ");
Serial.println(" meters");


The cheaply available BME280 shields have drivers which do all this for you,


Hi allan ,
Thanks for the comment
unfortunately we cant use that, we have to use the sensor provided to us as it a group project for college.thanks though

float altitude =((-14.76 * pressure value)+14952);    // change 200 to the statementWhere did you find that pressure/altitude relationship?

Try this one (after converting pressure units to Pa), which is what everyone else uses. Note that you have to update the sea level pressure (Pb or P0 in the above) quite frequently.

If you are a beginner at coding, it is best to start with some of the simple examples that come with the Arduino IDE, in order to learn the language and special features of the Arduino.

Please don't waste your time looking for the duplicate of this topic because I've deleted it.